Make WordPress Core

Changeset 47878

Timestamp:
06/01/2020 06:47:41 PM (4 years ago)
Author:
whyisjake
Message:

Canonical: Add the ability to disable redirect_guess_404_permalink().

This also adds a few more filters to make adding redirects easier. Notably:

  1. do_redirect_guess_404_permalink
  2. pre_redirect_guess_404_permalink
  3. strict_redirect_guess_404_permalink

Fixes: #16557.
Props: msafi, nacin, simonwheatley, westi, mboynes, joostdevalk, Lex_Robinson, MikeSchinkel, haukep, paulschreiber, DrewAPicture, ravenswd, esemlabel, stevegibson12, martychc23, DrLightman, jivanpal, neonkowy, laternastudio, apedog, audrasjb, davidbaumwald, Confridin, donmhico, ryotsun.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r47855 r47878  
    836836    global $wpdb;
    837837
     838
     839
     840
     841
     842
     843
     844
     845
     846
     847
     848
     849
     850
     851
     852
     853
     854
     855
     856
     857
     858
     859
     860
     861
     862
     863
     864
     865
    838866    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        }
    840884
    841885        // 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  
    232232
    233233    /**
     234
     235
     236
     237
     238
     239
     240
     241
     242
     243
     244
     245
     246
     247
     248
     249
     250
     251
     252
     253
     254
     255
     256
     257
     258
     259
     260
     261
     262
     263
     264
     265
     266
     267
     268
     269
     270
     271
     272
     273
     274
     275
     276
     277
     278
    234279     * @ticket 43745
    235280     */
Note: See TracChangeset for help on using the changeset viewer.