WordPress.org

Make WordPress Core

Changeset 33773


Ignore:
Timestamp:
08/27/2015 08:56:54 PM (6 years ago)
Author:
johnbillion
Message:

Don't change the View Post button permalink in the sample permalink HTML when updating the slug on a published or future post.

Fixes #32954
Props boonebgorges, johnbillion

Location:
trunk
Files:
2 edited

Legend:

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

    r33734 r33773  
    13091309        $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
    13101310        $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, urldecode( $permalink ) );
    1311         $pretty_permalink = str_replace( array( '%pagename%', '%postname%' ), $post_name, urldecode( $permalink ) );
    13121311
    13131312        $return =  '<strong>' . __( 'Permalink:' ) . "</strong>\n";
     
    13251324            $return .= "<span id='view-post-btn'><a href='" . esc_url( $preview_link ) . "' class='button button-small' target='wp-preview-{$post->ID}'>$view_post</a></span>\n";
    13261325        } else {
    1327             if ( empty( $pretty_permalink ) ) {
    1328                 $pretty_permalink = $permalink;
     1326            if ( 'publish' === $post->post_status ) {
     1327                // View Post button should always go to the saved permalink.
     1328                $pretty_permalink = get_permalink( $post );
     1329            } else {
     1330                // Allow non-published (private, future) to be viewed at a pretty permalink.
     1331                $pretty_permalink = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, urldecode( $permalink ) );
    13291332            }
    13301333
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r32647 r33773  
    316316
    317317    /**
     318     * @ticket 32954
     319     */
     320    public function test_get_sample_permalink_html_should_use_correct_permalink_for_view_post_button_when_changing_slug() {
     321        global $wp_rewrite;
     322        $old_permalink_structure = get_option( 'permalink_structure' );
     323        $permalink_structure = '%postname%';
     324        $wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
     325        flush_rewrite_rules();
     326
     327        wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     328
     329        // Published posts should use published permalink
     330        $p = $this->factory->post->create( array( 'post_status' => 'publish', 'post_name' => 'foo' ) );
     331
     332        $found = get_sample_permalink_html( $p, null, 'new_slug' );
     333        $post = get_post( $p );
     334        $this->assertContains( "span id='view-post-btn'><a href='" . get_option( 'home' ) . "/" . $post->post_name . "/'", $found );
     335
     336        // Scheduled posts should use published permalink
     337        $future_date = date( 'Y-m-d H:i:s', time() + 100 );
     338        $p = $this->factory->post->create( array( 'post_status' => 'future', 'post_name' => 'bar', 'post_date' => $future_date ) );
     339
     340        $found = get_sample_permalink_html( $p, null, 'new_slug' );
     341        $post = get_post( $p );
     342        $this->assertContains( "span id='view-post-btn'><a href='" . get_option( 'home' ) . "/" . $post->post_name . "/'", $found );
     343
     344        // Draft posts should use preview link
     345        $p = $this->factory->post->create( array( 'post_status' => 'draft', 'post_name' => 'baz' ) );
     346
     347        $found = get_sample_permalink_html( $p, null, 'new_slug' );
     348        $post = get_post( $p );
     349
     350        $preview_link = get_permalink( $post->ID );
     351        $preview_link = add_query_arg( 'preview', 'true', $preview_link );
     352
     353        $this->assertContains( "span id='view-post-btn'><a href='" . esc_url( $preview_link ) . "'", $found );
     354
     355        $wp_rewrite->set_permalink_structure( $old_permalink_structure );
     356        flush_rewrite_rules();
     357    }
     358
     359    /**
    318360     * @ticket 5305
    319361     */
Note: See TracChangeset for help on using the changeset viewer.