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. git-svn-id: https://develop.svn.wordpress.org/trunk@38572 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
61abf68e6d
commit
57530f4b73
|
@ -1300,14 +1300,14 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
|
||||||
$preview_target = '';
|
$preview_target = '';
|
||||||
|
|
||||||
if ( current_user_can( 'read_post', $post->ID ) ) {
|
if ( current_user_can( 'read_post', $post->ID ) ) {
|
||||||
if ( 'draft' === $post->post_status ) {
|
if ( 'draft' === $post->post_status || empty( $post->post_name ) ) {
|
||||||
$view_link = get_preview_post_link( $post );
|
$view_link = get_preview_post_link( $post );
|
||||||
$preview_target = " target='wp-preview-{$post->ID}'";
|
$preview_target = " target='wp-preview-{$post->ID}'";
|
||||||
} else {
|
} else {
|
||||||
if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
|
if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
|
||||||
$view_link = get_permalink( $post );
|
$view_link = get_permalink( $post );
|
||||||
} else {
|
} else {
|
||||||
// Allow non-published (private, future) to be viewed at a pretty permalink.
|
// Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set
|
||||||
$view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
|
$view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,6 +356,23 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
|
||||||
$this->assertContains( '>new_slug-صورة<', $found, $message );
|
$this->assertContains( '>new_slug-صورة<', $found, $message );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 30910
|
||||||
|
* @ticket 18306
|
||||||
|
*/
|
||||||
|
public function test_get_sample_permalink_html_should_use_preview_links_for_draft_and_pending_posts_with_no_post_name() {
|
||||||
|
$this->set_permalink_structure( '/%postname%/' );
|
||||||
|
|
||||||
|
wp_set_current_user( self::$admin_id );
|
||||||
|
|
||||||
|
$future_date = date( 'Y-m-d H:i:s', time() + 100 );
|
||||||
|
$p = self::factory()->post->create( array( 'post_status' => 'pending', 'post_name' => '', 'post_date' => $future_date ) );
|
||||||
|
|
||||||
|
$found = get_sample_permalink_html( $p );
|
||||||
|
$post = get_post( $p );
|
||||||
|
$this->assertContains( 'href="' . esc_url( get_preview_post_link( $post ) ), $found );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ticket 5305
|
* @ticket 5305
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue