Changeset 10403 for trunk/src/bp-core/bp-core-filters.php
- Timestamp:
- 12/13/2015 04:54:45 PM (10 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-core/bp-core-filters.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-filters.php
r10356 r10403 650 650 */ 651 651 function bp_modify_page_title( $title = '', $sep = '»', $seplocation = 'right' ) { 652 global $bp, $paged, $page, $_wp_theme_features; 653 654 // If this is not a BP page, just return the title produced by WP. 655 if ( bp_is_blog_page() ) { 652 global $paged, $page, $_wp_theme_features; 653 654 // Get the BuddyPress title parts 655 $bp_title_parts = bp_get_title_parts( $seplocation ); 656 657 // If not set, simply return the original title 658 if ( ! $bp_title_parts ) { 656 659 return $title; 657 }658 659 // If this is a 404, let WordPress handle it.660 if ( is_404() ) {661 return $title;662 }663 664 // If this is the front page of the site, return WP's title.665 if ( is_front_page() || is_home() ) {666 return $title;667 }668 669 // Return WP's title if not a BuddyPress page.670 if ( ! is_buddypress() ) {671 return $title;672 }673 674 // Setup an empty title parts array.675 $title_parts = array();676 677 // Is there a displayed user, and do they have a name?678 $displayed_user_name = bp_get_displayed_user_fullname();679 680 // Displayed user.681 if ( ! empty( $displayed_user_name ) && ! is_404() ) {682 683 // Get the component's ID to try and get its name.684 $component_id = $component_name = bp_current_component();685 686 // Set empty subnav name.687 $component_subnav_name = '';688 689 // Use the component nav name.690 if ( ! empty( $bp->bp_nav[$component_id] ) ) {691 $component_name = _bp_strip_spans_from_title( $bp->bp_nav[ $component_id ]['name'] );692 693 // Fall back on the component ID.694 } elseif ( ! empty( $bp->{$component_id}->id ) ) {695 $component_name = ucwords( $bp->{$component_id}->id );696 }697 698 // Append action name if we're on a member component sub-page.699 if ( ! empty( $bp->bp_options_nav[ $component_id ] ) && ! empty( $bp->canonical_stack['action'] ) ) {700 $component_subnav_name = wp_filter_object_list( $bp->bp_options_nav[ $component_id ], array( 'slug' => bp_current_action() ), 'and', 'name' );701 702 if ( ! empty( $component_subnav_name ) ) {703 $component_subnav_name = array_shift( $component_subnav_name );704 }705 }706 707 // If on the user profile's landing page, just use the fullname.708 if ( bp_is_current_component( $bp->default_component ) && ( bp_get_requested_url() === bp_displayed_user_domain() ) ) {709 $title_parts[] = $displayed_user_name;710 711 // Use component name on member pages.712 } else {713 $title_parts = array_merge( $title_parts, array_map( 'strip_tags', array(714 $displayed_user_name,715 $component_name,716 ) ) );717 718 // If we have a subnav name, add it separately for localization.719 if ( ! empty( $component_subnav_name ) ) {720 $title_parts[] = strip_tags( $component_subnav_name );721 }722 }723 724 // A single group.725 } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) {726 $subnav = isset( $bp->bp_options_nav[ $bp->groups->current_group->slug ][ bp_current_action() ]['name'] ) ? $bp->bp_options_nav[ $bp->groups->current_group->slug ][ bp_current_action() ]['name'] : '';727 $title_parts = array( $bp->bp_options_title, $subnav );728 729 // A single item from a component other than groups.730 } elseif ( bp_is_single_item() ) {731 $title_parts = array( $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'] );732 733 // An index or directory.734 } elseif ( bp_is_directory() ) {735 $current_component = bp_current_component();736 737 // No current component (when does this happen?).738 $title_parts = array( _x( 'Directory', 'component directory title', 'buddypress' ) );739 740 if ( ! empty( $current_component ) ) {741 $title_parts = array( bp_get_directory_title( $current_component ) );742 }743 744 // Sign up page.745 } elseif ( bp_is_register_page() ) {746 $title_parts = array( __( 'Create an Account', 'buddypress' ) );747 748 // Activation page.749 } elseif ( bp_is_activation_page() ) {750 $title_parts = array( __( 'Activate Your Account', 'buddypress' ) );751 752 // Group creation page.753 } elseif ( bp_is_group_create() ) {754 $title_parts = array( __( 'Create a Group', 'buddypress' ) );755 756 // Blog creation page.757 } elseif ( bp_is_create_blog() ) {758 $title_parts = array( __( 'Create a Site', 'buddypress' ) );759 }760 761 // Strip spans.762 $title_parts = array_map( '_bp_strip_spans_from_title', $title_parts );763 764 // Sep on right, so reverse the order.765 if ( 'right' == $seplocation ) {766 $title_parts = array_reverse( $title_parts );767 660 } 768 661 … … 778 671 $title_tag_compatibility = (bool) ( ! empty( $_wp_theme_features['title-tag'] ) || strstr( $title, $blogname ) ); 779 672 780 // Append the site title to title parts if theme supports title tag .673 // Append the site title to title parts if theme supports title tag 781 674 if ( true === $title_tag_compatibility ) { 782 $ title_parts[] = $blogname;783 784 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {785 $ title_parts[] = sprintf( __( 'Page %s', 'buddypress' ), max( $paged, $page ) );675 $bp_title_parts['site'] = $blogname; 676 677 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() && ! bp_is_single_activity() ) { 678 $bp_title_parts['page'] = sprintf( __( 'Page %s', 'buddypress' ), max( $paged, $page ) ); 786 679 } 787 680 } 788 681 789 // Pad the separator with 1 space on each side .682 // Pad the separator with 1 space on each side 790 683 $prefix = str_pad( $sep, strlen( $sep ) + 2, ' ', STR_PAD_BOTH ); 791 684 792 // Join the parts together .793 $new_title = join( $prefix, array_filter( $ title_parts ) );794 795 // Append the prefix for pre `title-tag` compatibility .685 // Join the parts together 686 $new_title = join( $prefix, array_filter( $bp_title_parts ) ); 687 688 // Append the prefix for pre `title-tag` compatibility 796 689 if ( false === $title_tag_compatibility ) { 797 690 $new_title = $new_title . $prefix; … … 799 692 800 693 /** 801 * Filters the page title for BuddyPress pages.694 * Filters the older 'wp_title' page title for BuddyPress pages. 802 695 * 803 696 * @since 1.5.0 … … 810 703 return apply_filters( 'bp_modify_page_title', $new_title, $title, $sep, $seplocation ); 811 704 } 812 add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 ); 813 add_filter( 'bp_modify_page_title', 'wptexturize' ); 814 add_filter( 'bp_modify_page_title', 'convert_chars' ); 815 add_filter( 'bp_modify_page_title', 'esc_html' ); 816 817 /** 818 * Strip span tags out of title part strings. 819 * 820 * This is a temporary function for compatibility with WordPress versions 821 * less than 4.0, and should be removed at a later date. 822 * 823 * @param string $title_part Title part to clean up. 824 * @return string 825 */ 826 function _bp_strip_spans_from_title( $title_part = '' ) { 827 $title = $title_part; 828 $span = strpos( $title, '<span' ); 829 if ( false !== $span ) { 830 $title = substr( $title, 0, $span - 1 ); 831 } 832 return $title; 833 } 705 add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 ); 706 add_filter( 'bp_modify_page_title', 'wptexturize' ); 707 add_filter( 'bp_modify_page_title', 'convert_chars' ); 708 add_filter( 'bp_modify_page_title', 'esc_html' ); 709 710 /** 711 * Filter the document title for BuddyPress pages. 712 * 713 * @since 2.4.3 714 * 715 * @param array $title The WordPress document title parts 716 * @return array the unchanged title parts or the BuddyPress ones 717 */ 718 function bp_modify_document_title_parts( $title = array() ) { 719 // Get the BuddyPress title parts 720 $bp_title_parts = bp_get_title_parts(); 721 722 // If not set, simply return the original title 723 if ( ! $bp_title_parts ) { 724 return $title; 725 } 726 727 // Get the separator used by wp_get_document_title() 728 $sep = apply_filters( 'document_title_separator', '-' ); 729 730 // Build the BuddyPress portion of the title. 731 // We don't need to sanitize this as WordPress will take care of it. 732 $bp_title = array( 733 'title' => join( " $sep ", $bp_title_parts ) 734 ); 735 736 // Add the pagination number if needed (not sure if this is necessary). 737 if ( isset( $title['page'] ) && ! bp_is_single_activity() ) { 738 $bp_title['page'] = $title['page']; 739 } 740 741 // Add the sitename if needed. 742 if ( isset( $title['site'] ) ) { 743 $bp_title['site'] = $title['site']; 744 } 745 746 /** 747 * Filters BuddyPress title parts that will be used into the document title. 748 * 749 * @since 2.4.3 750 * 751 * @param array $bp_title The BuddyPress page title parts. 752 * @param array $title The original WordPress title parts. 753 */ 754 return apply_filters( 'bp_modify_document_title_parts', $bp_title, $title ); 755 } 756 add_filter( 'document_title_parts', 'bp_modify_document_title_parts', 20, 1 ); 834 757 835 758 /**
Note: See TracChangeset
for help on using the changeset viewer.