Changeset 10402 for branches/2.4/src/bp-core/bp-core-filters.php
- Timestamp:
- 12/13/2015 04:45:43 PM (10 years ago)
- File:
-
- 1 edited
-
branches/2.4/src/bp-core/bp-core-filters.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/2.4/src/bp-core/bp-core-filters.php
r10276 r10402 661 661 */ 662 662 function bp_modify_page_title( $title = '', $sep = '»', $seplocation = 'right' ) { 663 global $bp, $paged, $page, $_wp_theme_features; 664 665 // If this is not a BP page, just return the title produced by WP 666 if ( bp_is_blog_page() ) { 663 global $paged, $page, $_wp_theme_features; 664 665 // Get the BuddyPress title parts 666 $bp_title_parts = bp_get_title_parts( $seplocation ); 667 668 // If not set, simply return the original title 669 if ( ! $bp_title_parts ) { 667 670 return $title; 668 }669 670 // If this is a 404, let WordPress handle it671 if ( is_404() ) {672 return $title;673 }674 675 // If this is the front page of the site, return WP's title676 if ( is_front_page() || is_home() ) {677 return $title;678 }679 680 // Return WP's title if not a BuddyPress page681 if ( ! is_buddypress() ) {682 return $title;683 }684 685 // Setup an empty title parts array686 $title_parts = array();687 688 // Is there a displayed user, and do they have a name?689 $displayed_user_name = bp_get_displayed_user_fullname();690 691 // Displayed user692 if ( ! empty( $displayed_user_name ) && ! is_404() ) {693 694 // Get the component's ID to try and get its name695 $component_id = $component_name = bp_current_component();696 697 // Set empty subnav name698 $component_subnav_name = '';699 700 // Use the component nav name701 if ( ! empty( $bp->bp_nav[$component_id] ) ) {702 $component_name = _bp_strip_spans_from_title( $bp->bp_nav[ $component_id ]['name'] );703 704 // Fall back on the component ID705 } elseif ( ! empty( $bp->{$component_id}->id ) ) {706 $component_name = ucwords( $bp->{$component_id}->id );707 }708 709 // Append action name if we're on a member component sub-page710 if ( ! empty( $bp->bp_options_nav[ $component_id ] ) && ! empty( $bp->canonical_stack['action'] ) ) {711 $component_subnav_name = wp_filter_object_list( $bp->bp_options_nav[ $component_id ], array( 'slug' => bp_current_action() ), 'and', 'name' );712 713 if ( ! empty( $component_subnav_name ) ) {714 $component_subnav_name = array_shift( $component_subnav_name );715 }716 }717 718 // If on the user profile's landing page, just use the fullname719 if ( bp_is_current_component( $bp->default_component ) && ( bp_get_requested_url() === bp_displayed_user_domain() ) ) {720 $title_parts[] = $displayed_user_name;721 722 // Use component name on member pages723 } else {724 $title_parts = array_merge( $title_parts, array_map( 'strip_tags', array(725 $displayed_user_name,726 $component_name,727 ) ) );728 729 // If we have a subnav name, add it separately for localization730 if ( ! empty( $component_subnav_name ) ) {731 $title_parts[] = strip_tags( $component_subnav_name );732 }733 }734 735 // A single group736 } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) {737 $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'] : '';738 $title_parts = array( $bp->bp_options_title, $subnav );739 740 // A single item from a component other than groups741 } elseif ( bp_is_single_item() ) {742 $title_parts = array( $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'] );743 744 // An index or directory745 } elseif ( bp_is_directory() ) {746 $current_component = bp_current_component();747 748 // No current component (when does this happen?)749 $title_parts = array( _x( 'Directory', 'component directory title', 'buddypress' ) );750 751 if ( ! empty( $current_component ) ) {752 $title_parts = array( bp_get_directory_title( $current_component ) );753 }754 755 // Sign up page756 } elseif ( bp_is_register_page() ) {757 $title_parts = array( __( 'Create an Account', 'buddypress' ) );758 759 // Activation page760 } elseif ( bp_is_activation_page() ) {761 $title_parts = array( __( 'Activate Your Account', 'buddypress' ) );762 763 // Group creation page764 } elseif ( bp_is_group_create() ) {765 $title_parts = array( __( 'Create a Group', 'buddypress' ) );766 767 // Blog creation page768 } elseif ( bp_is_create_blog() ) {769 $title_parts = array( __( 'Create a Site', 'buddypress' ) );770 }771 772 // Strip spans773 $title_parts = array_map( '_bp_strip_spans_from_title', $title_parts );774 775 // sep on right, so reverse the order776 if ( 'right' == $seplocation ) {777 $title_parts = array_reverse( $title_parts );778 671 } 779 672 … … 791 684 // Append the site title to title parts if theme supports title tag 792 685 if ( true === $title_tag_compatibility ) { 793 $ title_parts[] = $blogname;794 795 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {796 $ title_parts[] = sprintf( __( 'Page %s', 'buddypress' ), max( $paged, $page ) );686 $bp_title_parts['site'] = $blogname; 687 688 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() && ! bp_is_single_activity() ) { 689 $bp_title_parts['page'] = sprintf( __( 'Page %s', 'buddypress' ), max( $paged, $page ) ); 797 690 } 798 691 } … … 802 695 803 696 // Join the parts together 804 $new_title = join( $prefix, array_filter( $ title_parts ) );697 $new_title = join( $prefix, array_filter( $bp_title_parts ) ); 805 698 806 699 // Append the prefix for pre `title-tag` compatibility … … 810 703 811 704 /** 812 * Filters the page title for BuddyPress pages.705 * Filters the older 'wp_title' page title for BuddyPress pages. 813 706 * 814 707 * @since 1.5.0 … … 821 714 return apply_filters( 'bp_modify_page_title', $new_title, $title, $sep, $seplocation ); 822 715 } 823 add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 ); 824 add_filter( 'bp_modify_page_title', 'wptexturize' ); 825 add_filter( 'bp_modify_page_title', 'convert_chars' ); 826 add_filter( 'bp_modify_page_title', 'esc_html' ); 827 828 /** 829 * Strip span tags out of title part strings. 830 * 831 * This is a temporary function for compatibility with WordPress versions 832 * less than 4.0, and should be removed at a later date. 833 * 834 * @param string $title_part 835 * 836 * @return string 837 */ 838 function _bp_strip_spans_from_title( $title_part = '' ) { 839 $title = $title_part; 840 $span = strpos( $title, '<span' ); 841 if ( false !== $span ) { 842 $title = substr( $title, 0, $span - 1 ); 843 } 844 return $title; 845 } 716 add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 ); 717 add_filter( 'bp_modify_page_title', 'wptexturize' ); 718 add_filter( 'bp_modify_page_title', 'convert_chars' ); 719 add_filter( 'bp_modify_page_title', 'esc_html' ); 720 721 /** 722 * Filter the document title for BuddyPress pages. 723 * 724 * @since 2.4.3 725 * 726 * @param array $title The WordPress document title parts 727 * @return array the unchanged title parts or the BuddyPress ones 728 */ 729 function bp_modify_document_title_parts( $title = array() ) { 730 // Get the BuddyPress title parts 731 $bp_title_parts = bp_get_title_parts(); 732 733 // If not set, simply return the original title 734 if ( ! $bp_title_parts ) { 735 return $title; 736 } 737 738 // Get the separator used by wp_get_document_title() 739 $sep = apply_filters( 'document_title_separator', '-' ); 740 741 // Build the BuddyPress portion of the title. 742 // We don't need to sanitize this as WordPress will take care of it. 743 $bp_title = array( 744 'title' => join( " $sep ", $bp_title_parts ) 745 ); 746 747 // Add the pagination number if needed (not sure if this is necessary). 748 if ( isset( $title['page'] ) && ! bp_is_single_activity() ) { 749 $bp_title['page'] = $title['page']; 750 } 751 752 // Add the sitename if needed. 753 if ( isset( $title['site'] ) ) { 754 $bp_title['site'] = $title['site']; 755 } 756 757 /** 758 * Filters BuddyPress title parts that will be used into the document title. 759 * 760 * @since 2.4.3 761 * 762 * @param array $bp_title The BuddyPress page title parts. 763 * @param array $title The original WordPress title parts. 764 */ 765 return apply_filters( 'bp_modify_document_title_parts', $bp_title, $title ); 766 } 767 add_filter( 'document_title_parts', 'bp_modify_document_title_parts', 20, 1 ); 846 768 847 769 /**
Note: See TracChangeset
for help on using the changeset viewer.