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 | json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php +34 -23 13.2.416.3-a.1 View file →
@@ -8,8 +8,12 @@
8 8 * Delete a post: /sites/%s/posts/%d/delete
9 9 * Restore a post: /sites/%s/posts/%d/restore
10 10 */
11 11
12 +if ( ! defined( 'ABSPATH' ) ) {
13 + exit( 0 );
14 +}
15 +
12 16 new WPCOM_JSON_API_Update_Post_v1_1_Endpoint(
13 17 array(
14 18 'description' => 'Create a post.',
15 19 'group' => 'posts',
@@ -204,8 +208,10 @@
204 208
205 209 // phpcs:disable PEAR.NamingConventions.ValidClassName.Invalid
206 210 /**
207 211 * Update post v1.1 endpoint class.
212 + *
213 + * @phan-constructor-used-for-side-effects
208 214 */
209 215 class WPCOM_JSON_API_Update_Post_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_Endpoint {
210 216 /**
211 217 * WPCOM_JSON_API_Update_Post_v1_1_Endpoint constructor.
@@ -268,9 +274,9 @@
268 274 $args = $this->query_args();
269 275
270 276 // unhook publicize, it's hooked again later -- without this, skipping services is impossible.
271 277 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
272 - remove_action( 'save_post', array( $GLOBALS['publicize_ui']->publicize, 'async_publicize_post' ), 100, 2 );
278 + remove_action( 'save_post', array( $GLOBALS['publicize_ui']->publicize, 'async_publicize_post' ), 100 );
273 279 add_action( 'rest_api_inserted_post', array( $GLOBALS['publicize_ui']->publicize, 'async_publicize_post' ) );
274 280
275 281 if ( $this->should_load_theme_functions( $post_id ) ) {
276 282 $this->load_theme_functions();
@@ -331,8 +337,13 @@
331 337 if ( ! is_array( $input ) || ! $input ) {
332 338 return new WP_Error( 'invalid_input', 'Invalid request input', 400 );
333 339 }
334 340
341 + $post = get_post( $post_id );
342 + if ( ! $post || is_wp_error( $post ) ) {
343 + return new WP_Error( 'unknown_post', 'Unknown post', 404 );
344 + }
345 +
335 346 if ( isset( $input['status'] ) && 'trash' === $input['status'] && ! current_user_can( 'delete_post', $post_id ) ) {
336 347 return new WP_Error( 'unauthorized', 'User cannot delete post', 403 );
337 348 }
338 349
@@ -340,14 +351,10 @@
340 351 if ( isset( $input['status'] ) && 'future' === $input['status'] ) {
341 352 $input['status'] = 'publish';
342 353 }
343 354
344 - $post = get_post( $post_id );
345 355 $_post_type = ( ! empty( $input['type'] ) ) ? $input['type'] : $post->post_type;
346 356 $post_type = get_post_type_object( $_post_type );
347 - if ( ! $post || is_wp_error( $post ) ) {
348 - return new WP_Error( 'unknown_post', 'Unknown post', 404 );
349 - }
350 357
351 358 if ( ! current_user_can( 'edit_post', $post->ID ) ) {
352 359 return new WP_Error( 'unauthorized', 'User cannot edit post', 403 );
353 360 }
@@ -363,9 +370,9 @@
363 370 if ( ( isset( $input['status'] ) && 'publish' === $input['status'] ) && 'publish' !== $post->post_status && ! current_user_can( 'publish_post', $post->ID ) ) {
364 371 $input['status'] = 'pending';
365 372 }
366 373 $last_status = $post->post_status;
367 - $new_status = isset( $input['status'] ) ? $input['status'] : $last_status;
374 + $new_status = $input['status'] ?? $last_status;
368 375
369 376 // Make sure that drafts get the current date when transitioning to publish if not supplied in the post.
370 377 // Similarly, scheduled posts that are manually published before their scheduled date should have the date reset.
371 378 $date_in_past = ( strtotime( $post->post_date_gmt ) < time() );
@@ -520,9 +527,10 @@
520 527 $is_open = WPCOM_JSON_API::is_truthy( $discussion[ $discussion_open ] );
521 528 $discussion[ $discussion_status ] = $is_open ? 'open' : 'closed';
522 529 }
523 530
524 - if ( in_array( $discussion[ $discussion_status ], array( 'open', 'closed' ), true ) ) {
531 + if ( isset( $discussion[ $discussion_status ] ) &&
532 + in_array( $discussion[ $discussion_status ], array( 'open', 'closed' ), true ) ) {
525 533 $insert[ $discussion_status ] = $discussion[ $discussion_status ];
526 534 }
527 535 }
528 536 }
@@ -533,12 +541,12 @@
533 541 $insert['menu_order'] = $input['menu_order'];
534 542 unset( $input['menu_order'] );
535 543 }
536 544
537 - $publicize = isset( $input['publicize'] ) ? $input['publicize'] : null;
545 + $publicize = $input['publicize'] ?? null;
538 546 unset( $input['publicize'] );
539 547
540 - $publicize_custom_message = isset( $input['publicize_message'] ) ? $input['publicize_message'] : null;
548 + $publicize_custom_message = $input['publicize_message'] ?? null;
541 549 unset( $input['publicize_message'] );
542 550
543 551 if ( isset( $input['featured_image'] ) ) {
544 552 $featured_image = trim( $input['featured_image'] );
@@ -545,18 +553,18 @@
545 553 $delete_featured_image = empty( $featured_image );
546 554 unset( $input['featured_image'] );
547 555 }
548 556
549 - $metadata = isset( $input['metadata'] ) ? $input['metadata'] : null;
557 + $metadata = $input['metadata'] ?? null;
550 558 unset( $input['metadata'] );
551 559
552 - $likes = isset( $input['likes_enabled'] ) ? $input['likes_enabled'] : null;
560 + $likes = $input['likes_enabled'] ?? null;
553 561 unset( $input['likes_enabled'] );
554 562
555 - $sharing = isset( $input['sharing_enabled'] ) ? $input['sharing_enabled'] : null;
563 + $sharing = $input['sharing_enabled'] ?? null;
556 564 unset( $input['sharing_enabled'] );
557 565
558 - $sticky = isset( $input['sticky'] ) ? $input['sticky'] : null;
566 + $sticky = $input['sticky'] ?? null;
559 567 unset( $input['sticky'] );
560 568
561 569 foreach ( $input as $key => $value ) {
562 570 $insert[ "post_$key" ] = $value;
@@ -694,9 +702,9 @@
694 702
695 703 // Set sharing status of the post.
696 704 if ( $new ) {
697 705 $sharing_enabled = isset( $sharing ) ? (bool) $sharing : true;
698 - if ( false === $sharing_enabled ) {
706 + if ( ! $sharing_enabled ) {
699 707 update_post_meta( $post_id, 'sharing_disabled', 1 );
700 708 }
701 709 } elseif ( isset( $sharing ) && true === $sharing ) {
702 710 delete_post_meta( $post_id, 'sharing_disabled' );
@@ -827,9 +835,9 @@
827 835
828 836 $meta = (object) $meta;
829 837
830 838 if (
831 - in_array( $meta->key, Jetpack_SEO_Posts::POST_META_KEYS_ARRAY, true ) &&
839 + in_array( $meta->key ?? null, Jetpack_SEO_Posts::POST_META_KEYS_ARRAY, true ) &&
832 840 ! Jetpack_SEO_Utils::is_enabled_jetpack_seo()
833 841 ) {
834 842 return new WP_Error( 'unauthorized', __( 'SEO tools are not enabled for this site.', 'jetpack' ), 403 );
835 843 }
@@ -857,12 +865,12 @@
857 865 continue;
858 866 }
859 867 }
860 868
861 - $unslashed_meta_key = wp_unslash( $meta->key ); // should match what the final key will be.
862 - $meta->key = wp_slash( $meta->key );
863 - $unslashed_existing_meta_key = wp_unslash( $existing_meta_item->meta_key );
864 - $existing_meta_item->meta_key = wp_slash( $existing_meta_item->meta_key );
869 + $unslashed_meta_key = isset( $meta->key ) ? wp_unslash( $meta->key ) : null; // should match what the final key will be.
870 + $meta->key = isset( $meta->key ) ? wp_slash( $meta->key ) : null;
871 + $unslashed_existing_meta_key = isset( $existing_meta_item->meta_key ) ? wp_unslash( $existing_meta_item->meta_key ) : null;
872 + $existing_meta_item->meta_key = isset( $existing_meta_item->meta_key ) ? wp_slash( $existing_meta_item->meta_key ) : null;
865 873
866 874 // make sure that the meta id passed matches the existing meta key.
867 875 if ( ! empty( $meta->id ) && ! empty( $meta->key ) ) {
868 876 $meta_by_id = get_metadata_by_mid( 'post', $meta->id );
@@ -926,11 +934,13 @@
926 934 if ( ! empty( $media_results['errors'] ) ) {
927 935 $return['media_errors'] = $media_results['errors'];
928 936 }
929 937
930 - if ( 'publish' !== $post->post_status ) {
938 + // Generate suggestions for new posts or non-published posts
939 + if ( $new || ( isset( $return['status'] ) && 'publish' !== $return['status'] ) ) {
931 940 $sal_site = $this->get_sal_post_by( 'ID', $post_id, $args['context'] );
932 - $return['other_URLs'] = (object) $sal_site->get_permalink_suggestions( $input['title'] );
941 + $title = $input['title'] ?? '';
942 + $return['other_URLs'] = (object) $sal_site->get_permalink_suggestions( $title );
933 943 }
934 944
935 945 /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
936 946 do_action( 'wpcom_json_api_objects', 'posts' );
@@ -1105,9 +1115,10 @@
1105 1115 protected function untrash_post( $post, $input ) {
1106 1116 wp_untrash_post( $post->ID );
1107 1117 $untrashed_post = get_post( $post->ID );
1108 1118 // Lets make sure that we use the reverted the slug.
1109 - if ( isset( $untrashed_post->post_name ) && $untrashed_post->post_name . '__trashed' === $input['slug'] ) {
1119 + if ( isset( $input['slug'] ) && isset( $untrashed_post->post_name ) &&
1120 + $untrashed_post->post_name . '__trashed' === $input['slug'] ) {
1110 1121 unset( $input['slug'] );
1111 1122 }
1112 1123 return $input;
1113 1124 }
@@ -1121,9 +1132,9 @@
1121 1132 */
1122 1133 protected function should_load_theme_functions( $post_id = null ) {
1123 1134 if ( empty( $post_id ) ) {
1124 1135 $input = $this->input( true );
1125 - $type = $input['type'];
1136 + $type = $input['type'] ?? null;
1126 1137 } else {
1127 1138 $type = get_post_type( $post_id );
1128 1139 }
1129 1140