Fix the Permalink editor for custom post_types. Fixes #12742

git-svn-id: https://develop.svn.wordpress.org/trunk@13865 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2010-03-28 05:23:49 +00:00
parent fd04241472
commit b9682621d0
2 changed files with 19 additions and 8 deletions

View File

@ -1011,9 +1011,11 @@ function postbox_classes( $id, $page ) {
*/
function get_sample_permalink($id, $title = null, $name = null) {
$post = &get_post($id);
if ( !$post->ID ) {
if ( !$post->ID )
return array('', '');
}
$ptype = get_post_type_object($post->post_type);
$original_status = $post->post_status;
$original_date = $post->post_date;
$original_name = $post->post_name;
@ -1029,22 +1031,24 @@ function get_sample_permalink($id, $title = null, $name = null) {
// If the user wants to set a new name -- override the current one
// Note: if empty name is supplied -- use the title instead, see #6072
if ( !is_null($name) ) {
if ( !is_null($name) )
$post->post_name = sanitize_title($name ? $name : $title, $post->ID);
}
$post->filter = 'sample';
$permalink = get_permalink($post, true);
if ( $ptype->query_var ) // Replace custom post_type Token with generic pagename token for ease of use.
$permalink = str_replace('%' . $ptype->query_var . '%', '%pagename%', $permalink);
// Handle page hierarchy
if ( 'page' == $post->post_type ) {
if ( $ptype->hierarchical ) {
$uri = get_page_uri($post->ID);
$uri = untrailingslashit($uri);
$uri = strrev( stristr( strrev( $uri ), '/' ) );
$uri = untrailingslashit($uri);
if ( !empty($uri) )
$uri .='/';
$uri .= '/';
$permalink = str_replace('%pagename%', "${uri}%pagename%", $permalink);
}
@ -1074,7 +1078,14 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
if ( 'publish' == $post->post_status ) {
$view_post = 'post' == $post->post_type ? __('View Post') : __('View Page');
if ( 'post' == $post->post_type ) {
$view_post = __('View Post');
} elseif ( 'page' == $post->post_type ) {
$view_post = __('View Page');
} else {
$ptype = get_post_type_object($post->post_type);
$view_post = sprintf(__('View %s'), $ptype->singular_label);
}
$title = __('Click to edit this part of the permalink');
} else {
$title = __('Temporary permalink. Click to edit this part.');

View File

@ -108,7 +108,7 @@ function get_permalink($id = 0, $leavename = false) {
elseif ( $post->post_type == 'attachment' )
return get_attachment_link($post->ID);
elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) )
return get_post_permalink($post);
return get_post_permalink($post, $leavename);
$permalink = get_option('permalink_structure');