Make WordPress Core

Ticket #34197: 34197.diff

File 34197.diff, 5.0 KB (added by johnbillion, 10 years ago)
  • src/wp-includes/rewrite-functions.php

     
    77 */
    88
    99/**
    10  * Adds a straight rewrite rule.
     10 * Add a rewrite rule that transforms a URL structure to a set of query vars.
     11 *
     12 * Any value in the $after parameter that isn't 'bottom' will result in the rule
     13 * being placed at the top of the rewrite rules.
    1114 *
    1215 * @since 2.1.0
    13  * @since 4.4.0 Array support was added to the `$redirect` parameter.
     16 * @since 4.4.0 Array support was added to the `$query` parameter.
    1417 *
    1518 * @global WP_Rewrite $wp_rewrite WordPress Rewrite Component.
    1619 *
    17  * @param string       $regex    Regular Expression to match request against.
    18  * @param string|array $redirect Page to redirect to, or array of query vars and values.
    19  * @param string       $after    Optional. Location where to insert the new rule. Accepts 'top',
    20  *                               or 'bottom'. Default 'bottom'.
     20 * @param string       $regex Regular expression to match request against.
     21 * @param string|array $query The corresponding query vars for this rewrite rule.
     22 * @param string       $after Optional. Priority of the new rule. Accepts 'top'
     23 *                            or 'bottom'. Default 'bottom'.
    2124 */
    22 function add_rewrite_rule( $regex, $redirect, $after = 'bottom' ) {
     25function add_rewrite_rule( $regex, $query, $after = 'bottom' ) {
    2326        global $wp_rewrite;
    2427
    25         $wp_rewrite->add_rule( $regex, $redirect, $after );
     28        $wp_rewrite->add_rule( $regex, $query, $after );
    2629}
    2730
    2831/**
  • src/wp-includes/class-wp-rewrite.php

     
    15221522        }
    15231523
    15241524        /**
    1525          * Add a straight rewrite rule.
     1525         * Add a rewrite rule that transforms a URL structure to a set of query vars.
    15261526         *
    1527          * Any value in the $after parameter that isn't 'bottom' will be placed at
    1528          * the top of the rules.
     1527         * Any value in the $after parameter that isn't 'bottom' will result in the rule
     1528         * being placed at the top of the rewrite rules.
    15291529         *
    15301530         * @since 2.1.0
    1531          * @since 4.4.0 Array support was added to the `$redirect` parameter.
     1531         * @since 4.4.0 Array support was added to the `$query` parameter.
    15321532         * @access public
    15331533         *
    1534          * @param string       $regex    Regular expression to match against request.
    1535          * @param string|array $redirect URL regex redirects to when regex matches request, or array
    1536          *                               of query vars and values.
    1537          * @param string       $after    Optional, default is bottom. Location to place rule.
     1534         * @param string       $regex Regular expression to match request against.
     1535         * @param string|array $query The corresponding query vars for this rewrite rule.
     1536         * @param string       $after Optional. Priority of the new rule. Accepts 'top'
     1537         *                            or 'bottom'. Default 'bottom'.
    15381538         */
    1539         public function add_rule( $regex, $redirect, $after = 'bottom' ) {
    1540                 if ( is_array( $redirect ) ) {
     1539        public function add_rule( $regex, $query, $after = 'bottom' ) {
     1540                if ( is_array( $query ) ) {
    15411541                        $external = false;
    1542                         $redirect = add_query_arg( $redirect, 'index.php' );
     1542                        $query = add_query_arg( $query, 'index.php' );
    15431543                } else {
    1544                         $index = false === strpos( $redirect, '?' ) ? strlen( $redirect ) : strpos( $redirect, '?' );
    1545                         $front = substr( $redirect, 0, $index );
     1544                        $index = false === strpos( $query, '?' ) ? strlen( $query ) : strpos( $query, '?' );
     1545                        $front = substr( $query, 0, $index );
    15461546
    15471547                        $external = $front != $this->index;
    15481548                }
    15491549
    1550                 // "external" = it doesn't redirect to index.php
     1550                // "external" = it doesn't correspond to index.php
    15511551                if ( $external ) {
    1552                         $this->add_external_rule( $regex, $redirect );
     1552                        $this->add_external_rule( $regex, $query );
    15531553                } else {
    15541554                        if ( 'bottom' == $after ) {
    1555                                 $this->extra_rules = array_merge( $this->extra_rules, array( $regex => $redirect ) );
     1555                                $this->extra_rules = array_merge( $this->extra_rules, array( $regex => $query ) );
    15561556                        } else {
    1557                                 $this->extra_rules_top = array_merge( $this->extra_rules_top, array( $regex => $redirect ) );
     1557                                $this->extra_rules_top = array_merge( $this->extra_rules_top, array( $regex => $query ) );
    15581558                        }
    15591559                }
    15601560        }
    15611561
    15621562        /**
    1563          * Add a rule that doesn't redirect to index.php.
    1564          *
    1565          * Can redirect to any place.
     1563         * Add a rewrite rule that doesn't correspond to index.php.
    15661564         *
    15671565         * @since 2.1.0
    15681566         * @access public
    15691567         *
    1570          * @param string $regex    Regular expression to match against request.
    1571          * @param string $redirect URL regex redirects to when regex matches request.
     1568         * @param string $regex Regular expression to match request against.
     1569         * @param string $query The corresponding query vars for this rewrite rule.
    15721570         */
    1573         public function add_external_rule($regex, $redirect) {
    1574                 $this->non_wp_rules[$regex] = $redirect;
     1571        public function add_external_rule( $regex, $query ) {
     1572                $this->non_wp_rules[ $regex ] = $query;
    15751573        }
    15761574
    15771575        /**