Ticket #39953: 39953.1.patch
File 39953.1.patch, 9.5 KB (added by , 4 years ago) |
---|
-
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index 4876f40f0d..06aaf19d31 100644
function create_initial_post_types() { 345 345 'Draft <span class="count">(%s)</span>', 346 346 'Drafts <span class="count">(%s)</span>' 347 347 ), 348 'date_floating' => true, 348 349 ) 349 350 ); 350 351 … … function create_initial_post_types() { 397 398 'label' => 'auto-draft', 398 399 'internal' => true, 399 400 '_builtin' => true, /* internal use only. */ 401 'date_floating' => true 400 402 ) 401 403 ); 402 404 … … function _wp_privacy_statuses() { 1018 1020 * the top of the edit listings, 1019 1021 * e.g. All (12) | Published (9) | My Custom Status (2) 1020 1022 * Default is value of $internal. 1023 * @type bool $date_floating Whether the post has a floating creation date. 1024 * Default to false. 1021 1025 * } 1022 1026 * @return object 1023 1027 */ … … function register_post_status( $post_status, $args = array() ) { 1041 1045 'publicly_queryable' => null, 1042 1046 'show_in_admin_status_list' => null, 1043 1047 'show_in_admin_all_list' => null, 1048 'date_floating' => null, 1044 1049 ); 1045 1050 $args = wp_parse_args( $args, $defaults ); 1046 1051 $args = (object) $args; … … function register_post_status( $post_status, $args = array() ) { 1085 1090 $args->show_in_admin_status_list = ! $args->internal; 1086 1091 } 1087 1092 1093 if ( null === $args->date_floating ) { 1094 $args->date_floating = false; 1095 } 1096 1088 1097 if ( false === $args->label ) { 1089 1098 $args->label = $post_status; 1090 1099 } -
src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php index 155c8aaa96..23ff60e90d 100644
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { 234 234 $data['slug'] = $status->name; 235 235 } 236 236 237 if ( in_array('date_floating', $fields, true ) ) { 238 $data['date_floating'] = $status->date_floating; 239 } 240 237 241 $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; 238 242 $data = $this->add_additional_fields_to_object( $data, $request ); 239 243 $data = $this->filter_response_by_context( $data, $context ); … … class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { 319 323 'context' => array( 'embed', 'view', 'edit' ), 320 324 'readonly' => true, 321 325 ), 326 'date_floating'=> array( 327 'description' => __( 'Whether posts of this status may have floating published dates.' ), 328 'type' => 'boolean', 329 'context' => array( 'view', 'edit' ), 330 'readonly' => true 331 ) 322 332 ), 323 333 ); 324 334 -
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 8b4dfef229..9d3b489488 100644
class WP_REST_Posts_Controller extends WP_REST_Controller { 1021 1021 1022 1022 // Post date. 1023 1023 if ( ! empty( $schema['properties']['date'] ) && ! empty( $request['date'] ) ) { 1024 $current_date = isset( $prepared_post->ID ) ? get_post( $prepared_post->ID )->post_date : false; 1024 1025 $date_data = rest_get_date_with_gmt( $request['date'] ); 1025 1026 1026 if ( ! empty( $date_data ) ) {1027 if ( ! empty( $date_data ) && $current_date !== $date_data[0] ) { 1027 1028 list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data; 1028 1029 $prepared_post->edit_date = true; 1029 1030 } 1030 1031 } elseif ( ! empty( $schema['properties']['date_gmt'] ) && ! empty( $request['date_gmt'] ) ) { 1032 $current_date = isset( $prepared_post->ID ) ? get_post( $prepared_post->ID )->post_date_gmt : false; 1031 1033 $date_data = rest_get_date_with_gmt( $request['date_gmt'], true ); 1032 1034 1033 if ( ! empty( $date_data ) ) {1035 if ( ! empty( $date_data ) && $current_date !== $date_data[1] ) { 1034 1036 list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data; 1035 1037 $prepared_post->edit_date = true; 1036 1038 } -
tests/phpunit/tests/rest-api/rest-post-statuses-controller.php
diff --git tests/phpunit/tests/rest-api/rest-post-statuses-controller.php tests/phpunit/tests/rest-api/rest-post-statuses-controller.php index 1fe933b008..1a32293c88 100644
class WP_Test_REST_Post_Statuses_Controller extends WP_Test_REST_Controller_Test 153 153 $response = rest_get_server()->dispatch( $request ); 154 154 $data = $response->get_data(); 155 155 $properties = $data['schema']['properties']; 156 $this->assertEquals( 7, count( $properties ) );156 $this->assertEquals( 8, count( $properties ) ); 157 157 $this->assertArrayHasKey( 'name', $properties ); 158 158 $this->assertArrayHasKey( 'private', $properties ); 159 159 $this->assertArrayHasKey( 'protected', $properties ); … … class WP_Test_REST_Post_Statuses_Controller extends WP_Test_REST_Controller_Test 161 161 $this->assertArrayHasKey( 'queryable', $properties ); 162 162 $this->assertArrayHasKey( 'show_in_list', $properties ); 163 163 $this->assertArrayHasKey( 'slug', $properties ); 164 $this->assertArrayhasKey( 'date_floating', $properties ); 164 165 } 165 166 166 167 public function test_get_additional_field_registration() { … … class WP_Test_REST_Post_Statuses_Controller extends WP_Test_REST_Controller_Test 217 218 ), 218 219 array_keys( $links ) 219 220 ); 221 $this->assertEquals( $status_obj->date_floating, $data['date_floating']); 220 222 } 221 223 222 224 protected function check_post_status_object_response( $response ) { -
tests/phpunit/tests/rest-api/rest-posts-controller.php
diff --git tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php index ba174c448e..422eb79cf2 100644
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 4283 4283 4284 4284 } 4285 4285 4286 public function test_putting_same_publish_date_does_not_remove_floating_date() { 4287 4288 wp_set_current_user( self::$superadmin_id ); 4289 4290 $time = date( 'Y-m-d H:i:s' ); 4291 4292 $post = self::factory()->post->create_and_get( array( 4293 'post_status' => 'draft', 4294 'post_date' => $time, 4295 ) ); 4296 4297 $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); 4298 4299 $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); 4300 $get->set_query_params( array( 'context' => 'edit' ) ); 4301 4302 $get = rest_get_server()->dispatch( $get ); 4303 $get_body = $get->get_data(); 4304 4305 $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); 4306 $put->set_body_params( $get_body ); 4307 4308 $response = rest_get_server()->dispatch( $put ); 4309 $body = $response->get_data(); 4310 4311 $this->assertEquals( $get_body['date'], $body['date'] ); 4312 $this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] ); 4313 4314 $this->assertEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); 4315 } 4316 4317 public function test_putting_different_publish_date_removes_floating_date() { 4318 4319 wp_set_current_user( self::$superadmin_id ); 4320 4321 $time = date( 'Y-m-d H:i:s' ); 4322 $new_time = date( 'Y-m-d H:i:s', strtotime( '+1 week' ) ); 4323 4324 $post = self::factory()->post->create_and_get( array( 4325 'post_status' => 'draft', 4326 'post_date' => $time, 4327 ) ); 4328 4329 $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); 4330 4331 $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); 4332 $get->set_query_params( array( 'context' => 'edit' ) ); 4333 4334 $get = rest_get_server()->dispatch( $get ); 4335 $get_body = $get->get_data(); 4336 4337 $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); 4338 $put->set_body_params( array_merge( $get_body, array( 4339 'date' => mysql_to_rfc3339( $new_time ), 4340 ) ) ); 4341 4342 $response = rest_get_server()->dispatch( $put ); 4343 $body = $response->get_data(); 4344 4345 $this->assertEquals( mysql_to_rfc3339( $new_time ), $body['date'] ); 4346 4347 $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); 4348 } 4349 4350 public function test_publishing_post_with_same_date_removes_floating_date() { 4351 4352 wp_set_current_user( self::$superadmin_id ); 4353 4354 $time = date( 'Y-m-d H:i:s' ); 4355 4356 $post = self::factory()->post->create_and_get( array( 4357 'post_status' => 'draft', 4358 'post_date' => $time, 4359 ) ); 4360 4361 $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); 4362 4363 $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); 4364 $get->set_query_params( array( 'context' => 'edit' ) ); 4365 4366 $get = rest_get_server()->dispatch( $get ); 4367 $get_body = $get->get_data(); 4368 4369 $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); 4370 $put->set_body_params( array_merge( $get_body, array( 4371 'status' => 'publish', 4372 ) ) ); 4373 4374 $response = rest_get_server()->dispatch( $put ); 4375 $body = $response->get_data(); 4376 4377 $this->assertEquals( $get_body['date'], $body['date'] ); 4378 $this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] ); 4379 4380 $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); 4381 } 4382 4286 4383 public function tearDown() { 4287 4384 _unregister_post_type( 'private-post' ); 4288 4385 _unregister_post_type( 'youseeme' );