Changeset 57645
- Timestamp:
- 02/16/2024 11:32:48 PM (5 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/canonical.php
r57357 r57645 950 950 951 951 if ( get_query_var( 'name' ) ) { 952 953 954 952 955 /** 953 956 * Filters whether to perform a strict guess for a 404 redirect. … … 970 973 if ( get_query_var( 'post_type' ) ) { 971 974 if ( is_array( get_query_var( 'post_type' ) ) ) { 975 976 977 978 972 979 $where .= " AND post_type IN ('" . join( "', '", esc_sql( get_query_var( 'post_type' ) ) ) . "')"; 973 980 } else { 981 982 983 974 984 $where .= $wpdb->prepare( ' AND post_type = %s', get_query_var( 'post_type' ) ); 975 985 } 976 986 } else { 977 $where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true )) ) . "')";987 $where .= " AND post_type IN ('" . implode( "', '", ) ) . "')"; 978 988 } 979 989 … … 988 998 } 989 999 990 $publicly_viewable_statuses = array_filter( get_post_stati(), 'is_post_status_viewable' );991 1000 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared 992 1001 $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status IN ('" . implode( "', '", esc_sql( $publicly_viewable_statuses ) ) . "')" ); -
trunk/tests/phpunit/tests/canonical.php
r57357 r57645 11 11 class Tests_Canonical extends WP_Canonical_UnitTestCase { 12 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 13 28 public function set_up() { 14 29 parent::set_up(); 15 30 wp_set_current_user( self::$author_id ); 31 16 32 17 33 update_option( 'wp_attachment_pages_enabled', 1 ); 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 18 52 } 19 53 … … 344 378 * 345 379 * @ticket 43056 346 */ 347 public function test_redirect_guess_404_permalink_post_types() { 348 /* 349 * Sample-page is intentionally missspelt as sample-pag to ensure 350 * the 404 post permalink guessing runs. 351 * 352 * Please do not correct the apparent typo. 353 */ 354 355 // String format post type. 356 $this->assertCanonical( '/?name=sample-pag&post_type=page', '/sample-page/' ); 357 // Array formatted post type or types. 358 $this->assertCanonical( '/?name=sample-pag&post_type[]=page', '/sample-page/' ); 359 $this->assertCanonical( '/?name=sample-pag&post_type[]=page&post_type[]=post', '/sample-page/' ); 380 * @ticket 59795 381 * 382 * @dataProvider data_redirect_guess_404_permalink_post_types 383 */ 384 public function test_redirect_guess_404_permalink_post_types( $original_url, $expected ) { 385 $this->assertCanonical( $original_url, $expected ); 386 } 387 388 /** 389 * Data provider for test_redirect_guess_404_permalink_post_types(). 390 * 391 * In the original URLs the post names are intentionally misspelled 392 * to test the redirection. 393 * 394 * Please do not correct the apparent typos. 395 * 396 * @return array[] 397 */ 398 public function data_redirect_guess_404_permalink_post_types() { 399 return array( 400 'single string formatted post type' => array( 401 'original_url' => '/?name=sample-pag&post_type=page', 402 'expected' => '/sample-page/', 403 ), 404 'single array formatted post type' => array( 405 'original_url' => '/?name=sample-pag&post_type[]=page', 406 'expected' => '/sample-page/', 407 ), 408 'multiple array formatted post type' => array( 409 'original_url' => '/?name=sample-pag&post_type[]=page&post_type[]=post', 410 'expected' => '/sample-page/', 411 ), 412 'do not redirect to private post type' => array( 413 'original_url' => '/?name=private-cpt-po&post_type[]=wp_tests_private', 414 'expected' => '/?name=private-cpt-po&post_type[]=wp_tests_private', 415 ), 416 ); 360 417 } 361 418
Note: See TracChangeset
for help on using the changeset viewer.