wp_get_shortlink() improvements.
* Return shortlinks for pages and public CPTs. * Return shortlinks even when cruft-free links are not enabled. * Unit tests Props sillybean, layotte, cais fixes #18632 see #14760 Built from https://develop.svn.wordpress.org/trunk@25030 git-svn-id: http://core.svn.wordpress.org/trunk@25017 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d203c9f6bb
commit
564d80e29f
|
@ -368,7 +368,7 @@ wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
|
|||
<?php
|
||||
$sample_permalink_html = $post_type_object->public ? get_sample_permalink_html($post->ID) : '';
|
||||
$shortlink = wp_get_shortlink($post->ID, 'post');
|
||||
if ( !empty($shortlink) )
|
||||
if ( !empty( $shortlink ) && $shortlink !== get_permalink( $post->ID ) )
|
||||
$sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button button-small" onclick="prompt('URL:', jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>';
|
||||
|
||||
if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) {
|
||||
|
|
|
@ -2351,8 +2351,9 @@ function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) {
|
|||
|
||||
global $wp_query;
|
||||
$post_id = 0;
|
||||
if ( 'query' == $context && is_single() ) {
|
||||
if ( 'query' == $context && is_singular() ) {
|
||||
$post_id = $wp_query->get_queried_object_id();
|
||||
$post = get_post( $post_id );
|
||||
} elseif ( 'post' == $context ) {
|
||||
$post = get_post( $id );
|
||||
$post_id = $post->ID;
|
||||
|
@ -2360,11 +2361,11 @@ function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) {
|
|||
|
||||
$shortlink = '';
|
||||
|
||||
// Return p= link for posts.
|
||||
if ( !empty($post_id) && '' != get_option('permalink_structure') ) {
|
||||
$post = get_post($post_id);
|
||||
if ( isset($post->post_type) && 'post' == $post->post_type )
|
||||
$shortlink = home_url('?p=' . $post->ID);
|
||||
// Return p= link for all public post types.
|
||||
if ( ! empty( $post_id ) ) {
|
||||
$post_type = get_post_type_object( $post->post_type );
|
||||
if ( $post_type->public )
|
||||
$shortlink = home_url('?p=' . $post_id);
|
||||
}
|
||||
|
||||
return apply_filters('get_shortlink', $shortlink, $id, $context, $allow_slugs);
|
||||
|
|
Loading…
Reference in New Issue