Pass the screen context directly to get_sample_permalink_html(). see #16379.

git-svn-id: https://develop.svn.wordpress.org/trunk@22129 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2012-10-07 03:44:30 +00:00
parent 2aab5aa3b0
commit 5ecb1e0d87
5 changed files with 18 additions and 14 deletions

View File

@ -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() {

View File

@ -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 = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\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 = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
$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" : '<strong>' . __( 'Permalink:' ) . "</strong>\n";
$return = ( 'options-reading' == $screen->id ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n";
$return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
$return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
$return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
$return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
if ( isset( $view_post ) && 'options-reading' != $context )
if ( isset( $view_post ) && 'options-reading' != $screen->id )
$return .= "<span id='view-post-btn'><a href='$view_link' class='button button-small'>$view_post</a></span>\n";
$return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);

View File

@ -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);

0
wp-admin/js/sample-permalink.min.js vendored Normal file
View File

View File

@ -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'),