WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/15/13 20:08:06 (4 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r24940 r25030  
    23522352    global $wp_query; 
    23532353    $post_id = 0; 
    2354     if ( 'query' == $context && is_single() ) { 
     2354    if ( 'query' == $context && is_singular() ) {  
    23552355        $post_id = $wp_query->get_queried_object_id(); 
     2356        $post = get_post( $post_id ); 
    23562357    } elseif ( 'post' == $context ) { 
    2357         $post = get_post($id); 
     2358        $post = get_post( $id ); 
    23582359        $post_id = $post->ID; 
    23592360    } 
     
    23612362    $shortlink = ''; 
    23622363 
    2363     // Return p= link for posts. 
    2364     if ( !empty($post_id) && '' != get_option('permalink_structure') ) { 
    2365         $post = get_post($post_id); 
    2366         if ( isset($post->post_type) && 'post' == $post->post_type ) 
    2367             $shortlink = home_url('?p=' . $post->ID); 
     2364    // Return p= link for all public post types. 
     2365    if ( ! empty( $post_id ) ) { 
     2366        $post_type = get_post_type_object( $post->post_type ); 
     2367        if ( $post_type->public ) 
     2368            $shortlink = home_url('?p=' . $post_id); 
    23682369    } 
    23692370 
Note: See TracChangeset for help on using the changeset viewer.