From 89d76b98844ef594acbda1ccf73d55b42b9b5afa Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Fri, 14 Dec 2018 05:12:12 +0000 Subject: [PATCH] PHP7.3 compatibility: Fix compact throwing notices. In PHP 7.3, the `compact()` function has been changed to issue an `E_NOTICE` level error if a passed string refers to an unset variable. In previous versions of PHP, this notice was silently skipped. The full RFC can be viewed here: https://wiki.php.net/rfc/compact. Props jorbin, desrosj. Merges [43819] and [43832] to trunk. Fixes #44416. git-svn-id: https://develop.svn.wordpress.org/trunk@44166 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-comment-query.php | 4 +- src/wp-includes/class-wp-network-query.php | 3 ++ src/wp-includes/class-wp-site-query.php | 3 ++ src/wp-includes/class-wp-xmlrpc-server.php | 47 +++++++++------- src/wp-includes/comment.php | 2 +- src/wp-includes/post.php | 9 +++- tests/phpunit/tests/dependencies/scripts.php | 1 + tests/qunit/fixtures/wp-api-generated.js | 56 ++++++++++---------- 8 files changed, 75 insertions(+), 50 deletions(-) diff --git a/src/wp-includes/class-wp-comment-query.php b/src/wp-includes/class-wp-comment-query.php index d0e7cff14f..aa3be72af2 100644 --- a/src/wp-includes/class-wp-comment-query.php +++ b/src/wp-includes/class-wp-comment-query.php @@ -635,6 +635,7 @@ class WP_Comment_Query { $number = absint( $this->query_vars['number'] ); $offset = absint( $this->query_vars['offset'] ); $paged = absint( $this->query_vars['paged'] ); + $limits = ''; if ( ! empty( $number ) ) { if ( $offset ) { @@ -819,7 +820,8 @@ class WP_Comment_Query { $this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__not_in'] ) ) . ' )'; } - $join = ''; + $join = ''; + $groupby = ''; if ( $join_posts_table ) { $join .= "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID"; diff --git a/src/wp-includes/class-wp-network-query.php b/src/wp-includes/class-wp-network-query.php index 982009b3c3..d381e60117 100644 --- a/src/wp-includes/class-wp-network-query.php +++ b/src/wp-includes/class-wp-network-query.php @@ -327,6 +327,7 @@ class WP_Network_Query { $number = absint( $this->query_vars['number'] ); $offset = absint( $this->query_vars['offset'] ); + $limits = ''; if ( ! empty( $number ) ) { if ( $offset ) { @@ -392,6 +393,8 @@ class WP_Network_Query { $where = implode( ' AND ', $this->sql_clauses['where'] ); + $groupby = ''; + $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' ); /** diff --git a/src/wp-includes/class-wp-site-query.php b/src/wp-includes/class-wp-site-query.php index 0e76b7705b..d963c5edb4 100644 --- a/src/wp-includes/class-wp-site-query.php +++ b/src/wp-includes/class-wp-site-query.php @@ -420,6 +420,7 @@ class WP_Site_Query { $number = absint( $this->query_vars['number'] ); $offset = absint( $this->query_vars['offset'] ); + $limits = ''; if ( ! empty( $number ) ) { if ( $offset ) { @@ -584,6 +585,8 @@ class WP_Site_Query { $where = implode( ' AND ', $this->sql_clauses['where'] ); + $groupby = ''; + $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' ); /** diff --git a/src/wp-includes/class-wp-xmlrpc-server.php b/src/wp-includes/class-wp-xmlrpc-server.php index 5c8ee133c6..a2bf6e4a9a 100644 --- a/src/wp-includes/class-wp-xmlrpc-server.php +++ b/src/wp-includes/class-wp-xmlrpc-server.php @@ -3699,6 +3699,9 @@ class wp_xmlrpc_server extends IXR_Server { /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'wp.editComment' ); + $comment = array( + 'comment_ID' => $comment_ID, + ); if ( isset( $content_struct['status'] ) ) { $statuses = get_comment_statuses(); @@ -3707,36 +3710,34 @@ class wp_xmlrpc_server extends IXR_Server { if ( ! in_array( $content_struct['status'], $statuses ) ) { return new IXR_Error( 401, __( 'Invalid comment status.' ) ); } - $comment_approved = $content_struct['status']; + + $comment['comment_approved'] = $content_struct['status']; } // Do some timestamp voodoo if ( ! empty( $content_struct['date_created_gmt'] ) ) { // We know this is supposed to be GMT, so we're going to slap that Z on there by force - $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; - $comment_date = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); - $comment_date_gmt = iso8601_to_datetime( $dateCreated, 'GMT' ); + $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; + $comment['comment_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); + $comment['comment_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' ); } if ( isset( $content_struct['content'] ) ) { - $comment_content = $content_struct['content']; + $comment['comment_content'] = $content_struct['content']; } if ( isset( $content_struct['author'] ) ) { - $comment_author = $content_struct['author']; + $comment['comment_author'] = $content_struct['author']; } if ( isset( $content_struct['author_url'] ) ) { - $comment_author_url = $content_struct['author_url']; + $comment['comment_author_url'] = $content_struct['author_url']; } if ( isset( $content_struct['author_email'] ) ) { - $comment_author_email = $content_struct['author_email']; + $comment['comment_author_email'] = $content_struct['author_email']; } - // We've got all the data -- post it: - $comment = compact( 'comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url' ); - $result = wp_update_comment( $comment ); if ( is_wp_error( $result ) ) { return new IXR_Error( 500, $result->get_error_message() ); @@ -5261,16 +5262,22 @@ class wp_xmlrpc_server extends IXR_Server { // Only use a password if one was given. if ( isset( $content_struct['wp_password'] ) ) { $post_password = $content_struct['wp_password']; + } else { + $post_password = ''; } // Only set a post parent if one was provided. if ( isset( $content_struct['wp_page_parent_id'] ) ) { $post_parent = $content_struct['wp_page_parent_id']; + } else { + $post_parent = 0; } // Only set the menu_order if it was provided. if ( isset( $content_struct['wp_page_order'] ) ) { $menu_order = $content_struct['wp_page_order']; + } else { + $menu_order = 0; } $post_author = $user->ID; @@ -5599,14 +5606,16 @@ class wp_xmlrpc_server extends IXR_Server { $this->escape( $postdata ); - $ID = $postdata['ID']; - $post_content = $postdata['post_content']; - $post_title = $postdata['post_title']; - $post_excerpt = $postdata['post_excerpt']; - $post_password = $postdata['post_password']; - $post_parent = $postdata['post_parent']; - $post_type = $postdata['post_type']; - $menu_order = $postdata['menu_order']; + $ID = $postdata['ID']; + $post_content = $postdata['post_content']; + $post_title = $postdata['post_title']; + $post_excerpt = $postdata['post_excerpt']; + $post_password = $postdata['post_password']; + $post_parent = $postdata['post_parent']; + $post_type = $postdata['post_type']; + $menu_order = $postdata['menu_order']; + $ping_status = $postdata['ping_status']; + $comment_status = $postdata['comment_status']; // Let WordPress manage slug if none was provided. $post_name = $postdata['post_name']; diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 6bba04dd28..06200213a4 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -3082,7 +3082,7 @@ function _close_comments_for_old_post( $open, $post_id ) { */ function wp_handle_comment_submission( $comment_data ) { - $comment_post_ID = $comment_parent = 0; + $comment_post_ID = $comment_parent = $user_ID = 0; $comment_author = $comment_author_email = $comment_author_url = $comment_content = null; if ( isset( $comment_data['comment_post_ID'] ) ) { diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 5cda6bd5b6..2e648f08d4 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -3602,6 +3602,13 @@ function wp_insert_post( $postarr, $wp_error = false ) { $post_parent = 0; } + $new_postarr = array_merge( + array( + 'ID' => $post_ID, + ), + compact( array_diff( array_keys( $defaults ), array( 'context', 'filter' ) ) ) + ); + /** * Filters the post parent -- used to check for and prevent hierarchy loops. * @@ -3612,7 +3619,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { * @param array $new_postarr Array of parsed post data. * @param array $postarr Array of sanitized, but otherwise unmodified post data. */ - $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr ); + $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, $new_postarr, $postarr ); /* * If the post is being untrashed and it has a desired slug stored in post meta, diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 8e30f93fb7..198d970697 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -867,6 +867,7 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase { * @covers ::wp_enqueue_code_editor() */ public function test_wp_enqueue_code_editor_when_generated_array_by_compact_will_be_passed() { + $file = ''; $wp_enqueue_code_editor = wp_enqueue_code_editor( compact( 'file' ) ); $this->assertNonEmptyMultidimensionalArray( $wp_enqueue_code_editor ); diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index b5acdc4355..44e518bf28 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -5086,13 +5086,13 @@ mockedApiResponse.postRevisions = [ "author": 376, "date": "2017-02-14T00:00:00", "date_gmt": "2017-02-14T00:00:00", - "id": 3162, + "id": 36744, "modified": "2017-02-14T00:00:00", "modified_gmt": "2017-02-14T00:00:00", - "parent": 3161, - "slug": "3161-revision-v1", + "parent": 36743, + "slug": "36743-revision-v1", "guid": { - "rendered": "http://example.org/?p=3162" + "rendered": "http://example.org/?p=36744" }, "title": { "rendered": "REST API Client Fixture: Post" @@ -5106,7 +5106,7 @@ mockedApiResponse.postRevisions = [ "_links": { "parent": [ { - "href": "http://example.org/index.php?rest_route=/wp/v2/posts/3161" + "href": "http://example.org/index.php?rest_route=/wp/v2/posts/36743" } ] } @@ -5141,13 +5141,13 @@ mockedApiResponse.postAutosaves = [ "author": 376, "date": "2017-02-14T00:00:00", "date_gmt": "2017-02-14T00:00:00", - "id": 3163, + "id": 36745, "modified": "2017-02-14T00:00:00", "modified_gmt": "2017-02-14T00:00:00", - "parent": 3161, - "slug": "3161-autosave-v1", + "parent": 36743, + "slug": "36743-autosave-v1", "guid": { - "rendered": "http://example.org/?p=3163" + "rendered": "http://example.org/?p=36745" }, "title": { "rendered": "" @@ -5161,7 +5161,7 @@ mockedApiResponse.postAutosaves = [ "_links": { "parent": [ { - "href": "http://example.org/index.php?rest_route=/wp/v2/posts/3161" + "href": "http://example.org/index.php?rest_route=/wp/v2/posts/36743" } ] } @@ -5172,13 +5172,13 @@ mockedApiResponse.autosave = { "author": 376, "date": "2017-02-14T00:00:00", "date_gmt": "2017-02-14T00:00:00", - "id": 3163, + "id": 36745, "modified": "2017-02-14T00:00:00", "modified_gmt": "2017-02-14T00:00:00", - "parent": 3161, - "slug": "3161-autosave-v1", + "parent": 36743, + "slug": "36743-autosave-v1", "guid": { - "rendered": "http://example.org/?p=3163" + "rendered": "http://example.org/?p=36745" }, "title": { "rendered": "" @@ -5346,13 +5346,13 @@ mockedApiResponse.pageRevisions = [ "author": 376, "date": "2017-02-14T00:00:00", "date_gmt": "2017-02-14T00:00:00", - "id": 3165, + "id": 36747, "modified": "2017-02-14T00:00:00", "modified_gmt": "2017-02-14T00:00:00", - "parent": 3164, - "slug": "3164-revision-v1", + "parent": 36746, + "slug": "36746-revision-v1", "guid": { - "rendered": "http://example.org/?p=3165" + "rendered": "http://example.org/?p=36747" }, "title": { "rendered": "REST API Client Fixture: Page" @@ -5366,7 +5366,7 @@ mockedApiResponse.pageRevisions = [ "_links": { "parent": [ { - "href": "http://example.org/index.php?rest_route=/wp/v2/pages/3164" + "href": "http://example.org/index.php?rest_route=/wp/v2/pages/36746" } ] } @@ -5401,13 +5401,13 @@ mockedApiResponse.pageAutosaves = [ "author": 376, "date": "2017-02-14T00:00:00", "date_gmt": "2017-02-14T00:00:00", - "id": 3166, + "id": 36748, "modified": "2017-02-14T00:00:00", "modified_gmt": "2017-02-14T00:00:00", - "parent": 3164, - "slug": "3164-autosave-v1", + "parent": 36746, + "slug": "36746-autosave-v1", "guid": { - "rendered": "http://example.org/?p=3166" + "rendered": "http://example.org/?p=36748" }, "title": { "rendered": "" @@ -5421,7 +5421,7 @@ mockedApiResponse.pageAutosaves = [ "_links": { "parent": [ { - "href": "http://example.org/index.php?rest_route=/wp/v2/pages/3164" + "href": "http://example.org/index.php?rest_route=/wp/v2/pages/36746" } ] } @@ -5432,13 +5432,13 @@ mockedApiResponse.pageAutosave = { "author": 376, "date": "2017-02-14T00:00:00", "date_gmt": "2017-02-14T00:00:00", - "id": 3166, + "id": 36748, "modified": "2017-02-14T00:00:00", "modified_gmt": "2017-02-14T00:00:00", - "parent": 3164, - "slug": "3164-autosave-v1", + "parent": 36746, + "slug": "36746-autosave-v1", "guid": { - "rendered": "http://example.org/?p=3166" + "rendered": "http://example.org/?p=36748" }, "title": { "rendered": ""