Changeset 25030
- Timestamp:
- 08/15/2013 08:08:06 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/edit-form-advanced.php
r24955 r25030 369 369 $sample_permalink_html = $post_type_object->public ? get_sample_permalink_html($post->ID) : ''; 370 370 $shortlink = wp_get_shortlink($post->ID, 'post'); 371 if ( !empty( $shortlink) )371 if ( !empty( $shortlink ) && $shortlink !== get_permalink( $post->ID ) ) 372 372 $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>'; 373 373 -
trunk/src/wp-includes/link-template.php
r24940 r25030 2352 2352 global $wp_query; 2353 2353 $post_id = 0; 2354 if ( 'query' == $context && is_sing le() ) {2354 if ( 'query' == $context && is_singular() ) { 2355 2355 $post_id = $wp_query->get_queried_object_id(); 2356 $post = get_post( $post_id ); 2356 2357 } elseif ( 'post' == $context ) { 2357 $post = get_post( $id);2358 $post = get_post( $id ); 2358 2359 $post_id = $post->ID; 2359 2360 } … … 2361 2362 $shortlink = ''; 2362 2363 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); 2368 2369 } 2369 2370 -
trunk/tests/tests/link.php
r25002 r25030 3 3 * @group link 4 4 */ 5 class Tests_Link _Functionsextends WP_UnitTestCase {5 class Tests_Link extends WP_UnitTestCase { 6 6 7 7 function _get_pagenum_link_cb( $url ) { … … 28 28 $_SERVER['REQUEST_URI'] = $old_req_uri; 29 29 } 30 31 function test_wp_get_shortlink() { 32 $post_id = $this->factory->post->create(); 33 $post_id2 = $this->factory->post->create(); 34 35 // Basic case 36 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) ); 37 38 // Global post is not set 39 $this->assertEquals( '', wp_get_shortlink( 0, 'post' ) ); 40 $this->assertEquals( '', wp_get_shortlink( 0 ) ); 41 $this->assertEquals( '', wp_get_shortlink() ); 42 43 $GLOBALS['post'] = get_post( $post_id ); 44 45 // Global post is set 46 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0, 'post' ) ); 47 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0 ) ); 48 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink() ); 49 50 // Not the global post 51 $this->assertEquals( get_permalink( $post_id2 ), wp_get_shortlink( $post_id2, 'post' ) ); 52 53 unset( $GLOBALS['post'] ); 54 55 // Global post is not set, once again 56 $this->assertEquals( '', wp_get_shortlink( 0, 'post' ) ); 57 $this->assertEquals( '', wp_get_shortlink( 0 ) ); 58 $this->assertEquals( '', wp_get_shortlink() ); 59 60 global $wp_rewrite; 61 $wp_rewrite->permalink_structure = ''; 62 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 63 $wp_rewrite->flush_rules(); 64 65 // With a permalink structure set, get_permalink() will no longer match. 66 $this->assertNotEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) ); 67 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); 68 69 // Global post and permalink structure are set 70 $GLOBALS['post'] = get_post( $post_id ); 71 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0, 'post' ) ); 72 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) ); 73 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink() ); 74 75 $wp_rewrite->set_permalink_structure( '' ); 76 $wp_rewrite->flush_rules(); 77 } 78 79 function test_wp_get_shortlink_with_page() { 80 $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 81 82 // Basic case 83 // Don't test against get_permalink() since it uses ?page_id= for pages. 84 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); 85 86 global $wp_rewrite; 87 $wp_rewrite->permalink_structure = ''; 88 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 89 $wp_rewrite->flush_rules(); 90 91 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); 92 93 $wp_rewrite->set_permalink_structure( '' ); 94 $wp_rewrite->flush_rules(); 95 } 96 30 97 }
Note: See TracChangeset
for help on using the changeset viewer.