@@ -417,29 +417,29 @@ discard block |
||
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 $image_id; |
|
442 | + return $image_id; |
|
443 | 443 | |
444 | 444 | } |
445 | 445 | |
@@ -462,9 +462,9 @@ discard block |
||
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 ); |
@@ -14,7 +14,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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,8 +350,8 @@ discard block |
||
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 | 357 | return $content; |
@@ -366,7 +366,7 @@ discard block |
||
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 |
||
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 $paragraphs[ rand( 0, 9 ) ]; |
|
384 | + return $paragraphs[rand(0, 9)]; |
|
385 | 385 | |
386 | 386 | } |
387 | 387 | |
@@ -397,46 +397,46 @@ discard block |
||
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 | 442 | return $image_id; |
@@ -451,31 +451,31 @@ discard block |
||
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,10 +490,10 @@ discard block |
||
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 | - return date( $format, strtotime( " +$num_days days" ) ); |
|
495 | + $num_days = rand(1, 60); |
|
496 | + return date($format, strtotime(" +$num_days days")); |
|
497 | 497 | |
498 | 498 | } |
499 | 499 | |
@@ -505,19 +505,19 @@ discard block |
||
505 | 505 | * |
506 | 506 | * @return string Time string |
507 | 507 | */ |
508 | - public static function time(){ |
|
508 | + public static function time() { |
|
509 | 509 | |
510 | 510 | $times = array( |
511 | 511 | '8:00 am', |
512 | 512 | '5:00PM', |
513 | 513 | '13:00', |
514 | 514 | '2015', |
515 | - date( 'G:i', strtotime( " +".rand( 4, 24 )." hours" ) ), |
|
516 | - date( 'g:i', strtotime( " +".rand( 4, 24 )." hours" ) ), |
|
517 | - date( 'G:i A', strtotime( " +".rand( 4, 24 )." hours" ) ) |
|
515 | + date('G:i', strtotime(" +".rand(4, 24)." hours")), |
|
516 | + date('g:i', strtotime(" +".rand(4, 24)." hours")), |
|
517 | + date('G:i A', strtotime(" +".rand(4, 24)." hours")) |
|
518 | 518 | ); |
519 | 519 | |
520 | - return $times[ rand( 0, 6 ) ]; |
|
520 | + return $times[rand(0, 6)]; |
|
521 | 521 | |
522 | 522 | } |
523 | 523 | |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | * |
530 | 530 | * @return string Timezone |
531 | 531 | */ |
532 | - public static function timezone(){ |
|
532 | + public static function timezone() { |
|
533 | 533 | |
534 | 534 | $timezones = array( |
535 | 535 | 'America/Denver', |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | 'UTC' |
548 | 548 | ); |
549 | 549 | |
550 | - return $timezones[ rand( 0, 12 ) ]; |
|
550 | + return $timezones[rand(0, 12)]; |
|
551 | 551 | |
552 | 552 | } |
553 | 553 | |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | * |
561 | 561 | * @return string Phone #. |
562 | 562 | */ |
563 | - public static function phone(){ |
|
563 | + public static function phone() { |
|
564 | 564 | |
565 | 565 | $phone_numbers = array( |
566 | 566 | '7203893101', |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | '+43 780 0047112' |
577 | 577 | ); |
578 | 578 | |
579 | - return $phone_numbers[ rand( 0, 10 ) ]; |
|
579 | + return $phone_numbers[rand(0, 10)]; |
|
580 | 580 | |
581 | 581 | } |
582 | 582 | |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | * |
589 | 589 | * @return string Email address. |
590 | 590 | */ |
591 | - public static function email(){ |
|
591 | + public static function email() { |
|
592 | 592 | |
593 | 593 | $email_addresses = array( |
594 | 594 | '[email protected]', |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | '[email protected]' |
602 | 602 | ); |
603 | 603 | |
604 | - return $email_addresses[ rand( 0, 7 ) ]; |
|
604 | + return $email_addresses[rand(0, 7)]; |
|
605 | 605 | |
606 | 606 | } |
607 | 607 | |
@@ -615,12 +615,12 @@ discard block |
||
615 | 615 | * |
616 | 616 | * @return string URL. |
617 | 617 | */ |
618 | - public static function link(){ |
|
618 | + public static function link() { |
|
619 | 619 | |
620 | 620 | $links = array( |
621 | 621 | 'http://google.com', |
622 | 622 | 'https://www.twitter.com', |
623 | - site_url( '/?iam=anextravariable' ), |
|
623 | + site_url('/?iam=anextravariable'), |
|
624 | 624 | 'github.com', |
625 | 625 | 'http://filebase.com', |
626 | 626 | 'www.oldtownmediainc.com', |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | 'https://www.eff.org' |
629 | 629 | ); |
630 | 630 | |
631 | - return $links[ rand( 0, 7 ) ]; |
|
631 | + return $links[rand(0, 7)]; |
|
632 | 632 | |
633 | 633 | } |
634 | 634 | |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | * |
640 | 640 | * @return string URL. |
641 | 641 | */ |
642 | - public static function oembed(){ |
|
642 | + public static function oembed() { |
|
643 | 643 | |
644 | 644 | $links = array( |
645 | 645 | 'https://www.youtube.com/watch?v=A85-YQsm6pY', |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | 'https://www.instagram.com/p/-eyLo0RMfX', |
651 | 651 | ); |
652 | 652 | |
653 | - return $links[ rand( 0, 5 ) ]; |
|
653 | + return $links[rand(0, 5)]; |
|
654 | 654 | |
655 | 655 | } |
656 | 656 | |
@@ -664,10 +664,10 @@ discard block |
||
664 | 664 | * @param string $type Video service to get link from |
665 | 665 | * @return string URL. |
666 | 666 | */ |
667 | - public static function video( $type ){ |
|
667 | + public static function video($type) { |
|
668 | 668 | |
669 | 669 | // Switch through our video types. Expecting to add more in the future |
670 | - switch( $type ){ |
|
670 | + switch ($type) { |
|
671 | 671 | |
672 | 672 | // YouTube videos |
673 | 673 | case 'youtube' : |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | |
709 | 709 | } |
710 | 710 | |
711 | - return $links[ rand( 0, 8 ) ]; |
|
711 | + return $links[rand(0, 8)]; |
|
712 | 712 | |
713 | 713 | } |
714 | 714 |
@@ -8,7 +8,7 @@ discard block |
||
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 |
||
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,7 +64,7 @@ discard block |
||
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 | 70 | $title = TestContent::title(); |
@@ -74,16 +74,16 @@ discard block |
||
74 | 74 | $slug, |
75 | 75 | array( |
76 | 76 | 'description'=> TestContent::title(), |
77 | - 'slug' => sanitize_title( $title ), |
|
77 | + 'slug' => sanitize_title($title), |
|
78 | 78 | ) |
79 | 79 | ); |
80 | 80 | |
81 | 81 | // Then, set a test content flag on the new post for later deletion |
82 | - add_term_meta( $return['term_id'], 'evans_test_content', '__test__', true ); |
|
82 | + add_term_meta($return['term_id'], 'evans_test_content', '__test__', true); |
|
83 | 83 | |
84 | 84 | // Check if we have errors and return them or created message |
85 | - if ( is_wp_error( $return ) ){ |
|
86 | - error_log( $return->get_error_message() ); |
|
85 | + if (is_wp_error($return)) { |
|
86 | + error_log($return->get_error_message()); |
|
87 | 87 | return $return; |
88 | 88 | } else { |
89 | 89 | return array( |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | 'object' => 'term', |
92 | 92 | 'tid' => $return['term_id'], |
93 | 93 | 'taxonomy' => $slug, |
94 | - 'link_edit' => admin_url( '/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id'] ), |
|
95 | - 'link_view' => get_term_link( $return['term_id'] ) |
|
94 | + 'link_edit' => admin_url('/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id']), |
|
95 | + 'link_view' => get_term_link($return['term_id']) |
|
96 | 96 | ); |
97 | 97 | } |
98 | 98 |
@@ -8,7 +8,7 @@ discard block |
||
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 |
||
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 | |
@@ -46,29 +46,29 @@ discard block |
||
46 | 46 | * @param boolean $echo Whether or not to echo. Optional. |
47 | 47 | * @param int $num Optional. Number of posts to create. |
48 | 48 | */ |
49 | - public function create_post_type_content( $slug, $echo = false, $num = '' ){ |
|
49 | + public function create_post_type_content($slug, $echo = false, $num = '') { |
|
50 | 50 | |
51 | 51 | // If we're missing a custom post type id - don't do anything |
52 | - if ( empty( $slug ) ){ |
|
52 | + if (empty($slug)) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | 56 | // Gather the necessary data to create the posts |
57 | - $supports = $this->get_cpt_supports( $slug ); |
|
58 | - $metaboxes = $this->metaboxes->get_metaboxes( $slug ); |
|
57 | + $supports = $this->get_cpt_supports($slug); |
|
58 | + $metaboxes = $this->metaboxes->get_metaboxes($slug); |
|
59 | 59 | |
60 | 60 | // If we forgot to put in a quantity, make one for us |
61 | - if ( empty( $num ) ){ |
|
62 | - $num = rand( 5, 30 ); |
|
61 | + if (empty($num)) { |
|
62 | + $num = rand(5, 30); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | // Create test posts |
66 | - for( $i = 0; $i < $num; $i++ ){ |
|
66 | + for ($i = 0; $i < $num; $i++) { |
|
67 | 67 | |
68 | - $return = $this->create_test_object( $slug, $supports, $metaboxes ); |
|
68 | + $return = $this->create_test_object($slug, $supports, $metaboxes); |
|
69 | 69 | |
70 | - if ( $echo === true ){ |
|
71 | - echo \json_encode( $return ); |
|
70 | + if ($echo === true) { |
|
71 | + echo \json_encode($return); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @param array $supports Features that the post type supports. |
92 | 92 | * @param array $supports All CMB2 metaboxes attached to the post type. |
93 | 93 | */ |
94 | - private function create_test_object( $slug, $supports, $metaboxes ){ |
|
94 | + private function create_test_object($slug, $supports, $metaboxes) { |
|
95 | 95 | $return = ''; |
96 | 96 | |
97 | 97 | // Get a random title |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | // First, insert our post |
101 | 101 | $post = array( |
102 | - 'post_name' => sanitize_title( $title ), |
|
102 | + 'post_name' => sanitize_title($title), |
|
103 | 103 | 'post_status' => 'publish', |
104 | 104 | 'post_type' => $slug, |
105 | 105 | 'ping_status' => 'closed', |
@@ -107,52 +107,52 @@ discard block |
||
107 | 107 | ); |
108 | 108 | |
109 | 109 | // Add title if supported |
110 | - if ( $supports['title'] === true ){ |
|
110 | + if ($supports['title'] === true) { |
|
111 | 111 | $post['post_title'] = $title; |
112 | 112 | } |
113 | 113 | |
114 | 114 | // Add main content if supported |
115 | - if ( $supports['editor'] === true ){ |
|
115 | + if ($supports['editor'] === true) { |
|
116 | 116 | $post['post_content'] = TestContent::paragraphs(); |
117 | 117 | } |
118 | 118 | |
119 | 119 | // Insert then post object |
120 | - $post_id = wp_insert_post( $post ); |
|
120 | + $post_id = wp_insert_post($post); |
|
121 | 121 | |
122 | 122 | // Then, set a test content flag on the new post for later deletion |
123 | - add_post_meta( $post_id, 'evans_test_content', '__test__', true ); |
|
123 | + add_post_meta($post_id, 'evans_test_content', '__test__', true); |
|
124 | 124 | |
125 | 125 | // Add thumbnail if supported |
126 | - if ( $supports['thumbnail'] === true || in_array( $slug, array( 'post', 'page' ) ) ){ |
|
127 | - update_post_meta( $post_id, '_thumbnail_id', TestContent::image( $post_id ) ); |
|
126 | + if ($supports['thumbnail'] === true || in_array($slug, array('post', 'page'))) { |
|
127 | + update_post_meta($post_id, '_thumbnail_id', TestContent::image($post_id)); |
|
128 | 128 | } |
129 | 129 | |
130 | - $taxonomies = get_object_taxonomies( $slug ); |
|
130 | + $taxonomies = get_object_taxonomies($slug); |
|
131 | 131 | |
132 | 132 | // Assign the post to terms |
133 | - if ( !empty( $taxonomies ) ){ |
|
134 | - $return .= $this->assign_terms( $post_id, $taxonomies ); |
|
133 | + if (!empty($taxonomies)) { |
|
134 | + $return .= $this->assign_terms($post_id, $taxonomies); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | // Spin up metaboxes |
138 | - if ( !empty( $metaboxes ) ){ |
|
139 | - foreach ( $metaboxes as $cmb ) : |
|
140 | - $return .= $this->metaboxes->random_metabox_content( $post_id, $cmb ); |
|
138 | + if (!empty($metaboxes)) { |
|
139 | + foreach ($metaboxes as $cmb) : |
|
140 | + $return .= $this->metaboxes->random_metabox_content($post_id, $cmb); |
|
141 | 141 | endforeach; |
142 | 142 | } |
143 | 143 | |
144 | 144 | // Check if we have errors and return them or created message |
145 | - if ( is_wp_error( $return ) ){ |
|
146 | - error_log( $return->get_error_message() ); |
|
145 | + if (is_wp_error($return)) { |
|
146 | + error_log($return->get_error_message()); |
|
147 | 147 | return $return; |
148 | 148 | } else { |
149 | 149 | return array( |
150 | 150 | 'type' => 'created', |
151 | 151 | 'object' => 'post', |
152 | 152 | 'pid' => $post_id, |
153 | - 'post_type' => get_post_type( $post_id ), |
|
154 | - 'link_edit' => admin_url( '/post.php?post='.$post_id.'&action=edit' ), |
|
155 | - 'link_view' => get_permalink( $post_id ), |
|
153 | + 'post_type' => get_post_type($post_id), |
|
154 | + 'link_edit' => admin_url('/post.php?post='.$post_id.'&action=edit'), |
|
155 | + 'link_view' => get_permalink($post_id), |
|
156 | 156 | ); |
157 | 157 | } |
158 | 158 | |
@@ -169,12 +169,12 @@ discard block |
||
169 | 169 | * @param string $slug a custom post type ID. |
170 | 170 | * @return array Array of necessary supports booleans. |
171 | 171 | */ |
172 | - private function get_cpt_supports( $slug ){ |
|
172 | + private function get_cpt_supports($slug) { |
|
173 | 173 | |
174 | 174 | $supports = array( |
175 | - 'title' => post_type_supports( $slug, 'title' ), |
|
176 | - 'editor' => post_type_supports( $slug, 'editor' ), |
|
177 | - 'thumbnail' => post_type_supports( $slug, 'thumbnail' ) |
|
175 | + 'title' => post_type_supports($slug, 'title'), |
|
176 | + 'editor' => post_type_supports($slug, 'editor'), |
|
177 | + 'thumbnail' => post_type_supports($slug, 'thumbnail') |
|
178 | 178 | ); |
179 | 179 | |
180 | 180 | return $supports; |
@@ -195,26 +195,26 @@ discard block |
||
195 | 195 | * @param array $taxonomies taxonomies assigned to this cpt. |
196 | 196 | * @return object WP Error if there is one. |
197 | 197 | */ |
198 | - private function assign_terms( $post_id, $taxonomies ){ |
|
198 | + private function assign_terms($post_id, $taxonomies) { |
|
199 | 199 | |
200 | 200 | // Make sure it's an array & has items |
201 | - if ( empty( $taxonomies ) || !is_array( $taxonomies ) ){ |
|
201 | + if (empty($taxonomies) || !is_array($taxonomies)) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | - foreach ( $taxonomies as $tax ){ |
|
205 | + foreach ($taxonomies as $tax) { |
|
206 | 206 | |
207 | 207 | // Get the individual terms already existing |
208 | - $terms = get_terms( $tax, array( 'hide_empty' => false ) ); |
|
209 | - $count = count( $terms ) - 1; |
|
208 | + $terms = get_terms($tax, array('hide_empty' => false)); |
|
209 | + $count = count($terms) - 1; |
|
210 | 210 | |
211 | 211 | // If there are no terms, skip to the next taxonomy |
212 | - if ( empty( $terms ) ){ |
|
212 | + if (empty($terms)) { |
|
213 | 213 | continue; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // Get a random index to use |
217 | - $index = rand( 0, $count ); |
|
217 | + $index = rand(0, $count); |
|
218 | 218 | |
219 | 219 | // Initialize our array |
220 | 220 | $post_data = array( |
@@ -222,14 +222,14 @@ discard block |
||
222 | 222 | ); |
223 | 223 | |
224 | 224 | // Set the term data to update |
225 | - $post_data['tax_input'][ $tax ] = array( $terms[$index]->term_id ); |
|
225 | + $post_data['tax_input'][$tax] = array($terms[$index]->term_id); |
|
226 | 226 | |
227 | 227 | // Update the post with the taxonomy info |
228 | - $return = wp_update_post( $post_data ); |
|
228 | + $return = wp_update_post($post_data); |
|
229 | 229 | |
230 | 230 | // Return the error if it exists |
231 | - if ( is_wp_error( $return ) ){ |
|
232 | - error_log( $return->get_error_messages() ); |
|
231 | + if (is_wp_error($return)) { |
|
232 | + error_log($return->get_error_messages()); |
|
233 | 233 | return $return->get_error_messages(); |
234 | 234 | } |
235 | 235 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage Evans |
9 | 9 | * @author Old Town Media |
10 | 10 | */ |
11 | -class Metaboxes{ |
|
11 | +class Metaboxes { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Decide which cmb library to try and loop to get our metaboxes. |
@@ -22,18 +22,18 @@ discard block |
||
22 | 22 | * @param string $slug Post Type slug ID. |
23 | 23 | * @return array Fields to fill in for our post object. |
24 | 24 | */ |
25 | - public function get_metaboxes( $slug ){ |
|
25 | + public function get_metaboxes($slug) { |
|
26 | 26 | |
27 | 27 | $fields = array(); |
28 | 28 | |
29 | 29 | // CMB2 |
30 | - if ( class_exists( 'CMB2', false ) ) { |
|
31 | - $fields = $this->get_cmb2_metaboxes( $slug ); |
|
30 | + if (class_exists('CMB2', false)) { |
|
31 | + $fields = $this->get_cmb2_metaboxes($slug); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | // Custom Metaboxes and Fields (CMB1) |
35 | - if ( class_exists( 'cmb_Meta_Box', false ) ) { |
|
36 | - $fields = $this->get_cmb1_metaboxes( $slug ); |
|
35 | + if (class_exists('cmb_Meta_Box', false)) { |
|
36 | + $fields = $this->get_cmb1_metaboxes($slug); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | // Return our array |
@@ -56,55 +56,55 @@ discard block |
||
56 | 56 | * @param string $slug a custom post type ID. |
57 | 57 | * @return array Array of fields. |
58 | 58 | */ |
59 | - private function get_cmb2_metaboxes( $slug ){ |
|
59 | + private function get_cmb2_metaboxes($slug) { |
|
60 | 60 | |
61 | 61 | $fields = array(); |
62 | 62 | |
63 | 63 | // Get all metaboxes from CMB2 library |
64 | - $all_metaboxes = apply_filters( 'cmb2_meta_boxes', array() ); |
|
64 | + $all_metaboxes = apply_filters('cmb2_meta_boxes', array()); |
|
65 | 65 | |
66 | 66 | // Loop through all possible sets of metaboxes added the old way |
67 | - foreach ( $all_metaboxes as $metabox_array ){ |
|
67 | + foreach ($all_metaboxes as $metabox_array) { |
|
68 | 68 | |
69 | 69 | // If the custom post type ID matches this set of fields, set & stop |
70 | - if ( in_array( $slug, $metabox_array['object_types'] ) ) { |
|
70 | + if (in_array($slug, $metabox_array['object_types'])) { |
|
71 | 71 | |
72 | 72 | // If this is the first group of fields, simply set the value |
73 | 73 | // Else, merge this group with the previous one |
74 | - if ( empty( $fields ) ){ |
|
74 | + if (empty($fields)) { |
|
75 | 75 | $fields = $metabox_array['fields']; |
76 | 76 | } else { |
77 | - $fields = array_merge( $fields, $metabox_array['fields'] ); |
|
77 | + $fields = array_merge($fields, $metabox_array['fields']); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | 81 | } |
82 | 82 | |
83 | 83 | // Loop through all metaboxes added the new way |
84 | - foreach ( \CMB2_Boxes::get_all() as $cmb ) { |
|
84 | + foreach (\CMB2_Boxes::get_all() as $cmb) { |
|
85 | 85 | |
86 | 86 | // Create the default |
87 | 87 | $match = false; |
88 | 88 | |
89 | 89 | // Establish correct cmb types |
90 | - if ( is_string( $cmb->meta_box['object_types'] ) ){ |
|
91 | - if ( $cmb->meta_box['object_types'] == $slug ){ |
|
90 | + if (is_string($cmb->meta_box['object_types'])) { |
|
91 | + if ($cmb->meta_box['object_types'] == $slug) { |
|
92 | 92 | $match = true; |
93 | 93 | } |
94 | 94 | } else { |
95 | - if ( in_array( $slug, $cmb->meta_box['object_types'] ) ){ |
|
95 | + if (in_array($slug, $cmb->meta_box['object_types'])) { |
|
96 | 96 | $match = true; |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | - if ( $match !== true ){ |
|
100 | + if ($match !== true) { |
|
101 | 101 | continue; |
102 | 102 | } |
103 | 103 | |
104 | - if ( empty( $fields ) ){ |
|
104 | + if (empty($fields)) { |
|
105 | 105 | $fields = $cmb->meta_box['fields']; |
106 | 106 | } else { |
107 | - $fields = array_merge( $fields, $cmb->meta_box['fields'] ); |
|
107 | + $fields = array_merge($fields, $cmb->meta_box['fields']); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | } |
@@ -128,25 +128,25 @@ discard block |
||
128 | 128 | * @param string $slug a custom post type ID. |
129 | 129 | * @return array Array of fields. |
130 | 130 | */ |
131 | - private function get_cmb1_metaboxes( $slug ){ |
|
131 | + private function get_cmb1_metaboxes($slug) { |
|
132 | 132 | |
133 | 133 | $fields = array(); |
134 | 134 | |
135 | 135 | // Get all metaboxes from CMB2 library |
136 | - $all_metaboxes = apply_filters( 'cmb_meta_boxes', array() ); |
|
136 | + $all_metaboxes = apply_filters('cmb_meta_boxes', array()); |
|
137 | 137 | |
138 | 138 | // Loop through all possible sets of metaboxes |
139 | - foreach ( $all_metaboxes as $metabox_array ){ |
|
139 | + foreach ($all_metaboxes as $metabox_array) { |
|
140 | 140 | |
141 | 141 | // If the custom post type ID matches this set of fields, set & stop |
142 | - if ( in_array( $slug, $metabox_array['pages'] ) ) { |
|
142 | + if (in_array($slug, $metabox_array['pages'])) { |
|
143 | 143 | |
144 | 144 | // If this is the first group of fields, simply set the value |
145 | 145 | // Else, merge this group with the previous one |
146 | - if ( empty( $fields ) ){ |
|
146 | + if (empty($fields)) { |
|
147 | 147 | $fields = $metabox_array['fields']; |
148 | 148 | } else { |
149 | - $fields = array_merge( $fields, $metabox_array['fields'] ); |
|
149 | + $fields = array_merge($fields, $metabox_array['fields']); |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
@@ -169,36 +169,36 @@ discard block |
||
169 | 169 | * @param int $post_id Single post ID. |
170 | 170 | * @param array $cmb custom metabox array from CMB2. |
171 | 171 | */ |
172 | - public function random_metabox_content( $post_id, $cmb ){ |
|
172 | + public function random_metabox_content($post_id, $cmb) { |
|
173 | 173 | $value = ''; |
174 | 174 | |
175 | 175 | // First check that our post ID & cmb array aren't empty |
176 | - if ( empty( $cmb ) || empty( $post_id ) ){ |
|
176 | + if (empty($cmb) || empty($post_id)) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Fetch the appropriate type of data and return |
181 | - switch( $cmb['type'] ){ |
|
181 | + switch ($cmb['type']) { |
|
182 | 182 | |
183 | 183 | case 'text': |
184 | 184 | case 'text_small': |
185 | 185 | case 'text_medium': |
186 | 186 | |
187 | 187 | // If phone is in the id, fetch a phone # |
188 | - if ( stripos( $cmb['id'], 'phone' ) ){ |
|
188 | + if (stripos($cmb['id'], 'phone')) { |
|
189 | 189 | $value = TestContent::phone(); |
190 | 190 | |
191 | 191 | // If email is in the id, fetch an email address |
192 | - } elseif ( stripos( $cmb['id'], 'email' ) ){ |
|
192 | + } elseif (stripos($cmb['id'], 'email')) { |
|
193 | 193 | $value = TestContent::email(); |
194 | 194 | |
195 | 195 | // If time is in the id, fetch a time string |
196 | - } elseif ( stripos( $cmb['id'], 'time' ) ){ |
|
196 | + } elseif (stripos($cmb['id'], 'time')) { |
|
197 | 197 | $value = TestContent::time(); |
198 | 198 | |
199 | 199 | // Otherwise, just a random text string |
200 | 200 | } else { |
201 | - $value = TestContent::title( rand( 10, 50 ) ); |
|
201 | + $value = TestContent::title(rand(10, 50)); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | break; |
@@ -229,14 +229,14 @@ discard block |
||
229 | 229 | |
230 | 230 | case 'text_date': |
231 | 231 | |
232 | - $value = TestContent::date( 'm/d/Y' ); |
|
232 | + $value = TestContent::date('m/d/Y'); |
|
233 | 233 | |
234 | 234 | break; |
235 | 235 | |
236 | 236 | case 'text_date_timestamp': |
237 | 237 | case 'text_datetime_timestamp': |
238 | 238 | |
239 | - $value = TestContent::date( 'U' ); |
|
239 | + $value = TestContent::date('U'); |
|
240 | 240 | |
241 | 241 | break; |
242 | 242 | |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | |
245 | 245 | case 'text_money': |
246 | 246 | |
247 | - $value = rand( 0, 100000 ); |
|
247 | + $value = rand(0, 100000); |
|
248 | 248 | |
249 | 249 | break; |
250 | 250 | |
251 | 251 | case 'test_colorpicker': |
252 | 252 | |
253 | - $value = '#' . str_pad( dechex( mt_rand( 0, 0xFFFFFF ) ), 6, '0', STR_PAD_LEFT ); |
|
253 | + $value = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
254 | 254 | |
255 | 255 | break; |
256 | 256 | |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | case 'radio': |
268 | 268 | |
269 | 269 | // Grab a random item out of the array and return the key |
270 | - $new_val = array_slice( $cmb['options'], rand( 0, count( $cmb['options'] ) ), 1 ); |
|
271 | - $value = key( $new_val ); |
|
270 | + $new_val = array_slice($cmb['options'], rand(0, count($cmb['options'])), 1); |
|
271 | + $value = key($new_val); |
|
272 | 272 | |
273 | 273 | break; |
274 | 274 | |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | case 'checkbox': |
280 | 280 | |
281 | 281 | // 50/50 odds of being turned on |
282 | - if ( rand( 0, 1 ) == 1 ){ |
|
282 | + if (rand(0, 1) == 1) { |
|
283 | 283 | $value = 'on'; |
284 | 284 | } |
285 | 285 | |
@@ -290,10 +290,10 @@ discard block |
||
290 | 290 | $new_option = array(); |
291 | 291 | |
292 | 292 | // Loop through each of our options |
293 | - foreach ( $cmb['options'] as $key => $value ){ |
|
293 | + foreach ($cmb['options'] as $key => $value) { |
|
294 | 294 | |
295 | 295 | // 50/50 chance of being included |
296 | - if ( rand( 0, 1 ) ){ |
|
296 | + if (rand(0, 1)) { |
|
297 | 297 | $new_option[] = $key; |
298 | 298 | } |
299 | 299 | |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | |
312 | 312 | case 'file': |
313 | 313 | |
314 | - $value = TestContent::image( $post_id ); |
|
314 | + $value = TestContent::image($post_id); |
|
315 | 315 | |
316 | 316 | break; |
317 | 317 | |
@@ -326,20 +326,20 @@ discard block |
||
326 | 326 | } |
327 | 327 | |
328 | 328 | // Value must exist to attempt to insert |
329 | - if ( !empty( $value ) && !is_wp_error( $value ) ){ |
|
329 | + if (!empty($value) && !is_wp_error($value)) { |
|
330 | 330 | |
331 | 331 | // Files must be treated separately - they use the attachment ID |
332 | 332 | // & url of media for separate cmb values |
333 | - if ( $cmb['type'] != 'file' ){ |
|
334 | - add_post_meta( $post_id, $cmb['id'], $value, true ); |
|
333 | + if ($cmb['type'] != 'file') { |
|
334 | + add_post_meta($post_id, $cmb['id'], $value, true); |
|
335 | 335 | } else { |
336 | - add_post_meta( $post_id, $cmb['id'].'_id', $value, true ); |
|
337 | - add_post_meta( $post_id, $cmb['id'], wp_get_attachment_url( $value ), true ); |
|
336 | + add_post_meta($post_id, $cmb['id'].'_id', $value, true); |
|
337 | + add_post_meta($post_id, $cmb['id'], wp_get_attachment_url($value), true); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | // If we're dealing with a WP Error object, just return the message for debugging |
341 | - } elseif ( is_wp_error( $value ) ){ |
|
342 | - error_log( $value->get_error_message() ); |
|
341 | + } elseif (is_wp_error($value)) { |
|
342 | + error_log($value->get_error_message()); |
|
343 | 343 | return $value->get_error_message(); |
344 | 344 | } |
345 | 345 |