Skip to content

Commit 80156af

Browse files
committed
Editor: Add auth_callback to _wp_note_status comment meta.
Adds an `auth_callback` to the `_wp_note_status` comment meta so that only users with the `edit_comment` capability can update this meta field via the REST API. This is necessary to ensure that users can properly resolve or reopen Notes. Props wildworks, adamsilverstein, westonruter, mamaduka, desrosj. Fixes #64153. git-svn-id: https://develop.svn.wordpress.org/trunk@61089 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b482707 commit 80156af

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/wp-includes/comment.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4129,7 +4129,9 @@ function wp_create_initial_comment_meta() {
41294129
'enum' => array( 'resolved', 'reopen' ),
41304130
),
41314131
),
4132+
'auth_callback' => function ( $allowed, $meta_key, $object_id ) {
4133+
return current_user_can( 'edit_comment', $object_id );
4134+
},
41324135
)
41334136
);
41344137
}
4135-
add_action( 'init', 'wp_create_initial_comment_meta' );

src/wp-includes/default-filters.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
add_action( 'added_comment_meta', 'wp_cache_set_comments_last_changed' );
152152
add_action( 'updated_comment_meta', 'wp_cache_set_comments_last_changed' );
153153
add_action( 'deleted_comment_meta', 'wp_cache_set_comments_last_changed' );
154+
add_action( 'init', 'wp_create_initial_comment_meta' );
154155

155156
// Places to balance tags on input.
156157
foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {

tests/phpunit/tests/rest-api/rest-comments-controller.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ public static function wpTearDownAfterClass() {
170170
public function set_up() {
171171
parent::set_up();
172172
$this->endpoint = new WP_REST_Comments_Controller();
173+
wp_create_initial_comment_meta();
174+
173175
if ( is_multisite() ) {
174176
update_site_option( 'site_admins', array( 'superadmin' ) );
175177
}
@@ -3888,6 +3890,11 @@ public function test_create_empty_note_with_resolution_meta( $status ) {
38883890

38893891
$response = rest_get_server()->dispatch( $request );
38903892
$this->assertSame( 201, $response->get_status() );
3893+
3894+
$data = $response->get_data();
3895+
$this->assertArrayHasKey( 'meta', $data );
3896+
$this->assertArrayHasKey( '_wp_note_status', $data['meta'] );
3897+
$this->assertSame( $status, $data['meta']['_wp_note_status'] );
38913898
}
38923899

38933900
/**

0 commit comments

Comments
 (0)