Changeset 5425
- Timestamp:
- 11/30/2011 09:43:32 PM (13 years ago)
- Location:
- trunk/bp-core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-catchuri.php
r5412 r5425 509 509 add_action( 'login_form_bpnoaccess', 'bp_core_no_access_wp_login_error' ); 510 510 511 /** 512 * Canonicalizes BuddyPress URLs 513 * 514 * This function ensures that requests for BuddyPress content are always redirected to their 515 * most specific, trailingslashed versions. 516 * 517 * @since 1.6 518 * @see BP_Members_Component::setup_globals() where $bp->redirect_stack['base_url'] and 519 * ['component'] may be set 520 * @see bp_core_new_nav_item() where $bp->redirect_stack['action'] may be set 521 */ 522 function bp_redirect_canonical() { 523 global $bp; 524 525 if ( !bp_is_blog_page() && apply_filters( 'bp_do_redirect_canonical', true ) ) { 526 // build the URL in the address bar 527 $requested_url = is_ssl() ? 'https://' : 'http://'; 528 $requested_url .= $_SERVER['HTTP_HOST']; 529 $requested_url .= $_SERVER['REQUEST_URI']; 530 531 // Stash query args 532 $url_stack = explode( '?', $requested_url ); 533 $req_url_clean = $url_stack[0]; 534 535 // Process the redirect stack 536 if ( isset( $bp->redirect_stack['base_url'] ) ) { 537 $url_stack[0] = $bp->redirect_stack['base_url']; 538 } 539 540 if ( isset( $bp->redirect_stack['component'] ) ) { 541 $url_stack[0] = trailingslashit( $url_stack[0] . $bp->redirect_stack['component'] ); 542 } 543 544 if ( isset( $bp->redirect_stack['action'] ) ) { 545 $url_stack[0] = trailingslashit( $url_stack[0] . $bp->redirect_stack['action'] ); 546 } 547 548 if ( !empty( $bp->redirect_stack['action_variables'] ) ) { 549 foreach( (array)$bp->redirect_stack['action_variables'] as $av ) { 550 $url_stack[0] = trailingslashit( $url_stack[0] . $av ); 551 } 552 } 553 554 // Add trailing slash 555 $url_stack[0] = trailingslashit( $url_stack[0] ); 556 557 // Only redirect if we've assembled a URL different from the request 558 if ( $url_stack[0] !== $req_url_clean ) { 559 560 // Template messages have been deleted from the cookie by this point, so 561 // they must be readded before redirecting 562 if ( isset( $bp->template_message ) ) { 563 $message = stripslashes( $bp->template_message ); 564 $message_type = isset( $bp->template_message_type ) ? $bp->template_message_type : 'success'; 565 566 bp_core_add_message( $message, $message_type ); 567 } 568 569 bp_core_redirect( implode( '?', $url_stack ) ); 570 } 571 } 572 } 573 add_action( 'bp_core_pre_load_template', 'bp_redirect_canonical' ); 574 511 575 ?> -
trunk/bp-core/bp-core-functions.php
r5412 r5425 1602 1602 } 1603 1603 1604 /**1605 * Canonicalizes BuddyPress URLs1606 *1607 * This function ensures that requests for BuddyPress content are always redirected to their1608 * most specific, trailingslashed versions.1609 *1610 * @since 1.61611 * @see BP_Members_Component::setup_globals() where $bp->redirect_stack['base_url'] and1612 * ['component'] may be set1613 * @see bp_core_new_nav_item() where $bp->redirect_stack['action'] may be set1614 */1615 function bp_redirect_canonical() {1616 global $bp;1617 1618 if ( !bp_is_blog_page() && apply_filters( 'bp_do_redirect_canonical', true ) ) {1619 // build the URL in the address bar1620 $requested_url = is_ssl() ? 'https://' : 'http://';1621 $requested_url .= $_SERVER['HTTP_HOST'];1622 $requested_url .= $_SERVER['REQUEST_URI'];1623 1624 // Stash query args1625 $url_stack = explode( '?', $requested_url );1626 $req_url_clean = $url_stack[0];1627 1628 // Process the redirect stack1629 if ( isset( $bp->redirect_stack['base_url'] ) ) {1630 $url_stack[0] = $bp->redirect_stack['base_url'];1631 }1632 1633 if ( isset( $bp->redirect_stack['component'] ) ) {1634 $url_stack[0] = trailingslashit( $url_stack[0] . $bp->redirect_stack['component'] );1635 }1636 1637 if ( isset( $bp->redirect_stack['action'] ) ) {1638 $url_stack[0] = trailingslashit( $url_stack[0] . $bp->redirect_stack['action'] );1639 }1640 1641 if ( !empty( $bp->redirect_stack['action_variables'] ) ) {1642 foreach( (array)$bp->redirect_stack['action_variables'] as $av ) {1643 $url_stack[0] = trailingslashit( $url_stack[0] . $av );1644 }1645 }1646 1647 // Add trailing slash1648 $url_stack[0] = trailingslashit( $url_stack[0] );1649 1650 // Only redirect if we've assembled a URL different from the request1651 if ( $url_stack[0] !== $req_url_clean ) {1652 bp_core_redirect( implode( '?', $url_stack ) );1653 }1654 }1655 }1656 add_action( 'bp_core_pre_load_template', 'bp_redirect_canonical' );1657 1604 ?>
Note: See TracChangeset
for help on using the changeset viewer.