WordPress.org

Make WordPress Core

Changeset 10525


Ignore:
Timestamp:
02/08/09 13:38:02 (5 years ago)
Author:
azaozz
Message:

Fix permalink editor for pages, hide "View Post" button while editing permalink, fixes #9040

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r10458 r10525  
    944944 * @return unknown 
    945945 */ 
    946 function get_sample_permalink_html($id, $new_title=null, $new_slug=null) { 
     946function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { 
    947947    $post = &get_post($id); 
    948948    list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); 
     
    951951     
    952952    if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { 
    953         if ( 'page' == $post->post_type ) 
    954             return ''; 
    955          
    956953        $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $permalink . "</span>\n"; 
    957954        $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n"; 
  • trunk/wp-admin/js/slug.dev.js

    r10291 r10525  
    22    var i, c = 0, e = jQuery('#editable-post-name'), revert_e = e.html(), real_slug = jQuery('#post_name'), revert_slug = real_slug.html(), b = jQuery('#edit-slug-buttons'), revert_b = b.html(), full = jQuery('#editable-post-name-full').html(); 
    33 
    4     b.html('<a href="" class="save button">'+slugL10n.save+'</a> <a class="cancel" href="">'+slugL10n.cancel+'</a>'); 
     4    jQuery('#view-post-btn').hide(); 
     5    b.html('<a href="#" class="save button">'+slugL10n.save+'</a> <a class="cancel" href="#">'+slugL10n.cancel+'</a>'); 
    56    b.children('.save').click(function() { 
    67        var new_slug = e.children('input').val(); 
     
    1516                real_slug.attr('value', new_slug); 
    1617                make_slugedit_clickable(); 
     18                jQuery('#view-post-btn').show(); 
    1719            }); 
    1820        return false; 
    1921    }); 
    2022    jQuery('#edit-slug-buttons .cancel').click(function() { 
     23        jQuery('#view-post-btn').show(); 
    2124        e.html(revert_e); 
    2225        b.html(revert_b); 
  • trunk/wp-admin/js/slug.js

    r10291 r10525  
    1 function edit_permalink(a){var d,h=0,g=jQuery("#editable-post-name"),j=g.html(),m=jQuery("#post_name"),n=m.html(),k=jQuery("#edit-slug-buttons"),l=k.html(),f=jQuery("#editable-post-name-full").html();k.html('<a href="" class="save button">'+slugL10n.save+'</a> <a class="cancel" href="">'+slugL10n.cancel+"</a>");k.children(".save").click(function(){var b=g.children("input").val();jQuery.post(slugL10n.requestFile,{action:"sample-permalink",post_id:a,new_slug:b,new_title:jQuery("#title").val(),samplepermalinknonce:jQuery("#samplepermalinknonce").val()},function(c){jQuery("#edit-slug-box").html(c);k.html(l);m.attr("value",b);make_slugedit_clickable()});return false});jQuery("#edit-slug-buttons .cancel").click(function(){g.html(j);k.html(l);m.attr("value",n);return false});for(d=0;d<f.length;++d){if("%"==f.charAt(d)){h++}}slug_value=(h>f.length/4)?"":f;g.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children("input").keypress(function(c){var b=c.charCode?c.charCode:c.keyCode?c.keyCode:0;if(13==b){k.children(".save").click();return false}if(27==b){k.children(".cancel").click();return false}m.attr("value",this.value)}).focus()}function make_slugedit_clickable(){jQuery("#editable-post-name").click(function(){jQuery("#edit-slug-buttons").children(".edit-slug").click()})}; 
     1function edit_permalink(a){var d,h=0,g=jQuery("#editable-post-name"),j=g.html(),m=jQuery("#post_name"),n=m.html(),k=jQuery("#edit-slug-buttons"),l=k.html(),f=jQuery("#editable-post-name-full").html();jQuery("#view-post-btn").hide();k.html('<a href="#" class="save button">'+slugL10n.save+'</a> <a class="cancel" href="#">'+slugL10n.cancel+"</a>");k.children(".save").click(function(){var b=g.children("input").val();jQuery.post(slugL10n.requestFile,{action:"sample-permalink",post_id:a,new_slug:b,new_title:jQuery("#title").val(),samplepermalinknonce:jQuery("#samplepermalinknonce").val()},function(c){jQuery("#edit-slug-box").html(c);k.html(l);m.attr("value",b);make_slugedit_clickable();jQuery("#view-post-btn").show()});return false});jQuery("#edit-slug-buttons .cancel").click(function(){jQuery("#view-post-btn").show();g.html(j);k.html(l);m.attr("value",n);return false});for(d=0;d<f.length;++d){if("%"==f.charAt(d)){h++}}slug_value=(h>f.length/4)?"":f;g.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children("input").keypress(function(c){var b=c.charCode?c.charCode:c.keyCode?c.keyCode:0;if(13==b){k.children(".save").click();return false}if(27==b){k.children(".cancel").click();return false}m.attr("value",this.value)}).focus()}function make_slugedit_clickable(){jQuery("#editable-post-name").click(function(){jQuery("#edit-slug-buttons").children(".edit-slug").click()})}; 
  • trunk/wp-includes/link-template.php

    r10426 r10525  
    9393    ); 
    9494 
    95     if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) 
     95    if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) { 
    9696        $post = $id; 
    97     else 
     97        $sample = true; 
     98    } else { 
    9899        $post = &get_post($id); 
     100        $sample = false; 
     101    } 
    99102 
    100103    if ( empty($post->ID) ) return false; 
    101104 
    102105    if ( $post->post_type == 'page' ) 
    103         return get_page_link($post->ID, $leavename); 
     106        return get_page_link($post->ID, $leavename, $sample); 
    104107    elseif ($post->post_type == 'attachment') 
    105108        return get_attachment_link($post->ID); 
     
    178181 * 
    179182 * @param int $id Optional. Post ID. 
    180  * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name. 
    181  * @return string 
    182  */ 
    183 function get_page_link($id = false, $leavename = false) { 
     183 * @param bool $leavename Optional, defaults to false. Whether to keep page name. 
     184 * @param bool $sample Optional, defaults to false. Is it a sample permalink. 
     185 * @return string 
     186 */ 
     187function get_page_link( $id = false, $leavename = false, $sample = false ) { 
    184188    global $post; 
    185189 
     
    191195        $link = get_option('home'); 
    192196    else 
    193         $link = _get_page_link( $id , $leavename ); 
     197        $link = _get_page_link( $id , $leavename, $sample ); 
    194198 
    195199    return apply_filters('page_link', $link, $id); 
     
    206210 * @param int $id Optional. Post ID. 
    207211 * @param bool $leavename Optional. Leave name. 
    208  * @return string 
    209  */ 
    210 function _get_page_link( $id = false, $leavename = false ) { 
     212 * @param bool $sample Optional. Sample permalink. 
     213 * @return string 
     214 */ 
     215function _get_page_link( $id = false, $leavename = false, $sample = false ) { 
    211216    global $post, $wp_rewrite; 
    212217 
     
    218223    $pagestruct = $wp_rewrite->get_page_permastruct(); 
    219224 
    220     if ( '' != $pagestruct && isset($post->post_status) && 'draft' != $post->post_status ) { 
     225    if ( '' != $pagestruct && ( ( isset($post->post_status) && 'draft' != $post->post_status ) || $sample ) ) { 
    221226        $link = get_page_uri($id); 
    222227        $link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct); 
  • trunk/wp-includes/script-loader.php

    r10522 r10525  
    241241        ) ); 
    242242 
    243         $scripts->add( 'slug', "/wp-admin/js/slug$suffix.js", array('jquery'), '20090102' ); 
     243        $scripts->add( 'slug', "/wp-admin/js/slug$suffix.js", array('jquery'), '20090207' ); 
    244244        $scripts->add_data( 'slug', 'group', 1 ); 
    245245        $scripts->localize( 'slug', 'slugL10n', array( 
Note: See TracChangeset for help on using the changeset viewer.