Make WordPress Core


Ignore:
Timestamp:
10/08/2015 05:27:05 PM (11 years ago)
Author:
johnbillion
Message:

Improve the parameter names and inline documentation for add_rewrite_rule(), WP_Rewrite::add_rule(), and WP_Rewrite::add_external_rule().

Fixes #34197

File:
1 edited

Legend:

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

    r34944 r34946  
    15421542
    15431543        /**
    1544          * Adds a straight rewrite rule.
    1545          *
    1546          * Any value in the $after parameter that isn't 'bottom' will be placed at
    1547          * the top of the rules.
     1544         * Adds a rewrite rule that transforms a URL structure to a set of query vars.
     1545         *
     1546         * Any value in the $after parameter that isn't 'bottom' will result in the rule
     1547         * being placed at the top of the rewrite rules.
    15481548         *
    15491549         * @since 2.1.0
    1550          * @since 4.4.0 Array support was added to the `$redirect` parameter.
    1551          * @access public
    1552          *
    1553          * @param string       $regex    Regular expression to match against request.
    1554          * @param string|array $redirect URL regex redirects to when regex matches request, or array
    1555          *                               of query vars and values.
    1556          * @param string       $after    Optional, default is bottom. Location to place rule.
    1557          */
    1558         public function add_rule( $regex, $redirect, $after = 'bottom' ) {
    1559                 if ( is_array( $redirect ) ) {
     1550         * @since 4.4.0 Array support was added to the `$query` parameter.
     1551         * @access public
     1552         *
     1553         * @param string       $regex Regular expression to match request against.
     1554         * @param string|array $query The corresponding query vars for this rewrite rule.
     1555         * @param string       $after Optional. Priority of the new rule. Accepts 'top'
     1556         *                            or 'bottom'. Default 'bottom'.
     1557         */
     1558        public function add_rule( $regex, $query, $after = 'bottom' ) {
     1559                if ( is_array( $query ) ) {
    15601560                        $external = false;
    1561                         $redirect = add_query_arg( $redirect, 'index.php' );
     1561                        $query = add_query_arg( $query, 'index.php' );
    15621562                } else {
    1563                         $index = false === strpos( $redirect, '?' ) ? strlen( $redirect ) : strpos( $redirect, '?' );
    1564                         $front = substr( $redirect, 0, $index );
     1563                        $index = false === strpos( $query, '?' ) ? strlen( $query ) : strpos( $query, '?' );
     1564                        $front = substr( $query, 0, $index );
    15651565
    15661566                        $external = $front != $this->index;
    15671567                }
    15681568
    1569                 // "external" = it doesn't redirect to index.php
     1569                // "external" = it doesn't correspond to index.php
    15701570                if ( $external ) {
    1571                         $this->add_external_rule( $regex, $redirect );
     1571                        $this->add_external_rule( $regex, $query );
    15721572                } else {
    15731573                        if ( 'bottom' == $after ) {
    1574                                 $this->extra_rules = array_merge( $this->extra_rules, array( $regex => $redirect ) );
     1574                                $this->extra_rules = array_merge( $this->extra_rules, array( $regex => $query ) );
    15751575                        } else {
    1576                                 $this->extra_rules_top = array_merge( $this->extra_rules_top, array( $regex => $redirect ) );
     1576                                $this->extra_rules_top = array_merge( $this->extra_rules_top, array( $regex => $query ) );
    15771577                        }
    15781578                }
    … …  
    15801580
    15811581        /**
    1582          * Adds a rule that doesn't redirect to index.php.
    1583          *
    1584          * Can redirect to any place.
     1582         * Adds a rewrite rule that doesn't correspond to index.php.
    15851583         *
    15861584         * @since 2.1.0
    15871585         * @access public
    15881586         *
    1589          * @param string $regex    Regular expression to match against request.
    1590          * @param string $redirect URL regex redirects to when regex matches request.
    1591          */
    1592         public function add_external_rule($regex, $redirect) {
    1593                 $this->non_wp_rules[$regex] = $redirect;
     1587         * @param string $regex Regular expression to match request against.
     1588         * @param string $query The corresponding query vars for this rewrite rule.
     1589         */
     1590        public function add_external_rule( $regex, $query ) {
     1591                $this->non_wp_rules[ $regex ] = $query;
    15941592        }
    15951593
Note: See TracChangeset for help on using the changeset viewer.