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. git-svn-id: https://develop.svn.wordpress.org/trunk@32002 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
468da41811
commit
ddb33c9aed
@ -1294,6 +1294,7 @@ 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>';
|
$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 ) );
|
$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 = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
|
||||||
$return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
|
$return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
|
||||||
@ -1309,7 +1310,11 @@ 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 );
|
$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";
|
$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 {
|
} else {
|
||||||
$return .= "<span id='view-post-btn'><a href='" . get_permalink( $post ) . "' class='button button-small'>$view_post</a></span>\n";
|
if ( empty( $pretty_permalink ) ) {
|
||||||
|
$pretty_permalink = $permalink;
|
||||||
|
}
|
||||||
|
|
||||||
|
$return .= "<span id='view-post-btn'><a href='" . $pretty_permalink . "' class='button button-small'>$view_post</a></span>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,4 +269,48 @@ class Tests_Admin_includesPost extends WP_UnitTestCase {
|
|||||||
$wp_rewrite->set_permalink_structure( $old_permalink_structure );
|
$wp_rewrite->set_permalink_structure( $old_permalink_structure );
|
||||||
flush_rewrite_rules();
|
flush_rewrite_rules();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 30910
|
||||||
|
*/
|
||||||
|
public function test_get_sample_permalink_html_should_use_default_permalink_for_view_post_button_when_pretty_permalinks_are_disabled() {
|
||||||
|
global $wp_rewrite;
|
||||||
|
$old_permalink_structure = get_option( 'permalink_structure' );
|
||||||
|
$wp_rewrite->set_permalink_structure( '' );
|
||||||
|
flush_rewrite_rules();
|
||||||
|
|
||||||
|
wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
|
||||||
|
|
||||||
|
$future_date = date( 'Y-m-d H:i:s', time() + 100 );
|
||||||
|
$p = $this->factory->post->create( array( 'post_status' => 'future', 'post_name' => 'foo', 'post_date' => $future_date ) );
|
||||||
|
|
||||||
|
$found = get_sample_permalink_html( $p );
|
||||||
|
$this->assertContains( "span id='view-post-btn'><a href='" . get_option( 'home' ) . "/?p=$p'", $found );
|
||||||
|
|
||||||
|
$wp_rewrite->set_permalink_structure( $old_permalink_structure );
|
||||||
|
flush_rewrite_rules();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 30910
|
||||||
|
*/
|
||||||
|
public function test_get_sample_permalink_html_should_use_pretty_permalink_for_view_post_button_when_pretty_permalinks_are_enabled() {
|
||||||
|
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' ) ) );
|
||||||
|
|
||||||
|
$future_date = date( 'Y-m-d H:i:s', time() + 100 );
|
||||||
|
$p = $this->factory->post->create( array( 'post_status' => 'future', 'post_name' => 'foo', 'post_date' => $future_date ) );
|
||||||
|
|
||||||
|
$found = get_sample_permalink_html( $p );
|
||||||
|
$post = get_post( $p );
|
||||||
|
$this->assertContains( "span id='view-post-btn'><a href='" . get_option( 'home' ) . "/" . $post->post_name . "/'", $found );
|
||||||
|
|
||||||
|
$wp_rewrite->set_permalink_structure( $old_permalink_structure );
|
||||||
|
flush_rewrite_rules();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user