Changeset 47878
- Timestamp:
- 06/01/2020 06:47:41 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/canonical.php
r47855 r47878 836 836 global $wpdb; 837 837 838 /** 839 * Filters whether to do redirect guess of 404 requests. 840 * 841 * Returning a false value from the filter will disable redirect guess 404 permalink. 842 * and return early. 843 * 844 * @since 5.5.0 845 * 846 * @param bool $do_redirect_guess Whether to do redirect guess 404 permalink. Default true. 847 */ 848 if ( false === apply_filters( 'do_redirect_guess_404_permalink', true ) ) { 849 return false; 850 } 851 852 /** 853 * Filters whether to short-circuit redirect guess of 404 requests. 854 * 855 * Return a non-false value from the filter will short-circuit the handling and return early. 856 * 857 * @since 5.5.0 858 * 859 * @param bool $pre Whether to short-circuit redirect guess 404 permalink. Default null. 860 */ 861 $pre = apply_filters( 'pre_redirect_guess_404_permalink', null ); 862 if ( null !== $pre ) { 863 return $pre; 864 } 865 838 866 if ( get_query_var( 'name' ) ) { 839 $where = $wpdb->prepare( 'post_name LIKE %s', $wpdb->esc_like( get_query_var( 'name' ) ) . '%' ); 867 868 /** 869 * Filters whether to do a strict or loose guess. 870 * 871 * Returning true value from the filter will guess redirect only exact post_name matches. 872 * 873 * @since 5.5.0 874 * 875 * @param bool $strict_guess Whether to do a strict/exact guess. Default false. 876 */ 877 $strict_guess = apply_filters( 'strict_redirect_guess_404_permalink', false ); 878 879 if ( $strict_guess ) { 880 $where = $wpdb->prepare( 'post_name = %s', get_query_var( 'name' ) ); 881 } else { 882 $where = $wpdb->prepare( 'post_name LIKE %s', $wpdb->esc_like( get_query_var( 'name' ) ) . '%' ); 883 } 840 884 841 885 // If any of post_type, year, monthnum, or day are set, use them to refine the query. -
trunk/tests/phpunit/tests/canonical.php
r47781 r47878 232 232 233 233 /** 234 * @ticket 16557 235 */ 236 public function test_do_redirect_guess_404_permalink() { 237 // Test disable do_redirect_guess_404_permalink(). 238 add_filter( 'do_redirect_guess_404_permalink', '__return_false' ); 239 $this->go_to( '/child-page-1' ); 240 $this->assertFalse( redirect_guess_404_permalink() ); 241 } 242 243 /** 244 * @ticket 16557 245 */ 246 public function test_pre_redirect_guess_404_permalink() { 247 // Test short-circuit filter. 248 add_filter( 249 'pre_redirect_guess_404_permalink', 250 function() { 251 return 'wp'; 252 } 253 ); 254 $this->go_to( '/child-page-1' ); 255 $this->assertEquals( 'wp', redirect_guess_404_permalink() ); 256 } 257 258 /** 259 * @ticket 16557 260 */ 261 public function test_strict_redirect_guess_404_permalink() { 262 $post = self::factory()->post->create( 263 array( 264 'post_title' => 'strict-redirect-guess-404-permalink', 265 ) 266 ); 267 268 $this->go_to( 'strict-redirect' ); 269 270 // Test default 'non-strict' redirect guess. 271 $this->assertEquals( get_permalink( $post ), redirect_guess_404_permalink() ); 272 273 // Test 'strict' redirect guess. 274 add_filter( 'strict_redirect_guess_404_permalink', '__return_true' ); 275 $this->assertFalse( redirect_guess_404_permalink() ); 276 } 277 278 /** 234 279 * @ticket 43745 235 280 */
Note: See TracChangeset
for help on using the changeset viewer.