WordPress.org

Make WordPress Core

Ticket #29118: 29118.diff

File 29118.diff, 2.3 KB (added by ericlewis, 7 years ago)
  • src/wp-includes/rewrite.php

    diff --git a/src/wp-includes/rewrite.php b/src/wp-includes/rewrite.php
    index 67dade3..5aa8777 100644
    a b function add_rewrite_rule($regex, $redirect, $after = 'bottom') { 
    2222}
    2323
    2424/**
     25 * Remove a rewrite rule.
     26 *
     27 * @see WP_Rewrite::add_rule() for long description.
     28 * @since 4.0.0
     29 *
     30 * @param string $regex Regular Expression to match request against.
     31 * @param string $redirect Page to redirect to.
     32 * @param string $after Optional, default is 'bottom'. Where to add rule, can also be 'top'.
     33 */
     34function remove_rewrite_rule($regex, $redirect, $after = 'bottom') {
     35        global $wp_rewrite;
     36        $wp_rewrite->remove_rule($regex, $redirect, $after);
     37}
     38
     39/**
    2540 * Add a new rewrite tag (like %postname%).
    2641 *
    2742 * The $query parameter is optional. If it is omitted you must ensure that
    class WP_Rewrite { 
    19381953        }
    19391954
    19401955        /**
     1956         * Remove a rewrite rule.
     1957         *
     1958         * @since 4.0.0
     1959         * @access public
     1960         *
     1961         * @param string $regex Regular expression to match against request.
     1962         * @param string $redirect URL regex redirects to when regex matches request.
     1963         * @param string $after Optional, default is bottom. Location to place rule.
     1964         */
     1965        public function remove_rule($regex, $redirect, $after = 'bottom' ) {
     1966                $strpos_to_end_of_filename_of_regex = (strpos($redirect, '?') == false ? strlen($redirect) : strpos($redirect, '?'));
     1967                $front = substr($redirect, 0, $strpos_to_end_of_filename_of_regex);
     1968                if ( $front != $this->index ) { //it doesn't redirect to WP's index.php
     1969                        $this->remove_external_rule( $regex, $redirect );
     1970                } else {
     1971                        if ( 'bottom' == $after ) {
     1972                                unset( $this->extra_rules[$regex] );
     1973                        } else {
     1974                                unset( $this->extra_rules_top[$regex] );
     1975                        }
     1976                }
     1977        }
     1978
     1979        /**
    19411980         * Add a rule that doesn't redirect to index.php.
    19421981         *
    19431982         * Can redirect to any place.
    class WP_Rewrite { 
    19531992        }
    19541993
    19551994        /**
     1995         * Remove a rule that doesn't redirect to index.php.
     1996         *
     1997         * @since 4.0.0
     1998         * @access public
     1999         *
     2000         * @param string $regex Regular expression to match against request.
     2001         * @param string $redirect URL regex redirects to when regex matches request.
     2002         */
     2003        public function remove_external_rule( $regex, $redirect ) {
     2004                unset( $this->non_wp_rules[$regex] );
     2005        }
     2006
     2007        /**
    19562008         * Add an endpoint, like /trackback/.
    19572009         *
    19582010         * @since 2.1.0