Changeset 57310
- Timestamp:
- 01/19/2024 12:42:48 AM (7 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/canonical.php
r57232 r57310 551 551 552 552 if ( is_attachment() && ! get_option( 'wp_attachment_pages_enabled' ) ) { 553 $attachment_id = get_query_var( 'attachment_id' ); 554 555 if ( current_user_can( 'read_post', $attachment_id ) ) { 556 $redirect_url = wp_get_attachment_url( $attachment_id ); 557 558 $is_attachment_redirect = true; 559 } 553 $attachment_id = get_query_var( 'attachment_id' ); 554 $attachment_post = get_post( $attachment_id ); 555 $attachment_parent_id = $attachment_post ? $attachment_post->post_parent : 0; 556 557 /* 558 * If an attachment is attached to a post, it inherits the parent post's status. Fetch the 559 * parent post to check its status later. 560 */ 561 if ( $attachment_parent_id ) { 562 $redirect_obj = get_post( $attachment_parent_id ); 563 } 564 $redirect_url = wp_get_attachment_url( $attachment_id ); 565 566 $is_attachment_redirect = true; 560 567 } 561 568 -
trunk/tests/phpunit/tests/canonical.php
r57232 r57310 408 408 409 409 /** 410 411 410 412 * @ticket 57913 411 */ 412 public function test_canonical_attachment_page_redirect_with_option_disabled() { 413 * @ticket 59866 414 * 415 * @dataProvider data_canonical_attachment_page_redirect_with_option_disabled 416 */ 417 public function test_canonical_attachment_page_redirect_with_option_disabled( $expected, $user = null, $parent_post_status = '' ) { 413 418 add_filter( 'pre_option_wp_attachment_pages_enabled', '__return_false' ); 419 420 421 422 423 424 425 426 427 428 414 429 415 430 $filename = DIR_TESTDATA . '/images/test-image.jpg'; … … 417 432 $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); 418 433 419 $attachment_id = $this->_make_attachment( $upload ); 434 $attachment_id = $this->_make_attachment( $upload, $parent_post_id ); 435 $attachment_url = wp_get_attachment_url( $attachment_id ); 420 436 $attachment_page = get_permalink( $attachment_id ); 421 437 438 439 440 441 442 422 443 $this->go_to( $attachment_page ); 423 444 424 $url = redirect_canonical( $attachment_page, false ); 425 $expected = wp_get_attachment_url( $attachment_id ); 445 $url = redirect_canonical( $attachment_page, false ); 446 if ( is_string( $expected ) ) { 447 $expected = str_replace( '%%attachment_url%%', $attachment_url, $expected ); 448 } 426 449 427 450 $this->assertSame( $expected, $url ); 428 451 } 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 429 489 }
Note: See TracChangeset
for help on using the changeset viewer.