WordPress.org

Make WordPress Core

Changeset 38572


Ignore:
Timestamp:
09/08/2016 04:04:22 AM (21 months ago)
Author:
jorbin
Message:

Permalinks: Ensure Pending Review Posts permalink posts link to the draft

[34670] made the displayed permalink clickable. For posts that were pending review, the permalink wasn't being properly generated so the link wouldn't go to the preview.

Props knutsp, enshrined.
Fixes #37423.

Location:
trunk
Files:
2 edited

Legend:

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

    r38303 r38572  
    13011301
    13021302    if ( current_user_can( 'read_post', $post->ID ) ) {
    1303         if ( 'draft' === $post->post_status ) {
     1303        if ( 'draft' === $post->post_status || empty( $post->post_name ) ) {
    13041304            $view_link = get_preview_post_link( $post );
    13051305            $preview_target = " target='wp-preview-{$post->ID}'";
     
    13081308                $view_link = get_permalink( $post );
    13091309            } else {
    1310                 // Allow non-published (private, future) to be viewed at a pretty permalink.
     1310                // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set
    13111311                $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
    13121312            }
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r38417 r38572  
    358358
    359359    /**
     360     * @ticket 30910
     361     * @ticket 18306
     362     */
     363    public function test_get_sample_permalink_html_should_use_preview_links_for_draft_and_pending_posts_with_no_post_name() {
     364        $this->set_permalink_structure( '/%postname%/' );
     365
     366        wp_set_current_user( self::$admin_id );
     367
     368        $future_date = date( 'Y-m-d H:i:s', time() + 100 );
     369        $p = self::factory()->post->create( array( 'post_status' => 'pending', 'post_name' => '', 'post_date' => $future_date ) );
     370
     371        $found = get_sample_permalink_html( $p );
     372        $post = get_post( $p );
     373        $this->assertContains( 'href="' . esc_url( get_preview_post_link( $post ) ), $found );
     374    }
     375
     376    /**
    360377     * @ticket 5305
    361378     */
Note: See TracChangeset for help on using the changeset viewer.