Changeset 46252
- Timestamp:
- 09/23/2019 05:39:36 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r46246 r46252 338 338 'draft', 339 339 array( 340 'label' => _x( 'Draft', 'post status' ),341 'protected' => true,342 '_builtin' => true, /* internal use only. */340 'label' => _x( 'Draft', 'post status' ), 341 'protected' => true, 342 '_builtin' => true, /* internal use only. */ 343 343 /* translators: %s: Number of draft posts. */ 344 'label_count' => _n_noop(344 'label_count' => _n_noop( 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 ); … … 395 396 'auto-draft', 396 397 array( 397 'label' => 'auto-draft', 398 'internal' => true, 399 '_builtin' => true, /* internal use only. */ 398 'label' => 'auto-draft', 399 'internal' => true, 400 '_builtin' => true, /* internal use only. */ 401 'date_floating' => true, 400 402 ) 401 403 ); … … 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 … … 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 ); … … 1084 1089 if ( null === $args->show_in_admin_status_list ) { 1085 1090 $args->show_in_admin_status_list = ! $args->internal; 1091 } 1092 1093 if ( null === $args->date_floating ) { 1094 $args->date_floating = false; 1086 1095 } 1087 1096 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php
r45811 r46252 233 233 if ( in_array( 'slug', $fields, true ) ) { 234 234 $data['slug'] = $status->name; 235 } 236 237 if ( in_array( 'date_floating', $fields, true ) ) { 238 $data['date_floating'] = $status->date_floating; 235 239 } 236 240 … … 278 282 'type' => 'object', 279 283 'properties' => array( 280 'name' => array(284 'name' => array( 281 285 'description' => __( 'The title for the status.' ), 282 286 'type' => 'string', … … 284 288 'readonly' => true, 285 289 ), 286 'private' => array(290 'private' => array( 287 291 'description' => __( 'Whether posts with this status should be private.' ), 288 292 'type' => 'boolean', … … 290 294 'readonly' => true, 291 295 ), 292 'protected' => array(296 'protected' => array( 293 297 'description' => __( 'Whether posts with this status should be protected.' ), 294 298 'type' => 'boolean', … … 296 300 'readonly' => true, 297 301 ), 298 'public' => array(302 'public' => array( 299 303 'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ), 300 304 'type' => 'boolean', … … 302 306 'readonly' => true, 303 307 ), 304 'queryable' => array(308 'queryable' => array( 305 309 'description' => __( 'Whether posts with this status should be publicly-queryable.' ), 306 310 'type' => 'boolean', … … 308 312 'readonly' => true, 309 313 ), 310 'show_in_list' => array(314 'show_in_list' => array( 311 315 'description' => __( 'Whether to include posts in the edit listing for their post type.' ), 312 316 'type' => 'boolean', … … 314 318 'readonly' => true, 315 319 ), 316 'slug' => array(320 'slug' => array( 317 321 'description' => __( 'An alphanumeric identifier for the status.' ), 318 322 'type' => 'string', 319 323 'context' => array( 'embed', 'view', 'edit' ), 324 'readonly' => true, 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' ), 320 330 'readonly' => true, 321 331 ), -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r46249 r46252 1022 1022 // Post date. 1023 1023 if ( ! empty( $schema['properties']['date'] ) && ! empty( $request['date'] ) ) { 1024 $date_data = rest_get_date_with_gmt( $request['date'] ); 1025 1026 if ( ! empty( $date_data ) ) { 1024 $current_date = isset( $prepared_post->ID ) ? get_post( $prepared_post->ID )->post_date : false; 1025 $date_data = rest_get_date_with_gmt( $request['date'] ); 1026 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'] ) ) { 1031 $date_data = rest_get_date_with_gmt( $request['date_gmt'], true ); 1032 1033 if ( ! empty( $date_data ) ) { 1032 $current_date = isset( $prepared_post->ID ) ? get_post( $prepared_post->ID )->post_date_gmt : false; 1033 $date_data = rest_get_date_with_gmt( $request['date_gmt'], true ); 1034 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; -
trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php
r43571 r46252 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 ); … … 162 162 $this->assertArrayHasKey( 'show_in_list', $properties ); 163 163 $this->assertArrayHasKey( 'slug', $properties ); 164 $this->assertArrayhasKey( 'date_floating', $properties ); 164 165 } 165 166 … … 218 219 array_keys( $links ) 219 220 ); 221 $this->assertEquals( $status_obj->date_floating, $data['date_floating'] ); 220 222 } 221 223 -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r46249 r46252 4414 4414 } 4415 4415 4416 public function test_putting_same_publish_date_does_not_remove_floating_date() { 4417 4418 wp_set_current_user( self::$superadmin_id ); 4419 4420 $time = date( 'Y-m-d H:i:s' ); 4421 4422 $post = self::factory()->post->create_and_get( 4423 array( 4424 'post_status' => 'draft', 4425 'post_date' => $time, 4426 ) 4427 ); 4428 4429 $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); 4430 4431 $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); 4432 $get->set_query_params( array( 'context' => 'edit' ) ); 4433 4434 $get = rest_get_server()->dispatch( $get ); 4435 $get_body = $get->get_data(); 4436 4437 $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); 4438 $put->set_body_params( $get_body ); 4439 4440 $response = rest_get_server()->dispatch( $put ); 4441 $body = $response->get_data(); 4442 4443 $this->assertEquals( $get_body['date'], $body['date'] ); 4444 $this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] ); 4445 4446 $this->assertEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); 4447 } 4448 4449 public function test_putting_different_publish_date_removes_floating_date() { 4450 4451 wp_set_current_user( self::$superadmin_id ); 4452 4453 $time = date( 'Y-m-d H:i:s' ); 4454 $new_time = date( 'Y-m-d H:i:s', strtotime( '+1 week' ) ); 4455 4456 $post = self::factory()->post->create_and_get( 4457 array( 4458 'post_status' => 'draft', 4459 'post_date' => $time, 4460 ) 4461 ); 4462 4463 $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); 4464 4465 $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); 4466 $get->set_query_params( array( 'context' => 'edit' ) ); 4467 4468 $get = rest_get_server()->dispatch( $get ); 4469 $get_body = $get->get_data(); 4470 4471 $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); 4472 $put->set_body_params( 4473 array_merge( 4474 $get_body, 4475 array( 4476 'date' => mysql_to_rfc3339( $new_time ), 4477 ) 4478 ) 4479 ); 4480 4481 $response = rest_get_server()->dispatch( $put ); 4482 $body = $response->get_data(); 4483 4484 $this->assertEquals( mysql_to_rfc3339( $new_time ), $body['date'] ); 4485 4486 $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); 4487 } 4488 4489 public function test_publishing_post_with_same_date_removes_floating_date() { 4490 4491 wp_set_current_user( self::$superadmin_id ); 4492 4493 $time = date( 'Y-m-d H:i:s' ); 4494 4495 $post = self::factory()->post->create_and_get( 4496 array( 4497 'post_status' => 'draft', 4498 'post_date' => $time, 4499 ) 4500 ); 4501 4502 $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); 4503 4504 $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); 4505 $get->set_query_params( array( 'context' => 'edit' ) ); 4506 4507 $get = rest_get_server()->dispatch( $get ); 4508 $get_body = $get->get_data(); 4509 4510 $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); 4511 $put->set_body_params( 4512 array_merge( 4513 $get_body, 4514 array( 4515 'status' => 'publish', 4516 ) 4517 ) 4518 ); 4519 4520 $response = rest_get_server()->dispatch( $put ); 4521 $body = $response->get_data(); 4522 4523 $this->assertEquals( $get_body['date'], $body['date'] ); 4524 $this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] ); 4525 4526 $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); 4527 } 4528 4416 4529 public function tearDown() { 4417 4530 _unregister_post_type( 'private-post' ); -
trunk/tests/qunit/fixtures/wp-api-generated.js
r46249 r46252 7393 7393 "queryable": true, 7394 7394 "slug": "publish", 7395 "date_floating": false, 7395 7396 "_links": { 7396 7397 "archives": [ … … 7406 7407 "queryable": false, 7407 7408 "slug": "future", 7409 "date_floating": false, 7408 7410 "_links": { 7409 7411 "archives": [ … … 7419 7421 "queryable": false, 7420 7422 "slug": "draft", 7423 "date_floating": true, 7421 7424 "_links": { 7422 7425 "archives": [ … … 7432 7435 "queryable": false, 7433 7436 "slug": "pending", 7437 "date_floating": false, 7434 7438 "_links": { 7435 7439 "archives": [ … … 7445 7449 "queryable": false, 7446 7450 "slug": "private", 7451 "date_floating": false, 7447 7452 "_links": { 7448 7453 "archives": [ … … 7458 7463 "queryable": false, 7459 7464 "slug": "trash", 7465 "date_floating": false, 7460 7466 "_links": { 7461 7467 "archives": [ … … 7472 7478 "public": true, 7473 7479 "queryable": true, 7474 "slug": "publish" 7480 "slug": "publish", 7481 "date_floating": false 7475 7482 }; 7476 7483
Note: See TracChangeset
for help on using the changeset viewer.