mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 21:00:21 +00:00
REST API: Check post meta update authorization only when value is changed.
Resolves a bug where a post save will be reported as failed if the post includes any meta keys the current user does not have authorization to update, even when those meta values are unchanged. Write authorization is now checked for a meta key only when the value of that key has changed, so that passing a REST response back unchanged will not cause failures. Authorization is only needed when data will be updated. Props ckoerner, TimothyBlynJacobs, spacedmonkey git-svn-id: https://develop.svn.wordpress.org/trunk@56075 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2299,6 +2299,42 @@ class WP_Test_REST_Post_Meta_Fields extends WP_Test_REST_TestCase {
|
||||
$this->assertSame( array( 'project' => 'WordCamp' ), $data['meta']['object'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 57745
|
||||
*/
|
||||
public function test_update_meta_with_unchanged_values_and_custom_authentication() {
|
||||
register_post_meta(
|
||||
'post',
|
||||
'authenticated',
|
||||
array(
|
||||
'single' => true,
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'show_in_rest' => true,
|
||||
'auth_callback' => '__return_false',
|
||||
)
|
||||
);
|
||||
|
||||
add_post_meta( self::$post_id, 'authenticated', false );
|
||||
|
||||
$this->grant_write_permission();
|
||||
|
||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
|
||||
$request->set_body_params(
|
||||
array(
|
||||
'meta' => array(
|
||||
'authenticated' => false,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( false, $data['meta']['authenticated'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 43392
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user