Make WordPress Core

Changeset 34946


Ignore:
Timestamp:
10/08/2015 05:27:05 PM (9 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

Location:
trunk/src/wp-includes
Files:
2 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
  • trunk/src/wp-includes/rewrite-functions.php

    r34890 r34946  
    88
    99/**
    10  * Adds a straight rewrite rule.
     10 * Adds 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'.
    21  */
    22 function add_rewrite_rule( $regex, $redirect, $after = 'bottom' ) {
    23     global $wp_rewrite;
    24 
    25     $wp_rewrite->add_rule( $regex, $redirect, $after );
     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'.
     24 */
     25function add_rewrite_rule( $regex, $query, $after = 'bottom' ) {
     26    global $wp_rewrite;
     27
     28    $wp_rewrite->add_rule( $regex, $query, $after );
    2629}
    2730
Note: See TracChangeset for help on using the changeset viewer.