diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index df8ac1a..d249ab8 100644
a
|
b
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
973 | 973 | } |
974 | 974 | |
975 | 975 | // Post password. |
976 | | if ( ! empty( $schema['properties']['password'] ) && isset( $request['password'] ) && '' !== $request['password'] ) { |
| 976 | if ( ! empty( $schema['properties']['password'] ) && isset( $request['password'] ) ) { |
977 | 977 | $prepared_post->post_password = $request['password']; |
978 | 978 | |
979 | | if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) { |
980 | | return new WP_Error( 'rest_invalid_field', __( 'A post can not be sticky and have a password.' ), array( 'status' => 400 ) ); |
981 | | } |
| 979 | if ( '' !== $request['password'] ) { |
| 980 | if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) { |
| 981 | return new WP_Error( 'rest_invalid_field', __( 'A post can not be sticky and have a password.' ), array( 'status' => 400 ) ); |
| 982 | } |
982 | 983 | |
983 | | if ( ! empty( $prepared_post->ID ) && is_sticky( $prepared_post->ID ) ) { |
984 | | return new WP_Error( 'rest_invalid_field', __( 'A sticky post can not be password protected.' ), array( 'status' => 400 ) ); |
| 984 | if ( ! empty( $prepared_post->ID ) && is_sticky( $prepared_post->ID ) ) { |
| 985 | return new WP_Error( 'rest_invalid_field', __( 'A sticky post can not be password protected.' ), array( 'status' => 400 ) ); |
| 986 | } |
985 | 987 | } |
986 | 988 | } |
987 | 989 | |
diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
index 526c390..0e738c3 100644
a
|
b
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
1949 | 1949 | $this->assertEquals( '', $new_data['content']['raw'] ); |
1950 | 1950 | } |
1951 | 1951 | |
| 1952 | public function test_update_post_with_empty_password() { |
| 1953 | wp_set_current_user( self::$editor_id ); |
| 1954 | wp_update_post( array( |
| 1955 | 'ID' => self::$post_id, |
| 1956 | 'post_password' => 'foo', |
| 1957 | ) ); |
| 1958 | |
| 1959 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| 1960 | $params = $this->set_post_data( array( |
| 1961 | 'password' => '', |
| 1962 | ) ); |
| 1963 | $request->set_body_params( $params ); |
| 1964 | $response = $this->server->dispatch( $request ); |
| 1965 | $data = $response->get_data(); |
| 1966 | $this->assertEquals( '', $data['password'] ); |
| 1967 | } |
| 1968 | |
1952 | 1969 | public function test_update_post_with_password_and_sticky_fails() { |
1953 | 1970 | wp_set_current_user( self::$editor_id ); |
1954 | 1971 | |