Completed
Push — master ( ef04cf...199149 )
by Mike
02:19
created
includes/class-delete.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 		$post_types = get_post_types( array( 'public' => true ), 'objects' );
26 26
 		foreach ( $post_types as $post_type ) :
27 27
 
28
-		    $this->delete_posts( $post_type->name, $echo );
28
+			$this->delete_posts( $post_type->name, $echo );
29 29
 
30 30
 		endforeach;
31 31
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 		$taxonomies = get_taxonomies();
34 34
 		foreach ( $taxonomies as $tax ) :
35 35
 
36
-		    $this->delete_terms( $tax, $echo );
36
+			$this->delete_terms( $tax, $echo );
37 37
 
38 38
 		endforeach;
39 39
 
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
 
183 183
 		// Query for our terms
184 184
 		$args = array(
185
-		    'hide_empty' => false,
186
-		    'meta_query' => array(
187
-		        array(
188
-		           'key'       => 'evans_test_content',
189
-		           'value'     => '__test__',
190
-		           'compare'   => '='
191
-		        )
192
-		    )
185
+			'hide_empty' => false,
186
+			'meta_query' => array(
187
+				array(
188
+				   'key'       => 'evans_test_content',
189
+				   'value'     => '__test__',
190
+				   'compare'   => '='
191
+				)
192
+			)
193 193
 		);
194 194
 
195 195
 		$terms = get_terms( $slug, $args );
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -8,32 +8,32 @@  discard block
 block discarded – undo
8 8
  * @subpackage Evans
9 9
  * @author     Old Town Media
10 10
  */
11
-class Delete{
11
+class Delete {
12 12
 
13 13
 	/**
14 14
 	 * Delete all test content created ever.
15 15
 	 *
16 16
 	 * @access private
17 17
 	 */
18
-	public function delete_all_test_data( $echo = false ){
18
+	public function delete_all_test_data($echo = false) {
19 19
 
20
-		if ( !$this->user_can_delete() ){
20
+		if (!$this->user_can_delete()) {
21 21
 			return;
22 22
 		}
23 23
 
24 24
 		// Loop through all post types and remove any test data
25
-		$post_types = get_post_types( array( 'public' => true ), 'objects' );
26
-		foreach ( $post_types as $post_type ) :
25
+		$post_types = get_post_types(array('public' => true), 'objects');
26
+		foreach ($post_types as $post_type) :
27 27
 
28
-		    $this->delete_posts( $post_type->name, $echo );
28
+		    $this->delete_posts($post_type->name, $echo);
29 29
 
30 30
 		endforeach;
31 31
 
32 32
 		// Loop through all taxonomies and remove any data
33 33
 		$taxonomies = get_taxonomies();
34
-		foreach ( $taxonomies as $tax ) :
34
+		foreach ($taxonomies as $tax) :
35 35
 
36
-		    $this->delete_terms( $tax, $echo );
36
+		    $this->delete_terms($tax, $echo);
37 37
 
38 38
 		endforeach;
39 39
 
@@ -52,15 +52,15 @@  discard block
 block discarded – undo
52 52
 	 * @param string $slug a custom post type ID.
53 53
 	 * @param boolean $echo Whether or not to echo the result
54 54
 	 */
55
-	public function delete_posts( $slug, $echo = false ){
55
+	public function delete_posts($slug, $echo = false) {
56 56
 
57 57
 		// Make sure that the current user is logged in & has full permissions.
58
-		if ( !$this->user_can_delete() ){
58
+		if (!$this->user_can_delete()) {
59 59
 			return;
60 60
 		}
61 61
 
62 62
 		// Check that $cptslg has a string.
63
-		if ( empty( $slug ) ){
63
+		if (empty($slug)) {
64 64
 			return;
65 65
 		}
66 66
 
@@ -77,39 +77,39 @@  discard block
 block discarded – undo
77 77
 			),
78 78
 		);
79 79
 
80
-		$objects = new \WP_Query( $query );
80
+		$objects = new \WP_Query($query);
81 81
 
82
-		if ( $objects->have_posts() ){
82
+		if ($objects->have_posts()) {
83 83
 
84 84
 			$events = array();
85 85
 
86
-			while ( $objects->have_posts() ) : $objects->the_post();
86
+			while ($objects->have_posts()) : $objects->the_post();
87 87
 
88 88
 				// Find any media associated with the test post and delete it as well
89
-				$this->delete_associated_media( get_the_id() );
89
+				$this->delete_associated_media(get_the_id());
90 90
 
91
-				if ( $echo === true ){
91
+				if ($echo === true) {
92 92
 					$events[] = array(
93 93
 						'type'		=> 'deleted',
94 94
 						'pid'		=> get_the_id(),
95
-						'post_type'	=> get_post_type( get_the_id() ),
95
+						'post_type'	=> get_post_type(get_the_id()),
96 96
 						'link'		=> ''
97 97
 					);
98 98
 				}
99 99
 
100 100
 				// Force delete the post
101
-				wp_delete_post( get_the_id(), true );
101
+				wp_delete_post(get_the_id(), true);
102 102
 
103 103
 			endwhile;
104 104
 
105
-			$obj = get_post_type_object( $slug );
105
+			$obj = get_post_type_object($slug);
106 106
 
107 107
 			$events[] = array(
108 108
 				'type'		=> 'general',
109
-				'message'	=> __( 'Deleted', 'otm-test-content' ) . ' ' . $obj->labels->all_items
109
+				'message'	=> __('Deleted', 'otm-test-content').' '.$obj->labels->all_items
110 110
 			);
111 111
 
112
-			echo \json_encode( $events );
112
+			echo \json_encode($events);
113 113
 
114 114
 		}
115 115
 
@@ -129,26 +129,26 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @param int $pid a custom post type ID.
131 131
 	 */
132
-	private function delete_associated_media( $pid ){
132
+	private function delete_associated_media($pid) {
133 133
 
134 134
 		// Make sure that the current user is logged in & has full permissions.
135
-		if ( !$this->user_can_delete() ){
135
+		if (!$this->user_can_delete()) {
136 136
 			return;
137 137
 		}
138 138
 
139 139
 		// Make sure $pid is, in fact, an ID
140
-		if ( !is_int( $pid ) ){
140
+		if (!is_int($pid)) {
141 141
 			return;
142 142
 		}
143 143
 
144 144
 		// Get our images
145
-		$media = get_attached_media( 'image', $pid );
145
+		$media = get_attached_media('image', $pid);
146 146
 
147
-		if ( !empty( $media ) ){
147
+		if (!empty($media)) {
148 148
 
149 149
 			// Loop through the media & delete each one
150
-			foreach ( $media as $attachment ){
151
-				wp_delete_attachment( $attachment->ID, true );
150
+			foreach ($media as $attachment) {
151
+				wp_delete_attachment($attachment->ID, true);
152 152
 			}
153 153
 
154 154
 		}
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
 	 * @param string $slug a custom post type ID.
169 169
 	 * @param boolean $echo Whether or not to echo the result
170 170
 	 */
171
-	public function delete_terms( $slug, $echo = false ){
171
+	public function delete_terms($slug, $echo = false) {
172 172
 
173 173
 		// Make sure that the current user is logged in & has full permissions.
174
-		if ( !$this->user_can_delete() ){
174
+		if (!$this->user_can_delete()) {
175 175
 			return;
176 176
 		}
177 177
 
178 178
 		// Check that $cptslg has a string.
179
-		if ( empty( $slug ) ){
179
+		if (empty($slug)) {
180 180
 			return;
181 181
 		}
182 182
 
@@ -192,15 +192,15 @@  discard block
 block discarded – undo
192 192
 		    )
193 193
 		);
194 194
 
195
-		$terms = get_terms( $slug, $args );
195
+		$terms = get_terms($slug, $args);
196 196
 
197
-		if ( !empty( $terms ) ){
197
+		if (!empty($terms)) {
198 198
 
199 199
 			$events = array();
200 200
 
201
-			foreach ( $terms as $term ){
201
+			foreach ($terms as $term) {
202 202
 
203
-				if ( $echo === true ){
203
+				if ($echo === true) {
204 204
 					$events[] = array(
205 205
 						'type'		=> 'deleted',
206 206
 						'pid'		=> $term->term_id,
@@ -210,18 +210,18 @@  discard block
 block discarded – undo
210 210
 				}
211 211
 
212 212
 				// Delete our term
213
-				wp_delete_term( $term->term_id, $slug );
213
+				wp_delete_term($term->term_id, $slug);
214 214
 
215 215
 			}
216 216
 
217
-			$taxonomy = get_taxonomy( $slug );
217
+			$taxonomy = get_taxonomy($slug);
218 218
 
219 219
 			$events[] = array(
220 220
 				'type'		=> 'general',
221
-				'message'	=> __( 'Deleted', 'otm-test-content' ) . ' ' . $taxonomy->labels->name
221
+				'message'	=> __('Deleted', 'otm-test-content').' '.$taxonomy->labels->name
222 222
 			);
223 223
 
224
-			echo \json_encode( $events );
224
+			echo \json_encode($events);
225 225
 
226 226
 		}
227 227
 
@@ -233,15 +233,15 @@  discard block
 block discarded – undo
233 233
 	 *
234 234
 	 * @see is_user_logged_in, current_user_can
235 235
 	 */
236
-	private function user_can_delete(){
236
+	private function user_can_delete() {
237 237
 
238 238
 		// User must be logged in
239
-		if ( !is_user_logged_in() ){
239
+		if (!is_user_logged_in()) {
240 240
 			return false;
241 241
 		}
242 242
 
243 243
 		// User must have editor priveledges, at a minimum
244
-		if ( !current_user_can( 'delete_others_posts' ) ){
244
+		if (!current_user_can('delete_others_posts')) {
245 245
 			return false;
246 246
 		}
247 247
 
Please login to merge, or discard this patch.
includes/class-create-post.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @subpackage Evans
9 9
  * @author     Old Town Media
10 10
  */
11
-class CreatePost{
11
+class CreatePost {
12 12
 
13 13
 	/**
14 14
 	 * metaboxes
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 *
26 26
 	 * @see Metaboxes
27 27
 	 */
28
-	public function __construct(){
28
+	public function __construct() {
29 29
 
30 30
 		$this->metaboxes = new Metaboxes;
31 31
 
@@ -47,32 +47,32 @@  discard block
 block discarded – undo
47 47
 	 * @param boolean $echo Whether or not to echo. Optional.
48 48
 	 * @param int $num Optional. Number of posts to create.
49 49
 	 */
50
-	public function create_post_type_content( $slug, $connection, $echo = false, $num = '' ){
50
+	public function create_post_type_content($slug, $connection, $echo = false, $num = '') {
51 51
 
52 52
 		// If we're missing a custom post type id - don't do anything
53
-		if ( empty( $slug ) ){
53
+		if (empty($slug)) {
54 54
 			return;
55 55
 		}
56 56
 
57 57
 		// Gather the necessary data to create the posts
58
-		$supports 	= $this->get_cpt_supports( $slug );
59
-		$metaboxes	= $this->metaboxes->get_metaboxes( $slug );
58
+		$supports 	= $this->get_cpt_supports($slug);
59
+		$metaboxes	= $this->metaboxes->get_metaboxes($slug);
60 60
 
61 61
 		// Set our connection status for the rest of the methods
62 62
 		$this->connected = $connection;
63 63
 
64 64
 		// If we forgot to put in a quantity, make one for us
65
-		if ( empty( $num ) ){
66
-			$num = rand( 5, 30 );
65
+		if (empty($num)) {
66
+			$num = rand(5, 30);
67 67
 		}
68 68
 
69 69
 		// Create test posts
70
-		for( $i = 0; $i < $num; $i++ ){
70
+		for ($i = 0; $i < $num; $i++) {
71 71
 
72
-			$return = $this->create_test_object( $slug, $supports, $metaboxes );
72
+			$return = $this->create_test_object($slug, $supports, $metaboxes);
73 73
 
74
-			if ( $echo === true ){
75
-				echo \json_encode( $return );
74
+			if ($echo === true) {
75
+				echo \json_encode($return);
76 76
 			}
77 77
 
78 78
 		}
@@ -95,15 +95,15 @@  discard block
 block discarded – undo
95 95
 	 * @param array $supports Features that the post type supports.
96 96
 	 * @param array $supports All CMB2 metaboxes attached to the post type.
97 97
 	 */
98
-	private function create_test_object( $slug, $supports, $metaboxes ){
98
+	private function create_test_object($slug, $supports, $metaboxes) {
99 99
 		$return = '';
100 100
 
101 101
 		// Get a random title
102
-		$title = apply_filters( "tc_{$slug}_post_title", TestContent::title() );
102
+		$title = apply_filters("tc_{$slug}_post_title", TestContent::title());
103 103
 
104 104
 		// First, insert our post
105 105
 		$post = array(
106
-		  'post_name'      => sanitize_title( $title ),
106
+		  'post_name'      => sanitize_title($title),
107 107
 		  'post_status'    => 'publish',
108 108
 		  'post_type'      => $slug,
109 109
 		  'ping_status'    => 'closed',
@@ -111,57 +111,57 @@  discard block
 block discarded – undo
111 111
 		);
112 112
 
113 113
 		// Add title if supported
114
-		if ( $supports['title'] === true ){
114
+		if ($supports['title'] === true) {
115 115
 			$post['post_title'] = $title;
116 116
 		}
117 117
 
118 118
 		// Add main content if supported
119
-		if ( $supports['editor'] === true ){
120
-			$post['post_content'] = apply_filters( "tc_{$slug}_post_content", TestContent::paragraphs() );
119
+		if ($supports['editor'] === true) {
120
+			$post['post_content'] = apply_filters("tc_{$slug}_post_content", TestContent::paragraphs());
121 121
 		}
122 122
 
123 123
 		// Add excerpt content if supported
124
-		if ( $supports['excerpt'] === true ){
125
-			$post['post_excerpt'] = apply_filters( "tc_{$slug}_post_excerpt", TestContent::plain_text() );
124
+		if ($supports['excerpt'] === true) {
125
+			$post['post_excerpt'] = apply_filters("tc_{$slug}_post_excerpt", TestContent::plain_text());
126 126
 		}
127 127
 
128 128
 		// Insert then post object
129
-		$post_id = wp_insert_post( apply_filters( "tc_{$slug}_post_arguments", $post ) );
129
+		$post_id = wp_insert_post(apply_filters("tc_{$slug}_post_arguments", $post));
130 130
 
131 131
 		// Then, set a test content flag on the new post for later deletion
132
-		add_post_meta( $post_id, 'evans_test_content', '__test__', true );
132
+		add_post_meta($post_id, 'evans_test_content', '__test__', true);
133 133
 
134 134
 		// Add thumbnail if supported
135
-		if ( $this->connected == true && ( $supports['thumbnail'] === true || in_array( $slug, array( 'post', 'page' ) ) ) ){
136
-			 update_post_meta( $post_id, '_thumbnail_id', TestContent::image( $post_id ) );
135
+		if ($this->connected == true && ($supports['thumbnail'] === true || in_array($slug, array('post', 'page')))) {
136
+			 update_post_meta($post_id, '_thumbnail_id', TestContent::image($post_id));
137 137
 		}
138 138
 
139
-		$taxonomies = get_object_taxonomies( $slug );
139
+		$taxonomies = get_object_taxonomies($slug);
140 140
 
141 141
 		// Assign the post to terms
142
-		if ( !empty( $taxonomies ) ){
143
-			$return .= $this->assign_terms( $post_id, $taxonomies );
142
+		if (!empty($taxonomies)) {
143
+			$return .= $this->assign_terms($post_id, $taxonomies);
144 144
 		}
145 145
 
146 146
 		// Spin up metaboxes
147
-		if ( !empty( $metaboxes ) ){
148
-			foreach ( $metaboxes as $cmb ) :
149
-				$return .= $this->metaboxes->random_metabox_content( $post_id, $cmb, $this->connected );
147
+		if (!empty($metaboxes)) {
148
+			foreach ($metaboxes as $cmb) :
149
+				$return .= $this->metaboxes->random_metabox_content($post_id, $cmb, $this->connected);
150 150
 			endforeach;
151 151
 		}
152 152
 
153 153
 		// Check if we have errors and return them or created message
154
-		if ( is_wp_error( $return ) ){
155
-			error_log( $return->get_error_message() );
154
+		if (is_wp_error($return)) {
155
+			error_log($return->get_error_message());
156 156
 			return $return;
157 157
 		} else {
158 158
 			return array(
159 159
 				'type'		=> 'created',
160 160
 				'object'	=> 'post',
161 161
 				'pid'		=> $post_id,
162
-				'post_type'	=> get_post_type( $post_id ),
163
-				'link_edit'	=> admin_url( '/post.php?post='.$post_id.'&action=edit' ),
164
-				'link_view'	=> get_permalink( $post_id ),
162
+				'post_type'	=> get_post_type($post_id),
163
+				'link_edit'	=> admin_url('/post.php?post='.$post_id.'&action=edit'),
164
+				'link_view'	=> get_permalink($post_id),
165 165
 			);
166 166
 		}
167 167
 
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
 	 * @param string $slug a custom post type ID.
179 179
 	 * @return array Array of necessary supports booleans.
180 180
 	 */
181
-	private function get_cpt_supports( $slug ){
181
+	private function get_cpt_supports($slug) {
182 182
 
183 183
 		$supports = array(
184
-			'title'		=> post_type_supports( $slug, 'title' ),
185
-			'editor'	=> post_type_supports( $slug, 'editor' ),
186
-			'excerpt'	=> post_type_supports( $slug, 'excerpt' ),
187
-			'thumbnail'	=> post_type_supports( $slug, 'thumbnail' )
184
+			'title'		=> post_type_supports($slug, 'title'),
185
+			'editor'	=> post_type_supports($slug, 'editor'),
186
+			'excerpt'	=> post_type_supports($slug, 'excerpt'),
187
+			'thumbnail'	=> post_type_supports($slug, 'thumbnail')
188 188
 		);
189 189
 
190 190
 		return $supports;
@@ -205,26 +205,26 @@  discard block
 block discarded – undo
205 205
 	 * @param array $taxonomies taxonomies assigned to this cpt.
206 206
 	 * @return object WP Error if there is one.
207 207
 	 */
208
-	private function assign_terms( $post_id, $taxonomies ){
208
+	private function assign_terms($post_id, $taxonomies) {
209 209
 
210 210
 		// Make sure it's an array & has items
211
-		if ( empty( $taxonomies ) || !is_array( $taxonomies ) ){
211
+		if (empty($taxonomies) || !is_array($taxonomies)) {
212 212
 			return;
213 213
 		}
214 214
 
215
-		foreach ( $taxonomies as $tax ){
215
+		foreach ($taxonomies as $tax) {
216 216
 
217 217
 			// Get the individual terms already existing
218
-			$terms = get_terms( $tax, array( 'hide_empty'	=> false ) );
219
-			$count = count( $terms ) - 1;
218
+			$terms = get_terms($tax, array('hide_empty'	=> false));
219
+			$count = count($terms) - 1;
220 220
 
221 221
 			// If there are no terms, skip to the next taxonomy
222
-			if ( empty( $terms ) ){
222
+			if (empty($terms)) {
223 223
 				continue;
224 224
 			}
225 225
 
226 226
 			// Get a random index to use
227
-			$index = rand( 0, $count );
227
+			$index = rand(0, $count);
228 228
 
229 229
 			// Initialize our array
230 230
 			$post_data = array(
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
 			);
233 233
 
234 234
 			// Set the term data to update
235
-			$post_data['tax_input'][ $tax ] = array( $terms[$index]->term_id );
235
+			$post_data['tax_input'][$tax] = array($terms[$index]->term_id);
236 236
 
237 237
 			// Update the post with the taxonomy info
238
-			$return = wp_update_post( $post_data );
238
+			$return = wp_update_post($post_data);
239 239
 
240 240
 			// Return the error if it exists
241
-			if ( is_wp_error( $return ) ){
242
-				error_log( $return->get_error_messages() );
241
+			if (is_wp_error($return)) {
242
+				error_log($return->get_error_messages());
243 243
 				return $return->get_error_messages();
244 244
 			}
245 245
 
Please login to merge, or discard this patch.
includes/class-test-content.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -417,29 +417,29 @@  discard block
 block discarded – undo
417 417
 		}
418 418
 
419 419
 		// Download the file
420
-	    $tmp = \download_url( $url );
420
+		$tmp = \download_url( $url );
421 421
 
422
-	    preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches );
422
+		preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches );
423 423
 
424
-        $file_array['name'] = basename( $matches[0] );
425
-        $file_array['tmp_name'] = $tmp;
424
+		$file_array['name'] = basename( $matches[0] );
425
+		$file_array['tmp_name'] = $tmp;
426 426
 
427
-	    // Check for download errors
428
-	    if ( is_wp_error( $tmp ) ) {
429
-	        unlink( $file_array[ 'tmp_name' ] );
430
-	        error_log( $tmp->get_error_message() );
431
-	    }
427
+		// Check for download errors
428
+		if ( is_wp_error( $tmp ) ) {
429
+			unlink( $file_array[ 'tmp_name' ] );
430
+			error_log( $tmp->get_error_message() );
431
+		}
432 432
 
433 433
 		// Pull the image into the media library
434
-	    $image_id = media_handle_sideload( $file_array, $post_id );
434
+		$image_id = media_handle_sideload( $file_array, $post_id );
435 435
 
436
-	    // Check for handle sideload errors.
437
-	    if ( is_wp_error( $image_id ) ) {
438
-	        unlink( $file_array['tmp_name'] );
439
-	        error_log( $image_id->get_error_message() );
440
-	    }
436
+		// Check for handle sideload errors.
437
+		if ( is_wp_error( $image_id ) ) {
438
+			unlink( $file_array['tmp_name'] );
439
+			error_log( $image_id->get_error_message() );
440
+		}
441 441
 
442
-	    return apply_filters( "tc_image_data", $image_id );
442
+		return apply_filters( "tc_image_data", $image_id );
443 443
 
444 444
 	}
445 445
 
@@ -462,9 +462,9 @@  discard block
 block discarded – undo
462 462
 
463 463
 		// If our cURL failed
464 464
 		if ( $curl_response === false ) {
465
-		    $info = curl_getinfo( $curl );
466
-		    curl_close( $curl );
467
-		    die( 'error occured during curl exec. Additional info: ' . var_export( $info ) );
465
+			$info = curl_getinfo( $curl );
466
+			curl_close( $curl );
467
+			die( 'error occured during curl exec. Additional info: ' . var_export( $info ) );
468 468
 		}
469 469
 
470 470
 		curl_close( $curl );
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  * @subpackage Evans
15 15
  * @author     Old Town Media
16 16
  */
17
-class TestContent{
17
+class TestContent {
18 18
 
19 19
 	/**
20 20
 	 * Title function.
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * @param int $num_words Number of words to return.
27 27
 	 * @return string Random title string.
28 28
 	 */
29
-	public static function title( $num_words = '' ){
29
+	public static function title($num_words = '') {
30 30
 
31 31
 		$title = '';
32 32
 
@@ -67,16 +67,16 @@  discard block
 block discarded – undo
67 67
 		);
68 68
 
69 69
 		// If we didn't choose a count, make one
70
-		if ( empty( $num_words ) ){
71
-			$num_words = rand( 2, 10 );
70
+		if (empty($num_words)) {
71
+			$num_words = rand(2, 10);
72 72
 		}
73 73
 
74 74
 		// Pull random words
75
-		for( $i = 1; $i <= $num_words; $i++ ){
76
-			$title .= $random_words[ rand( 0, 31 ) ] . " ";
75
+		for ($i = 1; $i <= $num_words; $i++) {
76
+			$title .= $random_words[rand(0, 31)]." ";
77 77
 		}
78 78
 
79
-		return apply_filters( "tc_title_data", substr( $title, 0, -1 ) );
79
+		return apply_filters("tc_title_data", substr($title, 0, -1));
80 80
 
81 81
 	}
82 82
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @return string Paragraph(s) of text.
91 91
 	 */
92
-	public static function paragraphs(){
92
+	public static function paragraphs() {
93 93
 
94 94
 		$content = '';
95 95
 
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
 
351 351
 		);
352 352
 
353
-		for( $i = 1; $i < 6; $i++ ){
354
-			$content .= $random_content_types[rand( 0, 12 )];
353
+		for ($i = 1; $i < 6; $i++) {
354
+			$content .= $random_content_types[rand(0, 12)];
355 355
 		}
356 356
 
357
-		return apply_filters( "tc_paragraphs_data", $content );
357
+		return apply_filters("tc_paragraphs_data", $content);
358 358
 
359 359
 	}
360 360
 
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	 *
367 367
 	 * @return string Plain text paragraphs.
368 368
 	 */
369
-	public static function plain_text(){
369
+	public static function plain_text() {
370 370
 
371 371
 		$paragraphs = array(
372 372
 			'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean tincidunt luctus eros, a tincidunt massa aliquet sit amet. Sed faucibus, eros non lacinia porttitor, risus odio efficitur sapien, id porta urna massa ac est. Cras efficitur lacinia magna eget tempus. Fusce ex felis, finibus consectetur mi at, finibus rhoncus augue. In ut tortor lacinia, rutrum mauris vel, maximus tortor. Praesent ac arcu nec eros pharetra tristique. Morbi congue leo sed ipsum fermentum vulputate. Ut nulla eros, porta varius pulvinar eget, bibendum quis dolor. Morbi sed diam eu dui semper ornare nec quis nisl.',
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 			'Fusce semper erat tortor, at pulvinar risus luctus suscipit. Phasellus quis enim nisl. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas semper dapibus odio, nec pellentesque sem laoreet sit amet. Maecenas ut enim tellus. Fusce malesuada mattis sem, porta interdum ex fermentum quis. Ut eget quam mi. In molestie volutpat feugiat. Nulla vel viverra nunc. Integer lobortis nisl vitae placerat egestas. Curabitur tristique nulla at libero blandit, a eleifend augue tempus.',
382 382
 		);
383 383
 
384
-		return apply_filters( "tc_plain_text_data", $paragraphs[ rand( 0, 9 ) ] );
384
+		return apply_filters("tc_plain_text_data", $paragraphs[rand(0, 9)]);
385 385
 
386 386
 	}
387 387
 
@@ -397,49 +397,49 @@  discard block
 block discarded – undo
397 397
 	 * @param int $post_id Post ID.
398 398
 	 * @return mixed Attachment ID or WP Error.
399 399
 	 */
400
-	public static function image( $post_id ){
400
+	public static function image($post_id) {
401 401
 		$file_array = array();
402 402
 
403 403
 		// Get the image from the API
404 404
 		$url = self::get_image_link();
405 405
 
406 406
 		// If the returned string is empty or it's not a string, try again.
407
-		if ( empty( $url ) || !is_string( $url ) ){
407
+		if (empty($url) || !is_string($url)) {
408 408
 
409 409
 			// Try again
410 410
 			$url = self::get_image_link();
411 411
 
412 412
 			// If it fails again, just give up
413
-			if ( empty( $url ) || !is_string( $url ) ){
413
+			if (empty($url) || !is_string($url)) {
414 414
 				return;
415 415
 			}
416 416
 
417 417
 		}
418 418
 
419 419
 		// Download the file
420
-	    $tmp = \download_url( $url );
420
+	    $tmp = \download_url($url);
421 421
 
422
-	    preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches );
422
+	    preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches);
423 423
 
424
-        $file_array['name'] = basename( $matches[0] );
424
+        $file_array['name'] = basename($matches[0]);
425 425
         $file_array['tmp_name'] = $tmp;
426 426
 
427 427
 	    // Check for download errors
428
-	    if ( is_wp_error( $tmp ) ) {
429
-	        unlink( $file_array[ 'tmp_name' ] );
430
-	        error_log( $tmp->get_error_message() );
428
+	    if (is_wp_error($tmp)) {
429
+	        unlink($file_array['tmp_name']);
430
+	        error_log($tmp->get_error_message());
431 431
 	    }
432 432
 
433 433
 		// Pull the image into the media library
434
-	    $image_id = media_handle_sideload( $file_array, $post_id );
434
+	    $image_id = media_handle_sideload($file_array, $post_id);
435 435
 
436 436
 	    // Check for handle sideload errors.
437
-	    if ( is_wp_error( $image_id ) ) {
438
-	        unlink( $file_array['tmp_name'] );
439
-	        error_log( $image_id->get_error_message() );
437
+	    if (is_wp_error($image_id)) {
438
+	        unlink($file_array['tmp_name']);
439
+	        error_log($image_id->get_error_message());
440 440
 	    }
441 441
 
442
-	    return apply_filters( "tc_image_data", $image_id );
442
+	    return apply_filters("tc_image_data", $image_id);
443 443
 
444 444
 	}
445 445
 
@@ -451,31 +451,31 @@  discard block
 block discarded – undo
451 451
 	 *
452 452
 	 * @return string Image URL.
453 453
 	 */
454
-	private static function get_image_link(){
454
+	private static function get_image_link() {
455 455
 
456 456
 		// cURL an image API for a completely random photo
457
-		$curl = curl_init( "http://www.splashbase.co/api/v1/images/random?images_only=true" );
457
+		$curl = curl_init("http://www.splashbase.co/api/v1/images/random?images_only=true");
458 458
 
459
-		curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE );
459
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
460 460
 
461
-		$curl_response = curl_exec( $curl );
461
+		$curl_response = curl_exec($curl);
462 462
 
463 463
 		// If our cURL failed
464
-		if ( $curl_response === false ) {
465
-		    $info = curl_getinfo( $curl );
466
-		    curl_close( $curl );
467
-		    die( 'error occured during curl exec. Additional info: ' . var_export( $info ) );
464
+		if ($curl_response === false) {
465
+		    $info = curl_getinfo($curl);
466
+		    curl_close($curl);
467
+		    die('error occured during curl exec. Additional info: '.var_export($info));
468 468
 		}
469 469
 
470
-		curl_close( $curl );
470
+		curl_close($curl);
471 471
 
472 472
 		// Decode the data
473
-		$response = json_decode( $curl_response, true );
473
+		$response = json_decode($curl_response, true);
474 474
 
475 475
 		// Check to make sure that the return contains a valid image extensions
476 476
 		preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $response['url'], $matches);
477 477
 
478
-		if ( !empty( $matches ) ){
478
+		if (!empty($matches)) {
479 479
 			return $response['url'];
480 480
 		}
481 481
 
@@ -490,12 +490,12 @@  discard block
 block discarded – undo
490 490
 	 * @param string $format PHP Date format.
491 491
 	 * @return mixed Date in the format requested.
492 492
 	 */
493
-	public static function date( $format ){
493
+	public static function date($format) {
494 494
 
495
-		$num_days = rand( 1, 60 );
496
-		$date = date( $format, strtotime( " +$num_days days" ) );
495
+		$num_days = rand(1, 60);
496
+		$date = date($format, strtotime(" +$num_days days"));
497 497
 
498
-		return apply_filters( "tc_date_data", $date );
498
+		return apply_filters("tc_date_data", $date);
499 499
 
500 500
 	}
501 501
 
@@ -507,19 +507,19 @@  discard block
 block discarded – undo
507 507
 	 *
508 508
 	 * @return string Time string
509 509
 	 */
510
-	public static function time(){
510
+	public static function time() {
511 511
 
512 512
 		$times = array(
513 513
 			'8:00 am',
514 514
 			'5:00PM',
515 515
 			'13:00',
516 516
 			'2015',
517
-			date( 'G:i', strtotime( " +".rand( 4, 24 )." hours" ) ),
518
-			date( 'g:i', strtotime( " +".rand( 4, 24 )." hours" ) ),
519
-			date( 'G:i A', strtotime( " +".rand( 4, 24 )." hours" ) )
517
+			date('G:i', strtotime(" +".rand(4, 24)." hours")),
518
+			date('g:i', strtotime(" +".rand(4, 24)." hours")),
519
+			date('G:i A', strtotime(" +".rand(4, 24)." hours"))
520 520
 		);
521 521
 
522
-		return apply_filters( "tc_time_data", $times[ rand( 0, 6 ) ] );
522
+		return apply_filters("tc_time_data", $times[rand(0, 6)]);
523 523
 
524 524
 	}
525 525
 
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 	 *
532 532
 	 * @return string Timezone
533 533
 	 */
534
-	public static function timezone(){
534
+	public static function timezone() {
535 535
 
536 536
 		$timezones = array(
537 537
 			'America/Denver',
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 			'UTC'
550 550
 		);
551 551
 
552
-		return apply_filters( "tc_timezone_data", $timezones[ rand( 0, 12 ) ] );
552
+		return apply_filters("tc_timezone_data", $timezones[rand(0, 12)]);
553 553
 
554 554
 	}
555 555
 
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 	 *
563 563
 	 * @return string Phone #.
564 564
 	 */
565
-	public static function phone(){
565
+	public static function phone() {
566 566
 
567 567
 		$phone_numbers = array(
568 568
 			'7203893101',
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 			'+43 780 0047112'
579 579
 		);
580 580
 
581
-		return apply_filters( "tc_phone_data", $phone_numbers[ rand( 0, 10 ) ] );
581
+		return apply_filters("tc_phone_data", $phone_numbers[rand(0, 10)]);
582 582
 
583 583
 	}
584 584
 
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 	 *
591 591
 	 * @return string Email address.
592 592
 	 */
593
-	public static function email(){
593
+	public static function email() {
594 594
 
595 595
 		$email_addresses = array(
596 596
 			'[email protected]',
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 			'[email protected]'
604 604
 		);
605 605
 
606
-		return apply_filters( "tc_email_data", $email_addresses[ rand( 0, 7 ) ] );
606
+		return apply_filters("tc_email_data", $email_addresses[rand(0, 7)]);
607 607
 
608 608
 	}
609 609
 
@@ -617,12 +617,12 @@  discard block
 block discarded – undo
617 617
 	 *
618 618
 	 * @return string URL.
619 619
 	 */
620
-	public static function link(){
620
+	public static function link() {
621 621
 
622 622
 		$links = array(
623 623
 			'http://google.com',
624 624
 			'https://www.twitter.com',
625
-			site_url( '/?iam=anextravariable' ),
625
+			site_url('/?iam=anextravariable'),
626 626
 			'github.com',
627 627
 			'http://filebase.com',
628 628
 			'www.oldtownmediainc.com',
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 			'https://www.eff.org'
631 631
 		);
632 632
 
633
-		return apply_filters( "tc_link_data", $links[ rand( 0, 7 ) ] );
633
+		return apply_filters("tc_link_data", $links[rand(0, 7)]);
634 634
 
635 635
 	}
636 636
 
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
 	 *
642 642
 	 * @return string URL.
643 643
 	 */
644
-	public static function oembed(){
644
+	public static function oembed() {
645 645
 
646 646
 		$links = array(
647 647
 			'https://www.youtube.com/watch?v=A85-YQsm6pY',
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 			'https://www.instagram.com/p/-eyLo0RMfX',
653 653
 		);
654 654
 
655
-		return apply_filters( "tc_oembed_data", $links[ rand( 0, 5 ) ] );
655
+		return apply_filters("tc_oembed_data", $links[rand(0, 5)]);
656 656
 
657 657
 	}
658 658
 
@@ -666,10 +666,10 @@  discard block
 block discarded – undo
666 666
 	 * @param	string $type Video service to get link from
667 667
 	 * @return	string URL.
668 668
 	 */
669
-	public static function video( $type ){
669
+	public static function video($type) {
670 670
 
671 671
 		// Switch through our video types. Expecting to add more in the future
672
-		switch( $type ){
672
+		switch ($type) {
673 673
 
674 674
 			// YouTube videos
675 675
 			case 'youtube' :
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
 
711 711
 		}
712 712
 
713
-		return apply_filters( "tc_video_data", $links[ rand( 0, 8 ) ] );
713
+		return apply_filters("tc_video_data", $links[rand(0, 8)]);
714 714
 
715 715
 	}
716 716
 
Please login to merge, or discard this patch.
includes/class-create-term.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @subpackage Evans
9 9
  * @author     Old Town Media
10 10
  */
11
-class CreateTerm{
11
+class CreateTerm {
12 12
 
13 13
 	/**
14 14
 	 * Create test data posts.
@@ -25,25 +25,25 @@  discard block
 block discarded – undo
25 25
 	 * @param boolean $echo Whether or not to echo. Optional.
26 26
 	 * @param int $num Optional. Number of posts to create.
27 27
 	 */
28
-	public function create_terms( $slug, $echo = false, $num = '' ){
28
+	public function create_terms($slug, $echo = false, $num = '') {
29 29
 
30 30
 		// If we're missing a custom post type id - don't do anything
31
-		if ( empty( $slug ) ){
31
+		if (empty($slug)) {
32 32
 			return;
33 33
 		}
34 34
 
35 35
 		// If we forgot to put in a quantity, make one for us
36
-		if ( empty( $num ) ){
37
-			$num = rand( 5, 30 );
36
+		if (empty($num)) {
37
+			$num = rand(5, 30);
38 38
 		}
39 39
 
40 40
 		// Create test terms
41
-		for( $i = 0; $i < $num; $i++ ){
41
+		for ($i = 0; $i < $num; $i++) {
42 42
 
43
-			$return = $this->create_test_object( $slug );
43
+			$return = $this->create_test_object($slug);
44 44
 
45
-			if ( $echo === true ){
46
-				echo \json_encode( $return );
45
+			if ($echo === true) {
46
+				echo \json_encode($return);
47 47
 			}
48 48
 
49 49
 		}
@@ -64,27 +64,27 @@  discard block
 block discarded – undo
64 64
 	 *
65 65
 	 * @param string $slug a custom post type ID.
66 66
 	 */
67
-	private function create_test_object( $slug ){
67
+	private function create_test_object($slug) {
68 68
 
69 69
 		// Get a random title
70
-		$title = apply_filters( "tc_{$slug}_term_title", TestContent::title() );
70
+		$title = apply_filters("tc_{$slug}_term_title", TestContent::title());
71 71
 
72 72
 		$return = wp_insert_term(
73 73
 			$title,
74 74
 			$slug,
75
-			apply_filters( "tc_{$slug}_term_arguments", array(
75
+			apply_filters("tc_{$slug}_term_arguments", array(
76 76
 					'description'=> TestContent::title(),
77
-					'slug' => sanitize_title( $title ),
77
+					'slug' => sanitize_title($title),
78 78
 				)
79 79
 			)
80 80
 		);
81 81
 
82 82
 		// Then, set a test content flag on the new post for later deletion
83
-		add_term_meta( $return['term_id'], 'evans_test_content', '__test__', true );
83
+		add_term_meta($return['term_id'], 'evans_test_content', '__test__', true);
84 84
 
85 85
 		// Check if we have errors and return them or created message
86
-		if ( is_wp_error( $return ) ){
87
-			error_log( $return->get_error_message() );
86
+		if (is_wp_error($return)) {
87
+			error_log($return->get_error_message());
88 88
 			return $return;
89 89
 		} else {
90 90
 			return array(
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 				'object'	=> 'term',
93 93
 				'tid'		=> $return['term_id'],
94 94
 				'taxonomy'	=> $slug,
95
-				'link_edit'	=> admin_url( '/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id'] ),
96
-				'link_view'	=> get_term_link( $return['term_id'] )
95
+				'link_edit'	=> admin_url('/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id']),
96
+				'link_view'	=> get_term_link($return['term_id'])
97 97
 			);
98 98
 		}
99 99
 
Please login to merge, or discard this patch.