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
This commit is contained in:
Jonathan Desrosiers
2018-12-14 05:12:12 +00:00
parent 3011f8c8e7
commit 89d76b9884
8 changed files with 75 additions and 50 deletions

View File

@@ -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'];