diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 9399889768e57..acc3379bbe3be 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -4129,7 +4129,10 @@ function wp_create_initial_comment_meta() { 'enum' => array( 'resolved', 'reopen' ), ), ), + 'auth_callback' => function ( $allowed, $meta_key, $object_id ) { + return current_user_can( 'edit_comment', $object_id ); + }, ) ); } -add_action( 'init', 'wp_create_initial_comment_meta' ); +add_action( 'rest_api_init', 'wp_create_initial_comment_meta' ); diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index e0868bbeca362..d1e1de901215c 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -3888,6 +3888,11 @@ public function test_create_empty_note_with_resolution_meta( $status ) { $response = rest_get_server()->dispatch( $request ); $this->assertSame( 201, $response->get_status() ); + + $data = $response->get_data(); + $this->assertArrayHasKey( 'meta', $data ); + $this->assertArrayHasKey( '_wp_note_status', $data['meta'] ); + $this->assertSame( $status, $data['meta']['_wp_note_status'] ); } /** diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index bf3d0d4703f37..d5390afbeff1d 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -22,6 +22,9 @@ public function set_up() { do_action( 'rest_api_init', $wp_rest_server ); add_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 ); + + // `get_post_embed_html()` assumes `wp-includes/js/wp-embed.js` is present: + self::touch( ABSPATH . WPINC . '/js/wp-embed.js' ); } public function tear_down() { diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index de83c1248e3db..ad92345619fe0 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -11654,7 +11654,18 @@ mockedApiResponse.Schema = { "meta": { "description": "Meta fields.", "type": "object", - "properties": [], + "properties": { + "_wp_note_status": { + "type": "string", + "title": "", + "description": "Note resolution status", + "default": "", + "enum": [ + "resolved", + "reopen" + ] + } + }, "required": false } } @@ -11801,7 +11812,18 @@ mockedApiResponse.Schema = { "meta": { "description": "Meta fields.", "type": "object", - "properties": [], + "properties": { + "_wp_note_status": { + "type": "string", + "title": "", + "description": "Note resolution status", + "default": "", + "enum": [ + "resolved", + "reopen" + ] + } + }, "required": false } } @@ -15480,6 +15502,7 @@ mockedApiResponse.CommentsCollection = [ "96": "https://secure.gravatar.com/avatar/9ca51ced0b389ffbeba3d269c6d824be664c84fa1b35503282abdd302e1f417c?s=96&d=mm&r=g" }, "meta": { + "_wp_note_status": null, "meta_key": "meta_value" }, "_links": { @@ -15534,6 +15557,7 @@ mockedApiResponse.CommentModel = { "96": "https://secure.gravatar.com/avatar/9ca51ced0b389ffbeba3d269c6d824be664c84fa1b35503282abdd302e1f417c?s=96&d=mm&r=g" }, "meta": { + "_wp_note_status": null, "meta_key": "meta_value" } }; diff --git a/tests/qunit/wp-includes/js/wp-api.js b/tests/qunit/wp-includes/js/wp-api.js index be0249462d398..14ad7ec89cac9 100644 --- a/tests/qunit/wp-includes/js/wp-api.js +++ b/tests/qunit/wp-includes/js/wp-api.js @@ -404,6 +404,9 @@ if ( 'Tags' === modelType ) { expectedMetas = '{"test_single":"","test_multi":[],"meta_key":"meta_value","test_tag_meta":""}'; } + if ( 'Comments' === modelType ) { + expectedMetas = '{"_wp_note_status":null,"meta_key":"meta_value"}'; + } // Verify the meta object returned correctly from `getMetas()`. assert.equal( JSON.stringify( endpoint.getMetas() ), expectedMetas, 'Full meta key/values object should be readable.' );