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 git-svn-id: https://develop.svn.wordpress.org/trunk@33773 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
65c07b81c0
commit
d89398f945
@ -1308,7 +1308,6 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
|
||||
|
||||
$post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
|
||||
$display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, urldecode( $permalink ) );
|
||||
$pretty_permalink = str_replace( array( '%pagename%', '%postname%' ), $post_name, urldecode( $permalink ) );
|
||||
|
||||
$return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
|
||||
$return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
|
||||
@ -1324,8 +1323,12 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
|
||||
$preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
|
||||
$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";
|
||||
} else {
|
||||
if ( empty( $pretty_permalink ) ) {
|
||||
$pretty_permalink = $permalink;
|
||||
if ( 'publish' === $post->post_status ) {
|
||||
// View Post button should always go to the saved permalink.
|
||||
$pretty_permalink = get_permalink( $post );
|
||||
} else {
|
||||
// Allow non-published (private, future) to be viewed at a pretty permalink.
|
||||
$pretty_permalink = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, urldecode( $permalink ) );
|
||||
}
|
||||
|
||||
$return .= "<span id='view-post-btn'><a href='" . $pretty_permalink . "' class='button button-small'>$view_post</a></span>\n";
|
||||
|
@ -314,6 +314,48 @@ class Tests_Admin_includesPost extends WP_UnitTestCase {
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 32954
|
||||
*/
|
||||
public function test_get_sample_permalink_html_should_use_correct_permalink_for_view_post_button_when_changing_slug() {
|
||||
global $wp_rewrite;
|
||||
$old_permalink_structure = get_option( 'permalink_structure' );
|
||||
$permalink_structure = '%postname%';
|
||||
$wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
|
||||
flush_rewrite_rules();
|
||||
|
||||
wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
|
||||
|
||||
// Published posts should use published permalink
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'publish', 'post_name' => 'foo' ) );
|
||||
|
||||
$found = get_sample_permalink_html( $p, null, 'new_slug' );
|
||||
$post = get_post( $p );
|
||||
$this->assertContains( "span id='view-post-btn'><a href='" . get_option( 'home' ) . "/" . $post->post_name . "/'", $found );
|
||||
|
||||
// Scheduled posts should use published permalink
|
||||
$future_date = date( 'Y-m-d H:i:s', time() + 100 );
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'future', 'post_name' => 'bar', 'post_date' => $future_date ) );
|
||||
|
||||
$found = get_sample_permalink_html( $p, null, 'new_slug' );
|
||||
$post = get_post( $p );
|
||||
$this->assertContains( "span id='view-post-btn'><a href='" . get_option( 'home' ) . "/" . $post->post_name . "/'", $found );
|
||||
|
||||
// Draft posts should use preview link
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'draft', 'post_name' => 'baz' ) );
|
||||
|
||||
$found = get_sample_permalink_html( $p, null, 'new_slug' );
|
||||
$post = get_post( $p );
|
||||
|
||||
$preview_link = get_permalink( $post->ID );
|
||||
$preview_link = add_query_arg( 'preview', 'true', $preview_link );
|
||||
|
||||
$this->assertContains( "span id='view-post-btn'><a href='" . esc_url( $preview_link ) . "'", $found );
|
||||
|
||||
$wp_rewrite->set_permalink_structure( $old_permalink_structure );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 5305
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user