Ticket #34197: 34197.diff
| File 34197.diff, 5.0 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/rewrite-functions.php
7 7 */ 8 8 9 9 /** 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. 11 14 * 12 15 * @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. 14 17 * 15 18 * @global WP_Rewrite $wp_rewrite WordPress Rewrite Component. 16 19 * 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'. 21 24 */ 22 function add_rewrite_rule( $regex, $ redirect, $after = 'bottom' ) {25 function add_rewrite_rule( $regex, $query, $after = 'bottom' ) { 23 26 global $wp_rewrite; 24 27 25 $wp_rewrite->add_rule( $regex, $ redirect, $after );28 $wp_rewrite->add_rule( $regex, $query, $after ); 26 29 } 27 30 28 31 /** -
src/wp-includes/class-wp-rewrite.php
1522 1522 } 1523 1523 1524 1524 /** 1525 * Add a straight rewrite rule.1525 * Add a rewrite rule that transforms a URL structure to a set of query vars. 1526 1526 * 1527 * Any value in the $after parameter that isn't 'bottom' will be placed at1528 * 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. 1529 1529 * 1530 1530 * @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. 1532 1532 * @access public 1533 1533 * 1534 * @param string $regex Regular expression to match against request.1535 * @param string|array $ redirect URL regex redirects to when regex matches request, or array1536 * 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'. 1538 1538 */ 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 ) ) { 1541 1541 $external = false; 1542 $ redirect = add_query_arg( $redirect, 'index.php' );1542 $query = add_query_arg( $query, 'index.php' ); 1543 1543 } 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 ); 1546 1546 1547 1547 $external = $front != $this->index; 1548 1548 } 1549 1549 1550 // "external" = it doesn't redirectto index.php1550 // "external" = it doesn't correspond to index.php 1551 1551 if ( $external ) { 1552 $this->add_external_rule( $regex, $ redirect);1552 $this->add_external_rule( $regex, $query ); 1553 1553 } else { 1554 1554 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 ) ); 1556 1556 } 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 ) ); 1558 1558 } 1559 1559 } 1560 1560 } 1561 1561 1562 1562 /** 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. 1566 1564 * 1567 1565 * @since 2.1.0 1568 1566 * @access public 1569 1567 * 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. 1572 1570 */ 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; 1575 1573 } 1576 1574 1577 1575 /**