Changeset 34946
- Timestamp:
- 10/08/2015 05:27:05 PM (9 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-rewrite.php
r34944 r34946 1542 1542 1543 1543 /** 1544 * Adds a straight rewrite rule.1545 * 1546 * Any value in the $after parameter that isn't 'bottom' will be placed at1547 * 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. 1548 1548 * 1549 1549 * @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 array1555 * 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 ) ) { 1560 1560 $external = false; 1561 $ redirect = add_query_arg( $redirect, 'index.php' );1561 $query = add_query_arg( $query, 'index.php' ); 1562 1562 } 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 ); 1565 1565 1566 1566 $external = $front != $this->index; 1567 1567 } 1568 1568 1569 // "external" = it doesn't redirectto index.php1569 // "external" = it doesn't correspond to index.php 1570 1570 if ( $external ) { 1571 $this->add_external_rule( $regex, $ redirect);1571 $this->add_external_rule( $regex, $query ); 1572 1572 } else { 1573 1573 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 ) ); 1575 1575 } 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 ) ); 1577 1577 } 1578 1578 } … … 1580 1580 1581 1581 /** 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. 1585 1583 * 1586 1584 * @since 2.1.0 1587 1585 * @access public 1588 1586 * 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; 1594 1592 } 1595 1593 -
trunk/src/wp-includes/rewrite-functions.php
r34890 r34946 8 8 9 9 /** 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. 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 * 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 */ 25 function add_rewrite_rule( $regex, $query, $after = 'bottom' ) { 26 global $wp_rewrite; 27 28 $wp_rewrite->add_rule( $regex, $query, $after ); 26 29 } 27 30
Note: See TracChangeset
for help on using the changeset viewer.