Make WordPress Core


Ignore:
Timestamp:
09/30/2015 01:10:03 AM (9 years ago)
Author:
wonderboymusic
Message:

Rewrite: allow add_rewrite_rule|WP_Rewrite::add_rule() to accept an associative array for the value of $redirect instead of requiring a query string.

Adds unit tests.

Props scribu, DrewAPicture.
Fixes #16840.

File:
1 edited

Legend:

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

    r34566 r34708  
    88
    99/**
    10  * Add a straight rewrite rule.
     10 * Adds a straight rewrite rule.
    1111 *
    1212 * @since 2.1.0
    13  *
    14  * @global WP_Rewrite $wp_rewrite
    15  *
    16  * @param string $regex    Regular Expression to match request against.
    17  * @param string $redirect Page to redirect to.
    18  * @param string $after    Optional, default is 'bottom'. Where to add rule, can also be 'top'.
    19  */
    20 function add_rewrite_rule($regex, $redirect, $after = 'bottom') {
    21     global $wp_rewrite;
    22     $wp_rewrite->add_rule($regex, $redirect, $after);
     13 * @since 4.4.0 Array support was added to the `$redirect` parameter.
     14 *
     15 * @global WP_Rewrite $wp_rewrite WordPress Rewrite Component.
     16 *
     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, default is 'bottom'. Where to add rule, can also be 'top'.
     20 */
     21function add_rewrite_rule( $regex, $redirect, $after = 'bottom' ) {
     22    global $wp_rewrite;
     23
     24    $wp_rewrite->add_rule( $regex, $redirect, $after );
    2325}
    2426
Note: See TracChangeset for help on using the changeset viewer.