diff --git a/src/wp-includes/class-wp-xmlrpc-server.php b/src/wp-includes/class-wp-xmlrpc-server.php index 513bd1cdbf..10fe6605cc 100644 --- a/src/wp-includes/class-wp-xmlrpc-server.php +++ b/src/wp-includes/class-wp-xmlrpc-server.php @@ -1412,19 +1412,19 @@ class wp_xmlrpc_server extends IXR_Server { $defaults = array( 'post_status' => 'draft', 'post_type' => 'post', - 'post_author' => null, - 'post_password' => null, - 'post_excerpt' => null, - 'post_content' => null, - 'post_title' => null, - 'post_date' => null, - 'post_date_gmt' => null, + 'post_author' => 0, + 'post_password' => '', + 'post_excerpt' => '', + 'post_content' => '', + 'post_title' => '', + 'post_date' => '', + 'post_date_gmt' => '', 'post_format' => null, 'post_name' => null, 'post_thumbnail' => null, - 'post_parent' => null, - 'ping_status' => null, - 'comment_status' => null, + 'post_parent' => 0, + 'ping_status' => '', + 'comment_status' => '', 'custom_fields' => null, 'terms_names' => null, 'terms' => null, @@ -1499,11 +1499,11 @@ class wp_xmlrpc_server extends IXR_Server { $post_data['post_author'] = $user->ID; } - if ( isset( $post_data['comment_status'] ) && 'open' !== $post_data['comment_status'] && 'closed' !== $post_data['comment_status'] ) { + if ( 'open' !== $post_data['comment_status'] && 'closed' !== $post_data['comment_status'] ) { unset( $post_data['comment_status'] ); } - if ( isset( $post_data['ping_status'] ) && 'open' !== $post_data['ping_status'] && 'closed' !== $post_data['ping_status'] ) { + if ( 'open' !== $post_data['ping_status'] && 'closed' !== $post_data['ping_status'] ) { unset( $post_data['ping_status'] ); } @@ -1681,6 +1681,14 @@ class wp_xmlrpc_server extends IXR_Server { */ $post_data = apply_filters( 'xmlrpc_wp_insert_post_data', $post_data, $content_struct ); + // Remove all null values to allow for using the insert/update post default values for those keys instead. + $post_data = array_filter( + $post_data, + static function ( $value ) { + return null !== $value; + } + ); + $post_ID = $update ? wp_update_post( $post_data, true ) : wp_insert_post( $post_data, true ); if ( is_wp_error( $post_ID ) ) { return new IXR_Error( 500, $post_ID->get_error_message() ); diff --git a/tests/phpunit/tests/date/xmlrpc.php b/tests/phpunit/tests/date/xmlrpc.php index 3258909cfb..63daeb41da 100644 --- a/tests/phpunit/tests/date/xmlrpc.php +++ b/tests/phpunit/tests/date/xmlrpc.php @@ -24,16 +24,6 @@ class Tests_Date_XMLRPC extends WP_XMLRPC_UnitTestCase { * @covers wp_xmlrpc_server::mw_newPost */ public function test_date_new_post() { - if ( PHP_VERSION_ID >= 80100 ) { - /* - * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in - * via hooked in filter functions until a more structural solution to the - * "missing input validation" conundrum has been architected and implemented. - */ - $this->expectDeprecation(); - $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' ); - } - $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone );