| 784 | | if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { |
| 785 | | $title_parts[] = sprintf( __( 'Page %s', 'buddypress' ), max( $paged, $page ) ); |
| | 786 | /** |
| | 787 | * Are we going to fake 'title-tag' theme functionality? |
| | 788 | * |
| | 789 | * @link https://buddypress.trac.wordpress.org/ticket/6107 |
| | 790 | * @see wp_title() |
| | 791 | */ |
| | 792 | $title_tag_compatibility = (bool) ( ! empty( $_wp_theme_features['title-tag'] ) || strstr( $title, $blogname ) ); |
| | 793 | |
| | 794 | // Append the site title to title parts if theme supports title tag |
| | 795 | if ( true === $title_tag_compatibility ) { |
| | 796 | $title_parts['site'] = $blogname; |
| | 797 | |
| | 798 | if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() && ! bp_is_single_activity() ) { |
| | 799 | $title_parts['page'] = sprintf( __( 'Page %s', 'buddypress' ), max( $paged, $page ) ); |
| | 800 | } |
| 789 | | // Pad the separator with 1 space on each side. |
| 790 | | $prefix = str_pad( $sep, strlen( $sep ) + 2, ' ', STR_PAD_BOTH ); |
| | 803 | // Pad the separator with 1 space on each side |
| | 804 | $prefix = str_pad( $sep, strlen( $sep ) + 2, ' ', STR_PAD_BOTH ); |
| | 805 | |
| | 806 | // Join the parts together |
| | 807 | $new_title = join( $prefix, array_filter( $title_parts ) ); |
| | 808 | |
| | 809 | // Append the prefix for pre `title-tag` compatibility |
| | 810 | if ( false === $title_tag_compatibility ) { |
| | 811 | $new_title = $new_title . $prefix; |
| | 812 | } |
| | 813 | |
| | 814 | /** |
| | 815 | * Filters the older 'wp_title' page title for BuddyPress pages. |
| | 816 | * |
| | 817 | * @since 1.5.0 |
| | 818 | * |
| | 819 | * @param string $new_title The BuddyPress page title. |
| | 820 | * @param string $title The original WordPress page title. |
| | 821 | * @param string $sep The title parts separator. |
| | 822 | * @param string $seplocation Location of the separator (left or right). |
| | 823 | */ |
| | 824 | return apply_filters( 'bp_modify_page_title', $new_title, $title, $sep, $seplocation ); |
| | 825 | |
| | 826 | // 'document_title_parts' - WP 4.4+ |
| | 827 | } else { |
| | 828 | // Get the separator used by wp_get_document_title() |
| | 829 | $sep = apply_filters( 'document_title_separator', '-' ); |
| | 830 | |
| | 831 | // Build the BuddyPress portion of the title. |
| | 832 | // We don't need to sanitize this as WordPress will take care of it. |
| | 833 | $bp_title = array( |
| | 834 | // @todo Perhaps re-apply the 'bp_modify_page_title' filter? The problem with that |
| | 835 | // is the sitename is included in the older filter; it isn't included here... |
| | 836 | 'title' => join( " $sep ", $title_parts ) |
| | 837 | ); |
| | 838 | |
| | 839 | // Add the pagination number if needed (not sure if this is necessary). |
| | 840 | if ( isset( $title['page'] ) && ! bp_is_single_activity() ) { |
| | 841 | $bp_title['page'] = $title['page']; |
| | 842 | } |
| 800 | | /** |
| 801 | | * Filters the page title for BuddyPress pages. |
| 802 | | * |
| 803 | | * @since 1.5.0 |
| 804 | | * |
| 805 | | * @param string $new_title The BuddyPress page title. |
| 806 | | * @param string $title The original WordPress page title. |
| 807 | | * @param string $sep The title parts separator. |
| 808 | | * @param string $seplocation Location of the separator (left or right). |
| 809 | | */ |
| 810 | | return apply_filters( 'bp_modify_page_title', $new_title, $title, $sep, $seplocation ); |
| | 853 | /** |
| | 854 | * Set up the document title after theme set up. |
| | 855 | * |
| | 856 | * We do logic here to determine if we should use the newer title-tag or the |
| | 857 | * older 'wp_title'. |
| | 858 | * |
| | 859 | * @since 2.4.1 |
| | 860 | */ |
| | 861 | function bp_setup_document_title() { |
| | 862 | // Use new WP 4.4 page title filter |
| | 863 | if ( function_exists( 'wp_get_document_title' ) && true === current_theme_supports( 'title-tag' ) ) { |
| | 864 | add_filter( 'document_title_parts', 'bp_modify_page_title', 20, 1 ); |
| | 865 | |
| | 866 | // Older 'wp_title' page title filter |
| | 867 | } else { |
| | 868 | add_filter( 'bp_modify_page_title', 'wptexturize' ); |
| | 869 | add_filter( 'bp_modify_page_title', 'convert_chars' ); |
| | 870 | add_filter( 'bp_modify_page_title', 'esc_html' ); |
| | 871 | |
| | 872 | add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 ); |
| | 873 | } |