Make WordPress Core


Ignore:
Timestamp:
08/18/2015 02:50:23 AM (9 years ago)
Author:
boonebgorges
Message:

When generating a fallback post_name using the post ID, wp_insert_post() should clear the post cache immediately.

If the post cache is not cleared at this point, the cache can become stale
for operations performed before the cache is cleared later in the function.
Specifically, the generation of a guid for new posts can use stale data,
resulting in non-unique values. [33262] introduced a call to get_post()
that introduced just such an invalidation problem.

Fixes #5305.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post.php

    r33261 r33630  
    436436
    437437    /**
     438     * @ticket 5305
     439     * @ticket 33392
     440     */
     441    public function test_wp_insert_post_should_invalidate_post_cache_before_generating_guid_when_post_name_is_empty_and_is_generated_from_the_post_ID(){
     442        register_post_type( 'wptests_pt' );
     443
     444        $p = wp_insert_post( array(
     445            'post_title' => '',
     446            'post_type' => 'wptests_pt',
     447            'post_status' => 'publish',
     448        ) );
     449
     450        $post = get_post( $p );
     451
     452        $this->assertContains( 'wptests_pt=' . $p, $post->guid );
     453    }
     454
     455    /**
    438456     * @ticket 5364
    439457     */
Note: See TracChangeset for help on using the changeset viewer.