WordPress.org

Make WordPress Core

Ticket #16557: 16557.short-circuit-and-strict-filters.diff

File 16557.short-circuit-and-strict-filters.diff, 1.9 KB (added by apedog, 21 months ago)

New patch off current master

  • wp-includes/canonical.php

    diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php
    index ecacb59a60..4f9b1b5b73 100644
    a b function strip_fragment_from_url( $url ) { 
    684684function redirect_guess_404_permalink() {
    685685        global $wpdb;
    686686
     687        /**
     688         * Filters whether to do redirect guess of 404 requests.
     689         *
     690         * Returning a false value from the filter will disable redirect guess 404 permalink
     691         * and return early.
     692         *
     693         * @since x.x.x
     694         *
     695         * @param bool     $do_redirect_guess  Whether to do redirect guess 404 permalink. Default true.
     696         */
     697        if ( false === apply_filters( 'do_redirect_guess_404_permalink', true ) ) {
     698                return false;
     699        }
     700
     701        /**
     702         * Filters whether to short-circuit redirect guess of 404 requests.
     703         *
     704         * Returning a non-false value from the filter will short-circuit the handling
     705         * and return early.
     706         *
     707         * @since x.x.x
     708         *
     709         * @param bool     $pre  Whether to short-circuit redirect guess 404 permalink. Default null.
     710         */
     711        $pre = apply_filters( 'pre_redirect_guess_404_permalink', null );
     712        if ( null !== $pre ){
     713                return $pre;
     714        }
     715
    687716        if ( get_query_var( 'name' ) ) {
    688                 $where = $wpdb->prepare( 'post_name LIKE %s', $wpdb->esc_like( get_query_var( 'name' ) ) . '%' );
     717
     718                /**
     719                 * Filters whether to do a strict or loose guess.
     720                 *
     721                 * Returning true value from the filter will guess redirect only exact post_name matches.
     722                 *
     723                 * @since x.x.x
     724                 *
     725                 * @param bool     $strict_guess  Whether to do a strict/exact guess. Default false.
     726                 */
     727                $strict_guess = apply_filters( 'strict_redirect_guess_404_permalink', false );
     728                if ( $strict_guess ){
     729                        $where = $wpdb->prepare( 'post_name = %s', get_query_var( 'name' ) );
     730                }else{
     731                        $where = $wpdb->prepare( 'post_name LIKE %s', $wpdb->esc_like( get_query_var( 'name' ) ) . '%' );
     732                }
     733               
    689734
    690735                // if any of post_type, year, monthnum, or day are set, use them to refine the query
    691736                if ( get_query_var( 'post_type' ) ) {