Make WordPress Core


Ignore:
Timestamp:
01/17/2008 04:51:32 PM (18 years ago)
Author:
matt
Message:

Edit permalink in place. Fixes #5679. Hat tip: nbachiyski.

File:
1 edited

Legend:

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

    r6604 r6633  
    525525}
    526526
     527function get_sample_permalink($id, $name = null) {
     528    $post = &get_post($id);
     529    $original_status = $post->post_status;
     530    $original_date = $post->post_date;
     531    $original_name = $post->post_name;
     532    if (in_array($post->post_status, array('draft', 'pending'))) {
     533        $post->post_status = 'publish';
     534        $post->post_date = date('Y-m-d H:i:s');
     535        $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
     536    }
     537    if (!is_null($name)) {
     538        $post->post_name = sanitize_title($name, $post->ID);
     539    }
     540    $permalink = get_permalink($post, true);
     541    $permalink = array($permalink, $post->post_name);
     542    $post->post_status = $original_status;
     543    $post->post_date = $original_date;
     544    $post->post_name = $original_name;
     545    return $permalink;
     546}
     547
     548function get_sample_permalink_html($id, $new_slug=null) {
     549    $post = &get_post($id);
     550    list($permalink, $post_name) = get_sample_permalink($post->ID, $new_slug);
     551    if (false === strpos($permalink, '%postname%')) {
     552        return '';
     553    }
     554    $title = __('You can edit this part of the permalink using the Edit button on the right');
     555    if (strlen($post_name) > 30) {
     556        $post_name = substr($post_name, 0, 14). '…' . substr($post_name, -14);
     557    }
     558    $post_name_html = '<span id="editable-post-name" title="'.$title.'">'.$post_name.'</span>';
     559    $display_link = str_replace('%postname%', $post_name_html, $permalink);
     560    return $display_link;
     561}
     562
    527563?>
Note: See TracChangeset for help on using the changeset viewer.