PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | sal/class.json-api-post-base.php +85 -37 12.0.3 → 16.3-a.1 View file →
@@ -10,8 +10,12 @@
10 10 */
11 11
12 12 use Automattic\Jetpack\Status;
13 13
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit( 0 );
16 +}
17 +
14 18 require_once __DIR__ . '/class.json-api-metadata.php';
15 19 require_once __DIR__ . '/class.json-api-date.php';
16 20 require_once ABSPATH . 'wp-admin/includes/post.php';
17 21 require_once ABSPATH . 'wp-includes/post.php';
@@ -358,9 +362,9 @@
358 362 );
359 363 }
360 364
361 365 /**
362 - * Returns an array with details of the posts revisions, or false if 'edit' isn't the current post request context.
366 + * Returns an array with post revision ids, or false if 'edit' isn't the current post request context.
363 367 *
364 368 * @return bool|array
365 369 */
366 370 public function get_revisions() {
@@ -367,16 +371,18 @@
367 371 if ( 'edit' !== $this->context ) {
368 372 return false;
369 373 }
370 374
371 - $revisions = array();
372 - $post_revisions = wp_get_post_revisions( $this->post->ID );
375 + $args = array(
376 + 'posts_per_page' => -1,
377 + 'post_type' => 'revision',
378 + 'post_status' => 'any',
379 + 'fields' => 'ids', // Fetch only the IDs.
380 + 'post_parent' => $this->post->ID,
381 + );
373 382
374 - foreach ( $post_revisions as $_post ) {
375 - $revisions[] = $_post->ID;
376 - }
377 -
378 - return $revisions;
383 + $revision_query = new WP_Query( $args );
384 + return $revision_query->posts; // This returns an array of revision IDs.
379 385 }
380 386
381 387 /**
382 388 * Returns an object with extra post permalink suggestions.
@@ -420,24 +426,44 @@
420 426 public function get_publicize_urls() {
421 427 $publicize_urls = array();
422 428 $publicize = get_post_meta( $this->post->ID, 'publicize_results', true );
423 429 if ( $publicize ) {
424 - foreach ( $publicize as $service => $data ) {
425 - switch ( $service ) {
426 - case 'twitter':
427 - foreach ( $data as $datum ) {
428 - $publicize_urls[] = esc_url_raw( "https://twitter.com/{$datum['user_id']}/status/{$datum['post_id']}" );
429 - }
430 - break;
431 - case 'fb':
432 - foreach ( $data as $datum ) {
433 - $publicize_urls[] = esc_url_raw( "https://www.facebook.com/permalink.php?story_fbid={$datum['post_id']}&id={$datum['user_id']}" );
434 - }
435 - break;
430 + // get_post_meta(..., true) will return a string if the value was stored as a scalar or serialized, so we may need to unserialize.
431 + if ( is_string( $publicize ) ) {
432 + $maybe_array_publicize = maybe_unserialize( $publicize );
433 + if ( ! is_array( $maybe_array_publicize ) ) {
434 + $maybe_array_publicize = json_decode( $publicize, true );
436 435 }
436 + if ( is_array( $maybe_array_publicize ) ) {
437 + $publicize = $maybe_array_publicize;
438 + } else {
439 + return $publicize_urls;
440 + }
437 441 }
442 +
443 + if ( is_array( $publicize ) ) {
444 + foreach ( $publicize as $service => $data ) {
445 + switch ( $service ) {
446 + // @todo explore removing once Twitter is removed from Publicize.
447 + case 'twitter':
448 + foreach ( $data as $datum ) {
449 + if ( isset( $datum['user_id'] ) && isset( $datum['post_id'] ) ) {
450 + $publicize_urls[] = esc_url_raw( "https://twitter.com/{$datum['user_id']}/status/{$datum['post_id']}" );
451 + }
452 + }
453 + break;
454 + case 'fb':
455 + foreach ( $data as $datum ) {
456 + if ( isset( $datum['user_id'] ) && isset( $datum['post_id'] ) ) {
457 + $publicize_urls[] = esc_url_raw( "https://www.facebook.com/permalink.php?story_fbid={$datum['post_id']}&id={$datum['user_id']}" );
458 + }
459 + }
460 + break;
461 + }
462 + }
463 + }
438 464 }
439 - return (array) $publicize_urls;
465 + return $publicize_urls;
440 466 }
441 467
442 468 /**
443 469 * Returns a string with the page's custom template metadata.
@@ -554,9 +580,9 @@
554 580 public function get_title() {
555 581 if ( 'display' === $this->context ) {
556 582 return (string) get_the_title( $this->post->ID );
557 583 } else {
558 - return (string) htmlspecialchars_decode( $this->post->post_title, ENT_QUOTES );
584 + return htmlspecialchars_decode( $this->post->post_title, ENT_QUOTES );
559 585 }
560 586 }
561 587
562 588 /**
@@ -650,14 +676,23 @@
650 676 */
651 677 public function get_password() {
652 678 $password = (string) $this->post->post_password;
653 679 if ( 'edit' === $this->context ) {
654 - $password = htmlspecialchars_decode( (string) $password, ENT_QUOTES );
680 + $password = htmlspecialchars_decode( $password, ENT_QUOTES );
655 681 }
656 682 return $password;
657 683 }
658 684
659 685 /**
686 + * Returns true if the post has a password set, regardless of whether the current user can view or receive the password value.
687 + *
688 + * @return bool
689 + */
690 + public function get_has_password(): bool {
691 + return strlen( (string) $this->post->post_password ) > 0;
692 + }
693 +
694 + /**
660 695 * Returns an object representing a post's parent, and false if it doesn't have one.
661 696 *
662 697 * @return object|bool
663 698 */
@@ -663,12 +698,15 @@
663 698 */
664 699 public function get_parent() {
665 700 if ( $this->post->post_parent ) {
666 701 $parent = get_post( $this->post->post_parent );
702 + if ( ! $parent ) {
703 + return false;
704 + }
667 705 if ( 'display' === $this->context ) {
668 706 $parent_title = (string) get_the_title( $parent->ID );
669 707 } else {
670 - $parent_title = (string) htmlspecialchars_decode( $this->post->post_title, ENT_QUOTES );
708 + $parent_title = htmlspecialchars_decode( $this->post->post_title, ENT_QUOTES );
671 709 }
672 710 return (object) array(
673 711 'ID' => (int) $parent->ID,
674 712 'type' => (string) $parent->post_type,
@@ -749,9 +787,9 @@
749 787
750 788 $old_pages = $pages;
751 789 $old_page = $page;
752 790
753 - $content = join( "\n\n", $pages );
791 + $content = implode( "\n\n", $pages );
754 792 $content = preg_replace( '/<!--more(.*?)?-->/', '', $content );
755 793 // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited -- Assignment to globals is intentional
756 794 $pages = array( $content );
757 795 $page = 1;
@@ -787,12 +825,12 @@
787 825 // @todo: factor this out
788 826 // phpcs:disable WordPress.NamingConventions.ValidVariableName
789 827 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
790 828 $active_blog = get_active_blog_for_user( $user->ID );
791 - $site_id = $active_blog->blog_id;
792 - $profile_URL = "https://en.gravatar.com/{$user->user_login}";
829 + $site_id = $active_blog->blog_id ?? -1;
830 + $profile_URL = "https://gravatar.com/{$user->user_login}";
793 831 } else {
794 - $profile_URL = 'https://en.gravatar.com/' . md5( strtolower( trim( $user->user_email ) ) );
832 + $profile_URL = 'https://gravatar.com/' . md5( strtolower( trim( $user->user_email ) ) );
795 833 $site_id = -1;
796 834 }
797 835
798 836 $author = array(
@@ -821,12 +859,14 @@
821 859 *
822 860 * @param string $email The user's email.
823 861 * @param int $avatar_size The size of the avatar in pixels.
824 862 *
863 + * @todo Provide a non-WP.com option.
864 + *
825 865 * @return string
826 866 */
827 867 protected function get_avatar_url( $email, $avatar_size = 96 ) {
828 - $avatar_url = wpcom_get_avatar_url( $email, $avatar_size, '', true );
868 + $avatar_url = function_exists( 'wpcom_get_avatar_url' ) ? wpcom_get_avatar_url( $email, $avatar_size ) : '';
829 869 if ( ! $avatar_url || is_wp_error( $avatar_url ) ) {
830 870 return '';
831 871 }
832 872
@@ -913,9 +953,9 @@
913 953 }
914 954
915 955 $file = basename( wp_get_attachment_url( $media_item->ID ) );
916 956 $file_info = pathinfo( $file );
917 - $ext = $file_info['extension'];
957 + $ext = $file_info['extension'] ?? '';
918 958
919 959 $response = array(
920 960 'ID' => $media_item->ID,
921 961 'URL' => wp_get_attachment_url( $media_item->ID ),
@@ -934,9 +974,9 @@
934 974 );
935 975
936 976 if ( in_array( $ext, array( 'jpg', 'jpeg', 'png', 'gif', 'webp' ), true ) ) {
937 977 $metadata = wp_get_attachment_metadata( $media_item->ID );
938 - if ( isset( $metadata['height'], $metadata['width'] ) ) {
978 + if ( isset( $metadata['height'] ) && isset( $metadata['width'] ) ) {
939 979 $response['height'] = $metadata['height'];
940 980 $response['width'] = $metadata['width'];
941 981 }
942 982
@@ -953,9 +993,11 @@
953 993 */
954 994 $sizes = apply_filters( 'rest_api_thumbnail_sizes', $metadata['sizes'], $media_id );
955 995 if ( is_array( $sizes ) ) {
956 996 foreach ( $sizes as $size => $size_details ) {
957 - $response['thumbnails'][ $size ] = dirname( $response['URL'] ) . '/' . $size_details['file'];
997 + if ( isset( $size_details['file'] ) ) {
998 + $response['thumbnails'][ $size ] = dirname( $response['URL'] ) . '/' . $size_details['file'];
999 + }
958 1000 }
959 1001 }
960 1002 }
961 1003
@@ -974,9 +1016,9 @@
974 1016 }
975 1017
976 1018 if ( in_array( $ext, array( 'ogv', 'mp4', 'mov', 'wmv', 'avi', 'mpg', '3gp', '3g2', 'm4v' ), true ) ) {
977 1019 $metadata = wp_get_attachment_metadata( $media_item->ID );
978 - if ( isset( $metadata['height'], $metadata['width'] ) ) {
1020 + if ( isset( $metadata['height'] ) && isset( $metadata['width'] ) ) {
979 1021 $response['height'] = $metadata['height'];
980 1022 $response['width'] = $metadata['width'];
981 1023 }
982 1024
@@ -983,8 +1025,16 @@
983 1025 if ( isset( $metadata['length'] ) ) {
984 1026 $response['length'] = $metadata['length'];
985 1027 }
986 1028
1029 + if ( empty( $response['length'] ) && isset( $metadata['duration'] ) ) {
1030 + $response['length'] = (int) $metadata['duration'];
1031 + }
1032 +
1033 + if ( empty( $response['length'] ) && isset( $metadata['videopress']['duration'] ) ) {
1034 + $response['length'] = ceil( $metadata['videopress']['duration'] / 1000 );
1035 + }
1036 +
987 1037 // add VideoPress info.
988 1038 if ( function_exists( 'video_get_info_by_blogpostid' ) ) {
989 1039 $info = video_get_info_by_blogpostid( $this->site->get_id(), $media_id );
990 1040
@@ -1003,13 +1053,11 @@
1003 1053 }
1004 1054 }
1005 1055 }
1006 1056
1007 - $response['videopress_guid'] = $info->guid;
1057 + $response['videopress_guid'] = $info->guid ?? null;
1008 1058 $response['videopress_processing_done'] = true;
1009 - if ( '0000-00-00 00:00:00' === $info->finish_date_gmt ) {
1010 - $response['videopress_processing_done'] = false;
1011 - }
1059 + $response['videopress_processing_done'] = isset( $info->finish_date_gmt ) && '0000-00-00 00:00:00' !== $info->finish_date_gmt ? $info->finish_date_gmt : false;
1012 1060 }
1013 1061 }
1014 1062
1015 1063 $response['thumbnails'] = (object) $response['thumbnails'];