Make WordPress Core

Changeset 31323


Ignore:
Timestamp:
02/02/2015 04:49:23 PM (10 years ago)
Author:
boonebgorges
Message:

In get_sample_permalink(), override 'future' status before generating permalink.

In [31114], get_permalink() was modified to prevent pretty permalinks from
being generated for posts with the 'future' post status. This inadvertently
broke the pretty permalink preview for scheduled posts. The fix is to include
the 'future' status in the list of statuses that get_sample_permalink() fakes
as 'publish' before it fetches a permalink.

Props DrewAPicture.
Fixes #30910.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/post.php

    r31292 r31323  
    11531153
    11541154    // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    1155     if ( in_array( $post->post_status, array( 'draft', 'pending' ) ) ) {
     1155    if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ) ) ) {
    11561156        $post->post_status = 'publish';
    11571157        $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r28113 r31323  
    179179    }
    180180
     181    /**
     182     * @ticket 30910
     183     */
     184    public function test_get_sample_permalink_should_return_pretty_permalink_for_posts_with_post_status_future() {
     185        global $wp_rewrite;
     186
     187        $old_permalink_structure = get_option( 'permalink_structure' );
     188        $permalink_structure = '%postname%';
     189        $wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
     190        flush_rewrite_rules();
     191
     192        $future_date = date( 'Y-m-d H:i:s', time() + 100 );
     193        $p = $this->factory->post->create( array( 'post_status' => 'future', 'post_name' => 'foo', 'post_date' => $future_date ) );
     194
     195        $found = get_sample_permalink( $p );
     196        $expected = trailingslashit( home_url( $permalink_structure ) );
     197
     198        $this->assertSame( $expected, $found[0] );
     199
     200        $wp_rewrite->set_permalink_structure( $old_permalink_structure );
     201        flush_rewrite_rules();
     202    }
    181203}
Note: See TracChangeset for help on using the changeset viewer.