diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 0edcb04938..d4f13d1ecf 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -1298,7 +1298,8 @@ function wp_ajax_sample_permalink() { $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0; $title = isset($_POST['new_title'])? $_POST['new_title'] : ''; $slug = isset($_POST['new_slug'])? $_POST['new_slug'] : null; - wp_die( get_sample_permalink_html( $post_id, $title, $slug ) ); + $screen = isset( $_POST['screen'] ) ? $_POST['screen'] : 'post'; + wp_die( get_sample_permalink_html( $post_id, $title, $slug, $screen ) ); } function wp_ajax_inline_save() { diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index aa671a72f7..40176d23f7 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1047,24 +1047,27 @@ function get_sample_permalink($id, $title = null, $name = null) { } /** - * sample permalink html - * - * intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor. + * Returns the HTML of the sample permalink slug editor. * * @since 2.5.0 * * @param int|object $id Post ID or post object. - * @param string $new_title (optional) New title - * @param string $new_slug (optional) New slug - * @return string intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor. + * @param string $new_title Optional. New title. + * @param string $new_slug Optional. New slug. + * @param string|WP_Screen $screen Optional. Screen where the editor is being shown. + * @return string The HTML of the sample permalink slug editor. */ -function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { +function get_sample_permalink_html( $id, $new_title = null, $new_slug = null, $screen = null ) { global $wpdb; $post = get_post($id); - $context = isset( $_POST['context'] ) ? $_POST['context'] : get_current_screen()->id; list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); + if ( isset( $screen ) ) + $screen = convert_to_screen( $screen ); + else + $screen = get_current_screen(); + if ( 'publish' == get_post_status( $post ) ) { $ptype = get_post_type_object($post->post_type); $view_post = $ptype->labels->view_item; @@ -1074,7 +1077,7 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { } if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { - if ( 'options-reading' == $context ) + if ( 'options-reading' == $screen->id ) return ''; $return = '' . __('Permalink:') . "\n" . '' . $permalink . "\n"; if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) @@ -1104,12 +1107,12 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { $post_name_html = '' . $post_name_abridged . ''; $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink); $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink); - $return = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '' . __( 'Permalink:' ) . "\n"; + $return = ( 'options-reading' == $screen->id ) ? __( 'Located at' ) . "\n" : '' . __( 'Permalink:' ) . "\n"; $return .= '' . $display_link . "\n"; $return .= '‎'; // Fix bi-directional text display defect in RTL languages. $return .= '' . __('Edit') . "\n"; $return .= '' . $post_name . "\n"; - if ( isset( $view_post ) && 'options-reading' != $context ) + if ( isset( $view_post ) && 'options-reading' != $screen->id ) $return .= "$view_post\n"; $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); diff --git a/wp-admin/js/sample-permalink.js b/wp-admin/js/sample-permalink.js index 9651dd0b54..7ba60e71ca 100644 --- a/wp-admin/js/sample-permalink.js +++ b/wp-admin/js/sample-permalink.js @@ -25,7 +25,7 @@ var editPermalink, makeSlugeditClickable; post_id: post_id, new_slug: new_slug, new_title: $('#title').val(), - context: pagenow, + screen: pagenow, samplepermalinknonce: $('#samplepermalinknonce').val() }, function(data) { $('#edit-slug-box').html(data); diff --git a/wp-admin/js/sample-permalink.min.js b/wp-admin/js/sample-permalink.min.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index eb19a2cdb3..d1790c2ef9 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -369,7 +369,7 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), false, 1 ); - $scripts->add( 'sample-permalink', "/wp-admin/js/sample-permalink.js", array(), false, 1 ); + $scripts->add( 'sample-permalink', "/wp-admin/js/sample-permalink$suffix.js", array(), false, 1 ); did_action( 'init' ) && $scripts->localize( 'sample-permalink', 'samplePermalinkL10n', array( 'ok' => __('OK'), 'cancel' => __('Cancel'),