Completed
Branch master (f19787)
by Mike
02:06
created
includes/class-create.php 2 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,6 @@  discard block
 block discarded – undo
22 22
 	 * @see $this-get_cpt_supports, $this->get_metaboxes, $this->create_test_object
23 23
 	 *
24 24
 	 * @param string $cptslug a custom post type ID.
25
-	 * @param boolean $true Whether or not to echo. Optional.
26 25
 	 * @param int $num Optional. Number of posts to create.
27 26
 	 */
28 27
 	public function create_post_type_content( $cptslug, $echo = false, $num = '' ){
@@ -209,6 +208,9 @@  discard block
 block discarded – undo
209 208
 	}
210 209
 
211 210
 
211
+	/**
212
+	 * @param string $cptslug
213
+	 */
212 214
 	private function get_metaboxes( $cptslug ){
213 215
 
214 216
 		if ( class_exists( 'CMB2_Bootstrap_212', false ) ) {
Please login to merge, or discard this patch.
Spacing   +80 added lines, -80 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 Create{
11
+class Create {
12 12
 
13 13
 	/**
14 14
 	 * Create test data posts.
@@ -25,28 +25,28 @@  discard block
 block discarded – undo
25 25
 	 * @param boolean $true Whether or not to echo. Optional.
26 26
 	 * @param int $num Optional. Number of posts to create.
27 27
 	 */
28
-	public function create_post_type_content( $cptslug, $echo = false, $num = '' ){
28
+	public function create_post_type_content($cptslug, $echo = false, $num = '') {
29 29
 
30 30
 		// If we're missing a custom post type id - don't do anything
31
-		if ( empty( $cptslug ) ){
31
+		if (empty($cptslug)) {
32 32
 			return;
33 33
 		}
34 34
 
35 35
 		// Gather the necessary data to create the posts
36
-		$supports 	= $this->get_cpt_supports( $cptslug );
37
-		$metaboxes	= $this->get_metaboxes( $cptslug );
36
+		$supports 	= $this->get_cpt_supports($cptslug);
37
+		$metaboxes	= $this->get_metaboxes($cptslug);
38 38
 
39 39
 		// If we forgot to put in a quantity, make one for us
40
-		if ( empty( $num ) ){
41
-			$num = rand( 5, 30 );
40
+		if (empty($num)) {
41
+			$num = rand(5, 30);
42 42
 		}
43 43
 
44 44
 		// Create test posts
45
-		for( $i = 0; $i < $num; $i++ ){
45
+		for ($i = 0; $i < $num; $i++) {
46 46
 
47
-			$return = $this->create_test_object( $cptslug, $supports, $metaboxes );
47
+			$return = $this->create_test_object($cptslug, $supports, $metaboxes);
48 48
 
49
-			if ( $echo === true ){
49
+			if ($echo === true) {
50 50
 				echo $return;
51 51
 			}
52 52
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 * @param array $supports Features that the post type supports.
71 71
 	 * @param array $supports All CMB2 metaboxes attached to the post type.
72 72
 	 */
73
-	private function create_test_object( $cptslug, $supports, $metaboxes ){
73
+	private function create_test_object($cptslug, $supports, $metaboxes) {
74 74
 		$return = '';
75 75
 
76 76
 		// Get a random title
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
 		// First, insert our post
80 80
 		$post = array(
81
-		  'post_name'      => sanitize_title( $title ),
81
+		  'post_name'      => sanitize_title($title),
82 82
 		  'post_status'    => 'publish',
83 83
 		  'post_type'      => $cptslug,
84 84
 		  'ping_status'    => 'closed',
@@ -86,45 +86,45 @@  discard block
 block discarded – undo
86 86
 		);
87 87
 
88 88
 		// Add title if supported
89
-		if ( $supports['title'] === true ){
89
+		if ($supports['title'] === true) {
90 90
 			$post['post_title'] = $title;
91 91
 		}
92 92
 
93 93
 		// Add main content if supported
94
-		if ( $supports['editor'] === true ){
94
+		if ($supports['editor'] === true) {
95 95
 			$post['post_content'] = TestContent::paragraphs();
96 96
 		}
97 97
 
98 98
 		// Insert then post object
99
-		$post_id = wp_insert_post( $post );
99
+		$post_id = wp_insert_post($post);
100 100
 
101 101
 		// Then, set a test content flag on the new post for later deletion
102
-		add_post_meta( $post_id, 'evans_test_content', '__test__', true );
102
+		add_post_meta($post_id, 'evans_test_content', '__test__', true);
103 103
 
104 104
 		// Add thumbnail if supported
105
-		if ( $supports['thumbnail'] === true || in_array( $cptslug, array( 'post', 'page' ) ) ){
106
-			 update_post_meta( $post_id, '_thumbnail_id', TestContent::image( $post_id ) );
105
+		if ($supports['thumbnail'] === true || in_array($cptslug, array('post', 'page'))) {
106
+			 update_post_meta($post_id, '_thumbnail_id', TestContent::image($post_id));
107 107
 		}
108 108
 
109
-		$taxonomies = get_object_taxonomies( $cptslug );
109
+		$taxonomies = get_object_taxonomies($cptslug);
110 110
 
111 111
 		// Assign the post to terms
112
-		if ( !empty( $taxonomies ) ){
113
-			$return .= $this->assign_terms( $post_id, $taxonomies );
112
+		if (!empty($taxonomies)) {
113
+			$return .= $this->assign_terms($post_id, $taxonomies);
114 114
 		}
115 115
 
116 116
 		// Spin up metaboxes
117
-		if ( !empty( $metaboxes ) ){
118
-			foreach ( $metaboxes as $cmb ) :
119
-				$return .= $this->random_metabox_content( $post_id, $cmb );
117
+		if (!empty($metaboxes)) {
118
+			foreach ($metaboxes as $cmb) :
119
+				$return .= $this->random_metabox_content($post_id, $cmb);
120 120
 			endforeach;
121 121
 		}
122 122
 
123 123
 		// Check if we have errors and return them or created message
124
-		if ( is_wp_error( $return ) ){
124
+		if (is_wp_error($return)) {
125 125
 			return $return;
126 126
 		} else {
127
-			return "Created " . get_post_type( $post_id ) . " $post_id: " . admin_url( '/post.php?post='.$post_id.'&action=edit' ) . "
127
+			return "Created " . get_post_type($post_id) . " $post_id: " . admin_url('/post.php?post=' . $post_id . '&action=edit') . "
128 128
 ";
129 129
 		}
130 130
 
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
 	 * @param string $cptslug a custom post type ID.
142 142
 	 * @return array Array of necessary supports booleans.
143 143
 	 */
144
-	private function get_cpt_supports( $cptslug ){
144
+	private function get_cpt_supports($cptslug) {
145 145
 
146 146
 		$supports = array(
147
-			'title'		=> post_type_supports( $cptslug, 'title' ),
148
-			'editor'	=> post_type_supports( $cptslug, 'editor' ),
149
-			'thumbnail'	=> post_type_supports( $cptslug, 'thumbnail' )
147
+			'title'		=> post_type_supports($cptslug, 'title'),
148
+			'editor'	=> post_type_supports($cptslug, 'editor'),
149
+			'thumbnail'	=> post_type_supports($cptslug, 'thumbnail')
150 150
 		);
151 151
 
152 152
 		return $supports;
@@ -167,26 +167,26 @@  discard block
 block discarded – undo
167 167
 	 * @param array $taxonomies taxonomies assigned to this cpt.
168 168
 	 * @return object WP Error if there is one.
169 169
 	 */
170
-	private function assign_terms( $post_id, $taxonomies ){
170
+	private function assign_terms($post_id, $taxonomies) {
171 171
 
172 172
 		// Make sure it's an array & has items
173
-		if ( empty( $taxonomies ) || !is_array( $taxonomies ) ){
173
+		if (empty($taxonomies) || !is_array($taxonomies)) {
174 174
 			return;
175 175
 		}
176 176
 
177
-		foreach ( $taxonomies as $tax ){
177
+		foreach ($taxonomies as $tax) {
178 178
 
179 179
 			// Get the individual terms already existing
180
-			$terms = get_terms( $tax, array( 'hide_empty'	=> false ) );
181
-			$count = count( $terms ) - 1;
180
+			$terms = get_terms($tax, array('hide_empty'	=> false));
181
+			$count = count($terms) - 1;
182 182
 
183 183
 			// If there are no terms, skip to the next taxonomy
184
-			if ( empty( $terms ) ){
184
+			if (empty($terms)) {
185 185
 				continue;
186 186
 			}
187 187
 
188 188
 			// Get a random index to use
189
-			$index = rand( 0, $count );
189
+			$index = rand(0, $count);
190 190
 
191 191
 			// Initialize our array
192 192
 			$post_data = array(
@@ -194,13 +194,13 @@  discard block
 block discarded – undo
194 194
 			);
195 195
 
196 196
 			// Set the term data to update
197
-			$post_data['tax_input'][ $tax ] = array( $terms[$index]->term_id );
197
+			$post_data['tax_input'][$tax] = array($terms[$index]->term_id);
198 198
 
199 199
 			// Update the post with the taxonomy info
200
-			$return = wp_update_post( $post_data );
200
+			$return = wp_update_post($post_data);
201 201
 
202 202
 			// Return the error if it exists
203
-			if ( is_wp_error( $return ) ){
203
+			if (is_wp_error($return)) {
204 204
 				return $return->get_error_messages();
205 205
 			}
206 206
 
@@ -209,14 +209,14 @@  discard block
 block discarded – undo
209 209
 	}
210 210
 
211 211
 
212
-	private function get_metaboxes( $cptslug ){
212
+	private function get_metaboxes($cptslug) {
213 213
 
214
-		if ( class_exists( 'CMB2_Bootstrap_212', false ) ) {
215
-			$fields = $this->get_cmb2_metaboxes( $cptslug );
214
+		if (class_exists('CMB2_Bootstrap_212', false)) {
215
+			$fields = $this->get_cmb2_metaboxes($cptslug);
216 216
 		}
217 217
 
218
-		if ( class_exists( 'cmb_Meta_Box', false ) ) {
219
-			$fields = $this->get_cmb1_metaboxes( $cptslug );
218
+		if (class_exists('cmb_Meta_Box', false)) {
219
+			$fields = $this->get_cmb1_metaboxes($cptslug);
220 220
 		}
221 221
 
222 222
 		return $fields;
@@ -238,25 +238,25 @@  discard block
 block discarded – undo
238 238
 	 * @param string $cptslug a custom post type ID.
239 239
 	 * @return array Array of fields.
240 240
 	 */
241
-	private function get_cmb2_metaboxes( $cptslug ){
241
+	private function get_cmb2_metaboxes($cptslug) {
242 242
 
243 243
 		$fields = array();
244 244
 
245 245
 		// Get all metaboxes from CMB2 library
246
-		$all_metaboxes = apply_filters( 'cmb2_meta_boxes', array() );
246
+		$all_metaboxes = apply_filters('cmb2_meta_boxes', array());
247 247
 
248 248
 		// Loop through all possible sets of metaboxes
249
-		foreach ( $all_metaboxes as $metabox_array ){
249
+		foreach ($all_metaboxes as $metabox_array) {
250 250
 
251 251
 			// If the custom post type ID matches this set of fields, set & stop
252
-			if ( in_array( $cptslug, $metabox_array['object_types'] ) ) {
252
+			if (in_array($cptslug, $metabox_array['object_types'])) {
253 253
 
254 254
 				// If this is the first group of fields, simply set the value
255 255
 				// Else, merge this group with the previous one
256
-				if ( empty( $fields ) ){
256
+				if (empty($fields)) {
257 257
 					$fields = $metabox_array['fields'];
258 258
 				} else {
259
-					$fields = array_merge( $fields, $metabox_array['fields'] );
259
+					$fields = array_merge($fields, $metabox_array['fields']);
260 260
 				}
261 261
 			}
262 262
 
@@ -280,25 +280,25 @@  discard block
 block discarded – undo
280 280
 	 * @param string $cptslug a custom post type ID.
281 281
 	 * @return array Array of fields.
282 282
 	 */
283
-	private function get_cmb1_metaboxes( $cptslug ){
283
+	private function get_cmb1_metaboxes($cptslug) {
284 284
 
285 285
 		$fields = array();
286 286
 
287 287
 		// Get all metaboxes from CMB2 library
288
-		$all_metaboxes = apply_filters( 'cmb_meta_boxes', array() );
288
+		$all_metaboxes = apply_filters('cmb_meta_boxes', array());
289 289
 
290 290
 		// Loop through all possible sets of metaboxes
291
-		foreach ( $all_metaboxes as $metabox_array ){
291
+		foreach ($all_metaboxes as $metabox_array) {
292 292
 
293 293
 			// If the custom post type ID matches this set of fields, set & stop
294
-			if ( in_array( $cptslug, $metabox_array['pages'] ) ) {
294
+			if (in_array($cptslug, $metabox_array['pages'])) {
295 295
 
296 296
 				// If this is the first group of fields, simply set the value
297 297
 				// Else, merge this group with the previous one
298
-				if ( empty( $fields ) ){
298
+				if (empty($fields)) {
299 299
 					$fields = $metabox_array['fields'];
300 300
 				} else {
301
-					$fields = array_merge( $fields, $metabox_array['fields'] );
301
+					$fields = array_merge($fields, $metabox_array['fields']);
302 302
 				}
303 303
 			}
304 304
 
@@ -323,35 +323,35 @@  discard block
 block discarded – undo
323 323
 	 * @param int $post_id Single post ID.
324 324
 	 * @param array $cmb custom metabox array from CMB2.
325 325
 	 */
326
-	private function random_metabox_content( $post_id, $cmb ){
326
+	private function random_metabox_content($post_id, $cmb) {
327 327
 		$value = '';
328 328
 
329 329
 		// First check that our post ID & cmb array aren't empty
330
-		if ( empty( $cmb ) || empty( $post_id ) ){
330
+		if (empty($cmb) || empty($post_id)) {
331 331
 			return;
332 332
 		}
333 333
 
334
-		switch( $cmb['type'] ){
334
+		switch ($cmb['type']) {
335 335
 
336 336
 			case 'text':
337 337
 			case 'text_small':
338 338
 			case 'text_medium':
339 339
 
340 340
 				// If phone is in the id, fetch a phone #
341
-				if ( stripos( $cmb['id'], 'phone' ) ){
341
+				if (stripos($cmb['id'], 'phone')) {
342 342
 					$value = TestContent::phone();
343 343
 
344 344
 				// If email is in the id, fetch an email address
345
-				} elseif ( stripos( $cmb['id'], 'email' ) ){
345
+				} elseif (stripos($cmb['id'], 'email')) {
346 346
 					$value = TestContent::email();
347 347
 
348 348
 				// If time is in the id, fetch a time string
349
-				} elseif ( stripos( $cmb['id'], 'time' ) ){
349
+				} elseif (stripos($cmb['id'], 'time')) {
350 350
 					$value = TestContent::time();
351 351
 
352 352
 				// Otherwise, just a random text string
353 353
 				} else {
354
-					$value = TestContent::title( rand( 10, 50 ) );
354
+					$value = TestContent::title(rand(10, 50));
355 355
 				}
356 356
 
357 357
 				break;
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
 
379 379
 			case 'text_date':
380 380
 
381
-				$value = TestContent::date( 'm/d/Y' );
381
+				$value = TestContent::date('m/d/Y');
382 382
 
383 383
 				break;
384 384
 
385 385
 			case 'text_date_timestamp':
386 386
 			case 'text_datetime_timestamp':
387 387
 
388
-				$value = TestContent::date( 'U' );
388
+				$value = TestContent::date('U');
389 389
 
390 390
 				break;
391 391
 
@@ -393,13 +393,13 @@  discard block
 block discarded – undo
393 393
 
394 394
 			case 'text_money':
395 395
 
396
-				$value = rand( 0, 100000 );
396
+				$value = rand(0, 100000);
397 397
 
398 398
 				break;
399 399
 
400 400
 			case 'test_colorpicker':
401 401
 
402
-				$value = '#' . str_pad( dechex( mt_rand( 0, 0xFFFFFF ) ), 6, '0', STR_PAD_LEFT );
402
+				$value = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
403 403
 
404 404
 				break;
405 405
 
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
 			case 'radio':
417 417
 
418 418
 				// Grab a random item out of the array and return the key
419
-				$new_val = array_slice( $cmb['options'], rand( 0, count( $cmb['options'] ) ), 1 );
420
-				$value = key( $new_val );
419
+				$new_val = array_slice($cmb['options'], rand(0, count($cmb['options'])), 1);
420
+				$value = key($new_val);
421 421
 
422 422
 				break;
423 423
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 			case 'checkbox':
429 429
 
430 430
 				// 50/50 odds of being turned on
431
-				if ( rand( 0, 1 ) == 1 ){
431
+				if (rand(0, 1) == 1) {
432 432
 					$value = 'on';
433 433
 				}
434 434
 
@@ -439,10 +439,10 @@  discard block
 block discarded – undo
439 439
 				$new_option = array();
440 440
 
441 441
 				// Loop through each of our options
442
-				foreach ( $cmb['options'] as $key => $value ){
442
+				foreach ($cmb['options'] as $key => $value) {
443 443
 
444 444
 					// 50/50 chance of being included
445
-					if ( rand( 0, 1 ) ){
445
+					if (rand(0, 1)) {
446 446
 						$new_option[] = $key;
447 447
 					}
448 448
 
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 
461 461
 			case 'file':
462 462
 
463
-				$value = TestContent::image( $post_id );
463
+				$value = TestContent::image($post_id);
464 464
 
465 465
 				break;
466 466
 
@@ -475,19 +475,19 @@  discard block
 block discarded – undo
475 475
 		}
476 476
 
477 477
 		// Value must exist to attempt to insert
478
-		if ( !empty( $value ) && !is_wp_error( $value ) ){
478
+		if (!empty($value) && !is_wp_error($value)) {
479 479
 
480 480
 			// Files must be treated separately - they use the attachment ID
481 481
 			// & url of media for separate cmb values
482
-			if ( $cmb['type'] != 'file' ){
483
-				add_post_meta( $post_id, $cmb['id'], $value, true );
482
+			if ($cmb['type'] != 'file') {
483
+				add_post_meta($post_id, $cmb['id'], $value, true);
484 484
 			} else {
485
-				add_post_meta( $post_id, $cmb['id'].'_id', $value, true );
486
-				add_post_meta( $post_id, $cmb['id'], wp_get_attachment_url( $value ), true );
485
+				add_post_meta($post_id, $cmb['id'] . '_id', $value, true);
486
+				add_post_meta($post_id, $cmb['id'], wp_get_attachment_url($value), true);
487 487
 			}
488 488
 
489 489
 		// If we're dealing with a WP Error object, just return the message for debugging
490
-		} elseif ( is_wp_error( $value ) ){
490
+		} elseif (is_wp_error($value)) {
491 491
 			return $value->get_error_message();
492 492
 		}
493 493
 
Please login to merge, or discard this patch.
includes/class-test-content.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -323,7 +323,7 @@
 block discarded – undo
323 323
 	 * Return a date in the future (up to 60 days out) in the format prescribed.
324 324
 	 *
325 325
 	 * @param string $format PHP Date format.
326
-	 * @return mixed Date in the format requested.
326
+	 * @return string Date in the format requested.
327 327
 	 */
328 328
 	public static function date( $format ){
329 329
 
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -252,29 +252,29 @@  discard block
 block discarded – undo
252 252
 		}
253 253
 
254 254
 		// Download the file
255
-	    $tmp = \download_url( $url );
255
+		$tmp = \download_url( $url );
256 256
 
257
-	    preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches );
257
+		preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches );
258 258
 
259
-        $file_array['name'] = basename( $matches[0] );
260
-        $file_array['tmp_name'] = $tmp;
259
+		$file_array['name'] = basename( $matches[0] );
260
+		$file_array['tmp_name'] = $tmp;
261 261
 
262
-	    // Check for download errors
263
-	    if ( is_wp_error( $tmp ) ) {
264
-	        @unlink( $file_array[ 'tmp_name' ] );
265
-	        return $tmp->get_error_message();
266
-	    }
262
+		// Check for download errors
263
+		if ( is_wp_error( $tmp ) ) {
264
+			@unlink( $file_array[ 'tmp_name' ] );
265
+			return $tmp->get_error_message();
266
+		}
267 267
 
268 268
 		// Pull the image into the media library
269
-	    $image_id = media_handle_sideload( $file_array, $post_id );
269
+		$image_id = media_handle_sideload( $file_array, $post_id );
270 270
 
271
-	    // Check for handle sideload errors.
272
-	    if ( is_wp_error( $image_id ) ) {
273
-	        @unlink( $file_array['tmp_name'] );
274
-	        return $image_id->get_error_message();
275
-	    }
271
+		// Check for handle sideload errors.
272
+		if ( is_wp_error( $image_id ) ) {
273
+			@unlink( $file_array['tmp_name'] );
274
+			return $image_id->get_error_message();
275
+		}
276 276
 
277
-	    return $image_id;
277
+		return $image_id;
278 278
 
279 279
 	}
280 280
 
@@ -297,9 +297,9 @@  discard block
 block discarded – undo
297 297
 
298 298
 		// If our cURL failed
299 299
 		if ( $curl_response === false ) {
300
-		    $info = curl_getinfo( $curl );
301
-		    curl_close( $curl );
302
-		    die( 'error occured during curl exec. Additional info: ' . var_export( $info ) );
300
+			$info = curl_getinfo( $curl );
301
+			curl_close( $curl );
302
+			die( 'error occured during curl exec. Additional info: ' . var_export( $info ) );
303 303
 		}
304 304
 
305 305
 		curl_close( $curl );
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 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 substr( $title, 0, -1 );
79
+		return 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
 
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 			'Sed porttitor augue vitae ante posuere sodales iaculis nec neque. Etiam dapibus nulla id vulputate tempus. Quisque tempus nisi dui, a commodo nulla sodales ut. Nulla nec odio tempus, sodales diam quis, feugiat odio. Nulla tincidunt tincidunt turpis, eget cursus felis tempor lacinia. Aenean molestie libero ut erat luctus aliquam. Sed vel enim quis nisl lacinia posuere. Ut fringilla ligula ligula, nec rhoncus mi suscipit id. Praesent volutpat blandit felis, et suscipit elit vulputate sit amet. Morbi sit amet justo quis sem rutrum euismod. Pellentesque at dictum sem, sed condimentum ex. Vivamus massa nisi, convallis in semper sit amet, venenatis convallis lectus. Nunc tristique, ex ac rutrum vehicula, arcu ex efficitur justo, sed euismod ligula nulla ut purus.',
186 186
 		);
187 187
 
188
-		for( $i = 1; $i < 6; $i++ ){
189
-			$content .= $random_content_types[rand( 0, 9 )];
188
+		for ($i = 1; $i < 6; $i++) {
189
+			$content .= $random_content_types[rand(0, 9)];
190 190
 		}
191 191
 
192 192
 		return $content;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 *
202 202
 	 * @return string Plain text paragraphs.
203 203
 	 */
204
-	public static function plain_text(){
204
+	public static function plain_text() {
205 205
 
206 206
 		$paragraphs = array(
207 207
 			'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.',
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 			'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.',
217 217
 		);
218 218
 
219
-		return $paragraphs[ rand( 0, 9 ) ];
219
+		return $paragraphs[rand(0, 9)];
220 220
 
221 221
 	}
222 222
 
@@ -232,45 +232,45 @@  discard block
 block discarded – undo
232 232
 	 * @param int $post_id Post ID.
233 233
 	 * @return mixed Attachment ID or WP Error.
234 234
 	 */
235
-	public static function image( $post_id ){
235
+	public static function image($post_id) {
236 236
 		$file_array = array();
237 237
 
238 238
 		// Get the image from the API
239 239
 		$url = self::get_image_link();
240 240
 
241 241
 		// If the returned string is empty or it's not a string, try again.
242
-		if ( empty( $url ) || !is_string( $url ) ){
242
+		if (empty($url) || !is_string($url)) {
243 243
 
244 244
 			// Try again
245 245
 			$url = self::get_image_link();
246 246
 
247 247
 			// If it fails again, just give up
248
-			if ( empty( $url ) || !is_string( $url ) ){
248
+			if (empty($url) || !is_string($url)) {
249 249
 				return;
250 250
 			}
251 251
 
252 252
 		}
253 253
 
254 254
 		// Download the file
255
-	    $tmp = \download_url( $url );
255
+	    $tmp = \download_url($url);
256 256
 
257
-	    preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches );
257
+	    preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches);
258 258
 
259
-        $file_array['name'] = basename( $matches[0] );
259
+        $file_array['name'] = basename($matches[0]);
260 260
         $file_array['tmp_name'] = $tmp;
261 261
 
262 262
 	    // Check for download errors
263
-	    if ( is_wp_error( $tmp ) ) {
264
-	        @unlink( $file_array[ 'tmp_name' ] );
263
+	    if (is_wp_error($tmp)) {
264
+	        @unlink($file_array['tmp_name']);
265 265
 	        return $tmp->get_error_message();
266 266
 	    }
267 267
 
268 268
 		// Pull the image into the media library
269
-	    $image_id = media_handle_sideload( $file_array, $post_id );
269
+	    $image_id = media_handle_sideload($file_array, $post_id);
270 270
 
271 271
 	    // Check for handle sideload errors.
272
-	    if ( is_wp_error( $image_id ) ) {
273
-	        @unlink( $file_array['tmp_name'] );
272
+	    if (is_wp_error($image_id)) {
273
+	        @unlink($file_array['tmp_name']);
274 274
 	        return $image_id->get_error_message();
275 275
 	    }
276 276
 
@@ -286,31 +286,31 @@  discard block
 block discarded – undo
286 286
 	 *
287 287
 	 * @return string Image URL.
288 288
 	 */
289
-	private static function get_image_link(){
289
+	private static function get_image_link() {
290 290
 
291 291
 		// cURL an image API for a completely random photo
292
-		$curl = curl_init( "http://www.splashbase.co/api/v1/images/random?images_only=true" );
292
+		$curl = curl_init("http://www.splashbase.co/api/v1/images/random?images_only=true");
293 293
 
294
-		curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE );
294
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
295 295
 
296
-		$curl_response = curl_exec( $curl );
296
+		$curl_response = curl_exec($curl);
297 297
 
298 298
 		// If our cURL failed
299
-		if ( $curl_response === false ) {
300
-		    $info = curl_getinfo( $curl );
301
-		    curl_close( $curl );
302
-		    die( 'error occured during curl exec. Additional info: ' . var_export( $info ) );
299
+		if ($curl_response === false) {
300
+		    $info = curl_getinfo($curl);
301
+		    curl_close($curl);
302
+		    die('error occured during curl exec. Additional info: ' . var_export($info));
303 303
 		}
304 304
 
305
-		curl_close( $curl );
305
+		curl_close($curl);
306 306
 
307 307
 		// Decode the data
308
-		$response = json_decode( $curl_response, true );
308
+		$response = json_decode($curl_response, true);
309 309
 
310 310
 		// Check to make sure that the return contains a valid image extensions
311 311
 		preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $response['url'], $matches);
312 312
 
313
-		if ( !empty( $matches ) ){
313
+		if (!empty($matches)) {
314 314
 			return $response['url'];
315 315
 		}
316 316
 
@@ -325,10 +325,10 @@  discard block
 block discarded – undo
325 325
 	 * @param string $format PHP Date format.
326 326
 	 * @return mixed Date in the format requested.
327 327
 	 */
328
-	public static function date( $format ){
328
+	public static function date($format) {
329 329
 
330
-		$num_days = rand( 1, 60 );
331
-		return date( $format, strtotime( " +$num_days days" ) );
330
+		$num_days = rand(1, 60);
331
+		return date($format, strtotime(" +$num_days days"));
332 332
 
333 333
 	}
334 334
 
@@ -340,19 +340,19 @@  discard block
 block discarded – undo
340 340
 	 *
341 341
 	 * @return string Time string
342 342
 	 */
343
-	public static function time(){
343
+	public static function time() {
344 344
 
345 345
 		$times = array(
346 346
 			'8:00 am',
347 347
 			'5:00PM',
348 348
 			'13:00',
349 349
 			'2015',
350
-			date( 'G:i', strtotime( " +".rand( 4, 24 )." hours" ) ),
351
-			date( 'g:i', strtotime( " +".rand( 4, 24 )." hours" ) ),
352
-			date( 'G:i A', strtotime( " +".rand( 4, 24 )." hours" ) )
350
+			date('G:i', strtotime(" +" . rand(4, 24) . " hours")),
351
+			date('g:i', strtotime(" +" . rand(4, 24) . " hours")),
352
+			date('G:i A', strtotime(" +" . rand(4, 24) . " hours"))
353 353
 		);
354 354
 
355
-		return $times[ rand( 0, 6 ) ];
355
+		return $times[rand(0, 6)];
356 356
 
357 357
 	}
358 358
 
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 	 *
365 365
 	 * @return string Timezone
366 366
 	 */
367
-	public static function timezone(){
367
+	public static function timezone() {
368 368
 
369 369
 		$timezones = array(
370 370
 			'America/Denver',
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 			'UTC'
383 383
 		);
384 384
 
385
-		return $timezones[ rand( 0, 12 ) ];
385
+		return $timezones[rand(0, 12)];
386 386
 
387 387
 	}
388 388
 
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
 	 *
396 396
 	 * @return string Phone #.
397 397
 	 */
398
-	public static function phone(){
398
+	public static function phone() {
399 399
 
400 400
 		$phone_numbers = array(
401 401
 			'7203893101',
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 			'+43 780 0047112'
412 412
 		);
413 413
 
414
-		return $phone_numbers[ rand( 0, 10 ) ];
414
+		return $phone_numbers[rand(0, 10)];
415 415
 
416 416
 	}
417 417
 
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
 	 *
424 424
 	 * @return string Email address.
425 425
 	 */
426
-	public static function email(){
426
+	public static function email() {
427 427
 
428 428
 		$email_addresses = array(
429 429
 			'[email protected]',
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
 			'[email protected]'
437 437
 		);
438 438
 
439
-		return $email_addresses[ rand( 0, 7 ) ];
439
+		return $email_addresses[rand(0, 7)];
440 440
 
441 441
 	}
442 442
 
@@ -450,12 +450,12 @@  discard block
 block discarded – undo
450 450
 	 *
451 451
 	 * @return string URL.
452 452
 	 */
453
-	public static function link(){
453
+	public static function link() {
454 454
 
455 455
 		$links = array(
456 456
 			'http://google.com',
457 457
 			'https://www.twitter.com',
458
-			site_url( '/?iam=anextravariable' ),
458
+			site_url('/?iam=anextravariable'),
459 459
 			'github.com',
460 460
 			'http://filebase.com',
461 461
 			'www.oldtownmediainc.com',
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 			'https://www.eff.org'
464 464
 		);
465 465
 
466
-		return $links[ rand( 0, 7 ) ];
466
+		return $links[rand(0, 7)];
467 467
 
468 468
 	}
469 469
 
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 	 *
475 475
 	 * @return string URL.
476 476
 	 */
477
-	public static function oembed(){
477
+	public static function oembed() {
478 478
 
479 479
 		$links = array(
480 480
 			'https://www.youtube.com/watch?v=A85-YQsm6pY',
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 			'https://www.instagram.com/p/-eyLo0RMfX',
486 486
 		);
487 487
 
488
-		return $links[ rand( 0, 5 ) ];
488
+		return $links[rand(0, 5)];
489 489
 
490 490
 	}
491 491
 
Please login to merge, or discard this patch.
includes/admin-page.php 1 patch
Spacing   +25 added lines, -25 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 AdminPage{
11
+class AdminPage {
12 12
 
13 13
 	/**
14 14
 	 * Hooks function.
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @see admin_menu, wp_ajax actions
19 19
 	 */
20
-	public function hooks(){
20
+	public function hooks() {
21 21
 
22
-		add_action( 'admin_menu' , array( $this, 'add_menu_item' ) );
23
-		add_action( 'wp_ajax_handle_test_data', array( $this, 'handle_test_data_callback' ) );
24
-		add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ) );
22
+		add_action('admin_menu', array($this, 'add_menu_item'));
23
+		add_action('wp_ajax_handle_test_data', array($this, 'handle_test_data_callback'));
24
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts'));
25 25
 
26 26
 	}
27 27
 
@@ -34,25 +34,25 @@  discard block
 block discarded – undo
34 34
 
35 35
 		add_submenu_page(
36 36
 			'tools.php',
37
-			__( 'Create Test Data', 'evans-mu' ),
38
-			__( 'Test Data', 'evans-mu' ),
37
+			__('Create Test Data', 'evans-mu'),
38
+			__('Test Data', 'evans-mu'),
39 39
 			'manage_options',
40 40
 			'create-test-data',
41
-			array( $this, 'admin_page' )
41
+			array($this, 'admin_page')
42 42
 		);
43 43
 
44 44
 	}
45 45
 
46 46
 
47
-	public function load_scripts( $hook ){
47
+	public function load_scripts($hook) {
48 48
 
49
-		wp_enqueue_script( 'test-content-js', plugins_url( 'assets/admin.js' , dirname( __FILE__ ) ) );
49
+		wp_enqueue_script('test-content-js', plugins_url('assets/admin.js', dirname(__FILE__)));
50 50
 
51 51
 		$data = array(
52
-			'nonce'	=> wp_create_nonce( 'handle-test-data' )
52
+			'nonce'	=> wp_create_nonce('handle-test-data')
53 53
 		);
54 54
 
55
-		wp_localize_script( 'test-content-js', 'test_content', $data );
55
+		wp_localize_script('test-content-js', 'test_content', $data);
56 56
 
57 57
 	}
58 58
 
@@ -66,23 +66,23 @@  discard block
 block discarded – undo
66 66
 
67 67
 		$cptslug	= $_REQUEST['cptslug'];
68 68
 		$action		= $_REQUEST['todo'];
69
-		$nonce		= $_REQUEST['nonce'];
69
+		$nonce = $_REQUEST['nonce'];
70 70
 
71 71
 		// Verify that we have a proper logged in user and it's the right person
72
-		if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'handle-test-data' ) ){
72
+		if (empty($nonce) || !wp_verify_nonce($nonce, 'handle-test-data')) {
73 73
 			return;
74 74
 		}
75 75
 
76 76
 		$create_content = new Create;
77 77
 		$delete_content = new Delete;
78 78
 
79
-		if ( $action == 'delete' ){
79
+		if ($action == 'delete') {
80 80
 
81
-			$delete_content->delete_test_content( $cptslug, true );
81
+			$delete_content->delete_test_content($cptslug, true);
82 82
 
83
-		} elseif ( $action == 'create' ){
83
+		} elseif ($action == 'create') {
84 84
 
85
-			$create_content->create_post_type_content( $cptslug, true, 1 );
85
+			$create_content->create_post_type_content($cptslug, true, 1);
86 86
 
87 87
 		}
88 88
 
@@ -94,21 +94,21 @@  discard block
 block discarded – undo
94 94
 	/**
95 95
 	 * Print out our admin page to control test data.
96 96
 	 */
97
-	public function admin_page(){
97
+	public function admin_page() {
98 98
 
99 99
 		$html = "";
100 100
 
101 101
 		$html .= '<div class="wrap" id="options_editor">' . "\n";
102 102
 
103
-			$html .= '<h2>' . __( 'Create Test Data' , 'evans-mu' ) . '</h2>' . "\n";
103
+			$html .= '<h2>' . __('Create Test Data', 'evans-mu') . '</h2>' . "\n";
104 104
 
105 105
 			// Loop through all other cpts
106
-			$post_types = get_post_types( array( 'public' => true ), 'objects' );
106
+			$post_types = get_post_types(array('public' => true), 'objects');
107 107
 
108
-			foreach ( $post_types as $post_type ) {
108
+			foreach ($post_types as $post_type) {
109 109
 
110 110
 				// Skip Attachments
111
-				if ( $post_type->name == 'attachment' ){
111
+				if ($post_type->name == 'attachment') {
112 112
 					continue;
113 113
 				}
114 114
 
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 					$html .= "<h3>";
118 118
 
119 119
 						$html .= "<span style='width: 20%; display: inline-block;'>" . $post_type->labels->name . "</span>";
120
-						$html .= " <a href='javascript:void(0);' data-cpt='".$post_type->name."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus' style='margin-top: 6px; font-size: 1.2em'></span> Create Test Data</a>";
121
-						$html .= " <a href='javascript:void(0);' data-cpt='".$post_type->name."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash' style='margin-top: 4px; font-size: 1.2em'></span> Delete Test Data</a>";
120
+						$html .= " <a href='javascript:void(0);' data-cpt='" . $post_type->name . "' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus' style='margin-top: 6px; font-size: 1.2em'></span> Create Test Data</a>";
121
+						$html .= " <a href='javascript:void(0);' data-cpt='" . $post_type->name . "' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash' style='margin-top: 4px; font-size: 1.2em'></span> Delete Test Data</a>";
122 122
 
123 123
 					$html .= "</h3>";
124 124
 
Please login to merge, or discard this patch.
includes/class-delete.php 1 patch
Spacing   +16 added lines, -16 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 Delete{
11
+class Delete {
12 12
 
13 13
 	/**
14 14
 	 * Delete test data posts.
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param string $cptslug a custom post type ID.
25 25
 	 */
26
-	public function delete_test_content( $cptslug, $echo = false ){
26
+	public function delete_test_content($cptslug, $echo = false) {
27 27
 
28 28
 		// Check that $cptslg has a string.
29 29
 		// Also make sure that the current user is logged in & has full permissions.
30
-		if ( empty( $cptslug ) || !is_user_logged_in() || !current_user_can( 'delete_posts' ) ){
30
+		if (empty($cptslug) || !is_user_logged_in() || !current_user_can('delete_posts')) {
31 31
 			return;
32 32
 		}
33 33
 
@@ -44,22 +44,22 @@  discard block
 block discarded – undo
44 44
 			),
45 45
 		);
46 46
 
47
-		$objects = new \WP_Query( $query );
47
+		$objects = new \WP_Query($query);
48 48
 
49
-		if ( $objects->have_posts() ){
49
+		if ($objects->have_posts()) {
50 50
 
51
-			while ( $objects->have_posts() ) : $objects->the_post();
51
+			while ($objects->have_posts()) : $objects->the_post();
52 52
 
53 53
 				// Find any media associated with the test post and delete it as well
54
-				$this->delete_associated_media( get_the_id() );
54
+				$this->delete_associated_media(get_the_id());
55 55
 
56
-				if ( $echo === true ){
57
-					echo "Deleted ".get_post_type( get_the_id() )." " . get_the_id()."
56
+				if ($echo === true) {
57
+					echo "Deleted " . get_post_type(get_the_id()) . " " . get_the_id() . "
58 58
 ";
59 59
 				}
60 60
 
61 61
 				// Force delete the post
62
-				wp_delete_post( get_the_id(), true );
62
+				wp_delete_post(get_the_id(), true);
63 63
 
64 64
 			endwhile;
65 65
 
@@ -83,20 +83,20 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @param int $pid a custom post type ID.
85 85
 	 */
86
-	private function delete_associated_media( $pid ){
86
+	private function delete_associated_media($pid) {
87 87
 
88
-		if ( !is_int( $pid ) ){
88
+		if (!is_int($pid)) {
89 89
 			return;
90 90
 		}
91 91
 
92 92
 		// Get our images
93
-		$media = get_attached_media( 'image', $pid );
93
+		$media = get_attached_media('image', $pid);
94 94
 
95
-		if ( !empty( $media ) ){
95
+		if (!empty($media)) {
96 96
 
97 97
 			// Loop through the media & delete each one
98
-			foreach ( $media as $attachment ){
99
-				wp_delete_attachment( $attachment->ID, true );
98
+			foreach ($media as $attachment) {
99
+				wp_delete_attachment($attachment->ID, true);
100 100
 			}
101 101
 
102 102
 		}
Please login to merge, or discard this patch.
test-content.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,6 +21,6 @@
 block discarded – undo
21 21
  */
22 22
 foreach ( $dirs as $dir ){
23 23
 	foreach ( glob( plugin_dir_path( __FILE__ ) . "/$dir/*.php", GLOB_NOSORT ) as $filename ){
24
-	    require_once $filename;
24
+		require_once $filename;
25 25
 	}
26 26
 }
27 27
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@
 block discarded – undo
19 19
 /*
20 20
  * Loop through our directory array and require any PHP files without individual calls.
21 21
  */
22
-foreach ( $dirs as $dir ){
23
-	foreach ( glob( plugin_dir_path( __FILE__ ) . "/$dir/*.php", GLOB_NOSORT ) as $filename ){
22
+foreach ($dirs as $dir) {
23
+	foreach (glob(plugin_dir_path(__FILE__) . "/$dir/*.php", GLOB_NOSORT) as $filename) {
24 24
 	    require_once $filename;
25 25
 	}
26 26
 }
27 27
\ No newline at end of file
Please login to merge, or discard this patch.