Changeset 49622
- Timestamp:
- 11/17/2020 03:27:07 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/canonical.php
r49563 r49622 78 78 $redirect = $original; 79 79 $redirect_url = false; 80 $redirect_obj = false;81 80 82 81 // Notice fixing. … … 104 103 if ( is_feed() && $post_id ) { 105 104 $redirect_url = get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) ); 106 $redirect_obj = get_post( $post_id );107 105 108 106 if ( $redirect_url ) { … … 129 127 130 128 $redirect_url = get_permalink( $post_id ); 131 $redirect_obj = get_post( $post_id );132 129 133 130 if ( $redirect_url ) { … … 154 151 if ( $post_type_obj->public && 'auto-draft' !== $redirect_post->post_status ) { 155 152 $redirect_url = get_permalink( $redirect_post ); 156 $redirect_obj = get_post( $redirect_post );157 153 158 154 $redirect['query'] = _remove_qs_args_if_not_in_url( … … 202 198 if ( $post_id ) { 203 199 $redirect_url = get_permalink( $post_id ); 204 $redirect_obj = get_post( $post_id );205 200 206 201 $redirect['path'] = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' ); … … 229 224 if ( ! empty( $_GET['attachment_id'] ) ) { 230 225 $redirect_url = get_attachment_link( get_query_var( 'attachment_id' ) ); 231 $redirect_obj = get_post( get_query_var( 'attachment_id' ) );232 226 233 227 if ( $redirect_url ) { … … 236 230 } else { 237 231 $redirect_url = get_attachment_link(); 238 $redirect_obj = get_post();239 232 } 240 233 } elseif ( is_single() && ! empty( $_GET['p'] ) && ! $redirect_url ) { 241 234 $redirect_url = get_permalink( get_query_var( 'p' ) ); 242 $redirect_obj = get_post( get_query_var( 'p' ) );243 235 244 236 if ( $redirect_url ) { … … 247 239 } elseif ( is_single() && ! empty( $_GET['name'] ) && ! $redirect_url ) { 248 240 $redirect_url = get_permalink( $wp_query->get_queried_object_id() ); 249 $redirect_obj = get_post( $wp_query->get_queried_object_id() );250 241 251 242 if ( $redirect_url ) { … … 254 245 } elseif ( is_page() && ! empty( $_GET['page_id'] ) && ! $redirect_url ) { 255 246 $redirect_url = get_permalink( get_query_var( 'page_id' ) ); 256 $redirect_obj = get_post( get_query_var( 'page_id' ) );257 247 258 248 if ( $redirect_url ) { … … 267 257 ) { 268 258 $redirect_url = get_permalink( get_option( 'page_for_posts' ) ); 269 $redirect_obj = get_post( get_option( 'page_for_posts' ) );270 259 271 260 if ( $redirect_url ) { … … 322 311 ) { 323 312 $redirect_url = get_author_posts_url( $author->ID, $author->user_nicename ); 324 $redirect_obj = $author;325 313 326 314 if ( $redirect_url ) { … … 398 386 ) { 399 387 $redirect_url = get_permalink( $wp_query->get_queried_object_id() ); 400 $redirect_obj = get_post( $wp_query->get_queried_object_id() );401 388 } 402 389 } … … 409 396 if ( ! $redirect_url ) { 410 397 $redirect_url = get_permalink( get_queried_object_id() ); 411 $redirect_obj = get_post( get_queried_object_id() );412 398 } 413 399 … … 755 741 } 756 742 757 if (758 $redirect_obj &&759 is_a( $redirect_obj, 'WP_Post' )760 ) {761 $post_status_obj = get_post_status_object( get_post_status( $redirect_obj ) );762 if (763 // Unviewable post types are never redirected.764 ! is_post_type_viewable( $redirect_obj->post_type ) ||765 // Internal or protected posts never redirect.766 $post_status_obj->internal ||767 $post_status_obj->protected ||768 (769 // Don't redirect a non-public post...770 ! $post_status_obj->public &&771 (772 // ...unless it's private and the logged in user has access.773 $post_status_obj->private &&774 ! current_user_can( 'read_post', $redirect_obj->ID )775 )776 )777 ) {778 $redirect_obj = false;779 $redirect_url = false;780 }781 }782 783 743 /** 784 744 * Filters the canonical redirect URL. -
trunk/src/wp-includes/link-template.php
r49563 r49622 165 165 $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename ); 166 166 167 if ( $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ), true ) ) { 167 if ( 168 $permalink && 169 ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future', 'trash' ), true ) 170 ) { 168 171 169 172 $category = ''; … … 419 422 if ( $parent && ! in_array( $parent->post_type, get_post_types(), true ) ) { 420 423 $parent = false; 421 }422 423 if ( $parent ) {424 $parent_status_obj = get_post_status_object( get_post_status( $post->post_parent ) );425 if (426 ! is_post_type_viewable( get_post_type( $post->post_parent ) ) ||427 $parent_status_obj->internal ||428 $parent_status_obj->protected429 ) {430 $parent = false;431 }432 424 } 433 425 -
trunk/tests/phpunit/tests/media.php
r49603 r49622 9 9 protected static $_sizes; 10 10 protected static $large_filename = 'test-image-large.jpg'; 11 protected static $post_ids; 11 12 12 13 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { … … 16 17 $filename = DIR_TESTDATA . '/images/' . self::$large_filename; 17 18 self::$large_id = $factory->attachment->create_upload_object( $filename ); 19 20 $post_statuses = array( 'publish', 'future', 'draft', 'auto-draft', 'trash' ); 21 foreach ( $post_statuses as $post_status ) { 22 $date = ''; 23 if ( 'future' === $post_status ) { 24 strftime( '%Y-%m-%d %H:%M:%S', strtotime( '+1 year' ) ); 25 } 26 27 self::$post_ids[ $post_status ] = $factory->post->create( 28 array( 29 'post_status' => 'trash' === $post_status ? 'publish' : $post_status, 30 'post_date' => $date, 31 'post_name' => "$post_status-post", 32 ) 33 ); 34 35 // Attachments without media. 36 self::$post_ids[ "$post_status-attachment" ] = $factory->attachment->create_object( 37 array( 38 'post_parent' => self::$post_ids[ $post_status ], 39 'post_status' => 'inherit', 40 'post_name' => "$post_status-attachment", 41 'post_date' => $date, 42 ) 43 ); 44 } 45 46 // Trash the trash post. 47 wp_trash_post( self::$post_ids['trash'] ); 18 48 } 19 49 … … 3024 3054 } 3025 3055 3056 /** 3057 * Test attachment permalinks based on parent post status. 3058 * 3059 * @dataProvider data_attachment_permalinks_based_on_parent_status 3060 * @ticket 51776 3061 * 3062 * @param string $post_key Post as keyed in the shared fixture array. 3063 * @param string $expected Expected result. 3064 * @param bool $expected_404 Whether the page is expected to return a 404 result. 3065 * 3066 */ 3067 function test_attachment_permalinks_based_on_parent_status( $post_key, $expected, $expected_404 ) { 3068 $this->set_permalink_structure( '/%postname%' ); 3069 $post = get_post( self::$post_ids[ $post_key ] ); 3070 3071 /* 3072 * The dataProvider runs before the fixures are set up, therefore the 3073 * post object IDs are placeholders that needs to be replaced. 3074 */ 3075 $expected = home_url( str_replace( '%ID%', $post->ID, $expected ) ); 3076 3077 $this->assertSame( $expected, get_permalink( $post ) ); 3078 $this->go_to( get_permalink( $post ) ); 3079 $this->assertSame( $expected_404, is_404() ); 3080 } 3081 3082 /** 3083 * Data provider for test_attachment_permalinks_based_on_parent_status(). 3084 * 3085 * @return array[] { 3086 * @type string $post_key Post as keyed in the shared fixture array. 3087 * @type string $expected Expected result. 3088 * $type bool $expected_404 Whether the page is expected to return a 404 result. 3089 * } 3090 */ 3091 function data_attachment_permalinks_based_on_parent_status() { 3092 return array( 3093 array( 'draft-attachment', '/?attachment_id=%ID%', true ), 3094 array( 'publish-attachment', '/publish-post/publish-attachment', false ), 3095 array( 'future-attachment', '/future-post/future-attachment', false ), 3096 array( 'auto-draft-attachment', '/?attachment_id=%ID%', true ), 3097 array( 'trash-attachment', '/?attachment_id=%ID%', false ), 3098 ); 3099 } 3026 3100 } 3027 3101
Note: See TracChangeset
for help on using the changeset viewer.