Posts, Post Types: Build list of "date floating" post stati dynamically when inserting post.

Completes work begun in #39953 to expose "date floating" status information to frontend clients via the REST API.

Props TimothyBlynJacobs.
Fixes #48113.


git-svn-id: https://develop.svn.wordpress.org/trunk@46279 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
K. Adam White 2019-09-23 21:01:16 +00:00
parent 0f1636c621
commit b7f36f7f56
2 changed files with 37 additions and 1 deletions

View File

@ -3727,7 +3727,7 @@ function wp_insert_post( $postarr, $wp_error = false ) {
} }
if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) { if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) {
if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) { if ( ! in_array( $post_status, get_post_stati( array( 'date_floating' => true ) ), true ) ) {
$post_date_gmt = get_gmt_from_date( $post_date ); $post_date_gmt = get_gmt_from_date( $post_date );
} else { } else {
$post_date_gmt = '0000-00-00 00:00:00'; $post_date_gmt = '0000-00-00 00:00:00';

View File

@ -1394,4 +1394,40 @@ class Tests_Post extends WP_UnitTestCase {
function filter_pre_wp_unique_post_slug( $default, $slug, $post_ID, $post_status, $post_type, $post_parent ) { function filter_pre_wp_unique_post_slug( $default, $slug, $post_ID, $post_status, $post_type, $post_parent ) {
return 'override-slug-' . $post_type; return 'override-slug-' . $post_type;
} }
/**
* @ticket 48113
*/
public function test_insert_post_should_respect_date_floating_post_status_arg() {
register_post_status( 'floating', array( 'date_floating' => true ) );
$post_id = self::factory()->post->create(
array(
'post_status' => 'floating',
'post_date' => null,
'post_date_gmt' => null,
)
);
$post = get_post( $post_id );
self::assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
}
/**
* @ticket 48113
*/
public function test_insert_post_should_respect_date_floating_post_status_arg_not_set() {
register_post_status( 'not-floating', array( 'date_floating' => false ) );
$post_id = self::factory()->post->create(
array(
'post_status' => 'floating',
'post_date' => null,
'post_date_gmt' => null,
)
);
$post = get_post( $post_id );
self::assertEquals( gmdate( 'Y-m-d H:i:s' ), $post->post_date_gmt );
}
} }