Make WordPress Core

Changeset 32002


Ignore:
Timestamp:
04/04/2015 01:26:08 AM (10 years ago)
Author:
boonebgorges
Message:

After [31114] and [31323], 'View Post' generated in get_sample_permalink_html() should go to pretty permalink.

get_permalink() will return a non-pretty permalink for future posts, which
breaks some user workflows that expect View Post to lead to a page with the
pretty permalink.

Fixes #30910.

Location:
trunk
Files:
2 edited

Legend:

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

    r31896 r32002  
    12951295        $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
    12961296        $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, urldecode( $permalink ) );
     1297        $pretty_permalink = str_replace( array( '%pagename%', '%postname%' ), $post_name, urldecode( $permalink ) );
    12971298
    12981299        $return =  '<strong>' . __( 'Permalink:' ) . "</strong>\n";
     
    13101311            $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";
    13111312        } else {
    1312             $return .= "<span id='view-post-btn'><a href='" . get_permalink( $post ) . "' class='button button-small'>$view_post</a></span>\n";
     1313            if ( empty( $pretty_permalink ) ) {
     1314                $pretty_permalink = $permalink;
     1315            }
     1316
     1317            $return .= "<span id='view-post-btn'><a href='" . $pretty_permalink . "' class='button button-small'>$view_post</a></span>\n";
    13131318        }
    13141319    }
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r31392 r32002  
    270270        flush_rewrite_rules();
    271271    }
     272
     273    /**
     274     * @ticket 30910
     275     */
     276    public function test_get_sample_permalink_html_should_use_default_permalink_for_view_post_button_when_pretty_permalinks_are_disabled() {
     277        global $wp_rewrite;
     278        $old_permalink_structure = get_option( 'permalink_structure' );
     279        $wp_rewrite->set_permalink_structure( '' );
     280        flush_rewrite_rules();
     281
     282        wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     283
     284        $future_date = date( 'Y-m-d H:i:s', time() + 100 );
     285        $p = $this->factory->post->create( array( 'post_status' => 'future', 'post_name' => 'foo', 'post_date' => $future_date ) );
     286
     287        $found = get_sample_permalink_html( $p );
     288        $this->assertContains( "span id='view-post-btn'><a href='" . get_option( 'home' ) . "/?p=$p'", $found );
     289
     290        $wp_rewrite->set_permalink_structure( $old_permalink_structure );
     291        flush_rewrite_rules();
     292    }
     293
     294    /**
     295     * @ticket 30910
     296     */
     297    public function test_get_sample_permalink_html_should_use_pretty_permalink_for_view_post_button_when_pretty_permalinks_are_enabled() {
     298        global $wp_rewrite;
     299        $old_permalink_structure = get_option( 'permalink_structure' );
     300        $permalink_structure = '%postname%';
     301        $wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
     302        flush_rewrite_rules();
     303
     304        wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     305
     306        $future_date = date( 'Y-m-d H:i:s', time() + 100 );
     307        $p = $this->factory->post->create( array( 'post_status' => 'future', 'post_name' => 'foo', 'post_date' => $future_date ) );
     308
     309        $found = get_sample_permalink_html( $p );
     310        $post = get_post( $p );
     311        $this->assertContains( "span id='view-post-btn'><a href='" . get_option( 'home' ) . "/" . $post->post_name . "/'", $found );
     312
     313        $wp_rewrite->set_permalink_structure( $old_permalink_structure );
     314        flush_rewrite_rules();
     315    }
    272316}
Note: See TracChangeset for help on using the changeset viewer.