Skip to content
Permalink
Browse files

Posts, Post Types: Build list of "date floating" post stati dynamical…

…ly 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
  • Loading branch information...
kadamwhite committed Sep 23, 2019
1 parent 0f1636c commit b7f36f7f56fa476d59431dddb5468a42427636ba
Showing with 37 additions and 1 deletion.
  1. +1 −1 src/wp-includes/post.php
  2. +36 −0 tests/phpunit/tests/post.php
@@ -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 ( ! 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 );
} else {
$post_date_gmt = '0000-00-00 00:00:00';
@@ -1394,4 +1394,40 @@ function test_pre_wp_unique_post_slug_filter() {
function filter_pre_wp_unique_post_slug( $default, $slug, $post_ID, $post_status, $post_type, $post_parent ) {
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 );
}
}

0 comments on commit b7f36f7

Please sign in to comment.
You can’t perform that action at this time.