From 913392b9a9f9c63a8619fcfe37a6acc5b5f42e66 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 30 Jun 2014 10:02:01 +0000 Subject: [PATCH] Display consistent preview links for drafts. props mordauk. fixes #28350. git-svn-id: https://develop.svn.wordpress.org/trunk@28920 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/post.php | 15 +++++++++++++-- src/wp-includes/admin-bar.php | 22 +++++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 4227e624b0..d3c7a7c12e 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -1179,7 +1179,11 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { if ( current_user_can( 'read_post', $post->ID ) ) { $ptype = get_post_type_object( $post->post_type ); - $view_post = $ptype->labels->view_item; + if( 'draft' == $post->post_status ) { + $view_post = __( 'Preview' ); + } else { + $view_post = $ptype->labels->view_item; + } } if ( 'publish' == get_post_status( $post ) ) { @@ -1234,7 +1238,14 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { $return .= '' . $post_name . "\n"; if ( isset( $view_post ) ) { - $return .= "$view_post\n"; + if( 'draft' == $post->post_status ) { + $preview_link = set_url_scheme( get_permalink( $post->ID ) ); + /** This filter is documented in wp-admin/includes/meta-boxes.php */ + $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ); + $return .= "$view_post\n"; + } else { + $return .= "$view_post\n"; + } } /** This filter is documented in wp-admin/includes/post.php */ diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php index 2a5c3b1f84..4215822fd9 100644 --- a/src/wp-includes/admin-bar.php +++ b/src/wp-includes/admin-bar.php @@ -493,11 +493,23 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) { && ( $post_type_object->public ) && ( $post_type_object->show_in_admin_bar ) ) { - $wp_admin_bar->add_menu( array( - 'id' => 'view', - 'title' => $post_type_object->labels->view_item, - 'href' => get_permalink( $post->ID ) - ) ); + if( 'draft' == $post->post_status ) { + $preview_link = set_url_scheme( get_permalink( $post->ID ) ); + /** This filter is documented in wp-admin/includes/meta-boxes.php */ + $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ); + $wp_admin_bar->add_menu( array( + 'id' => 'preview', + 'title' => __( 'Preview' ), + 'href' => esc_url( $preview_link ), + 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), + ) ); + } else { + $wp_admin_bar->add_menu( array( + 'id' => 'view', + 'title' => $post_type_object->labels->view_item, + 'href' => get_permalink( $post->ID ) + ) ); + } } elseif ( 'edit-tags' == $current_screen->base && isset( $tag ) && is_object( $tag ) && ( $tax = get_taxonomy( $tag->taxonomy ) )