Skip to:
Content

BuddyPress.org

Changeset 11080


Ignore:
Timestamp:
09/10/2016 02:25:50 PM (3 years ago)
Author:
hnla
Message:

Use WP page titles for BP directory pages headings

The activity directory heading historically used a hardcoded string for it's WP page title (post_title), with other component directories taking the name from the actual WP page title.

This commit brings all page headings for BP directories into parity, screens will look to the WP page(post_title) for the string to use, & BP sets a new series of initial default strings for new installs page creation.

An update routine is provided to ensure that no existing sites will suddenly see a new title string, if a previous install then update the post_title to older hardcoded strings (unless the page title changed by user), thereafter changes to the WP page title determine what BP will display.

Props boonebgorges, imath, dcavins, hnla
Fixes #6765

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/classes/class-bp-activity-component.php

    r11022 r11080  
    121121        );
    122122
     123        // Fetch the default directory title.
     124        $default_directory_titles = bp_core_get_directory_page_default_titles();
     125        $default_directory_title  = $default_directory_titles[$this->id];
     126
    123127        // All globals for activity component.
    124128        // Note that global_tables is included in this array.
     
    127131            'root_slug'             => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG,
    128132            'has_directory'         => true,
    129             'directory_title'       => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ),
     133            'directory_title'       => isset( $bp->pages->activity->title ) ? $bp->pages->activity->title : $default_directory_title,
    130134            'notification_callback' => 'bp_activity_format_notifications',
    131135            'search_string'         => __( 'Search Activity...', 'buddypress' ),
  • trunk/src/bp-blogs/classes/class-bp-blogs-component.php

    r10674 r11080  
    77 * information from those blogs to make querying blogs in bulk more performant.
    88 *
    9  * @package BuddyPress
     9    * @package BuddyPress
    1010 * @subpackage BlogsCore
    1111 * @since 1.5.0
     
    4545     * @since 1.5.0
    4646     *
    47      * @see BP_Component::setup_globals() for description of parameters.
     47        * @see BP_Component::setup_globals() for description of parameters.
    4848     *
    4949     * @param array $args See {@link BP_Component::setup_globals()}.
     
    6565            'blog' => $bp->table_prefix . 'bp_user_blogs_blogmeta',
    6666        );
     67
     68        // Fetch the default directory title.
     69        $default_directory_titles = bp_core_get_directory_page_default_titles();
     70        $default_directory_title  = $default_directory_titles[$this->id];
    6771
    6872        // All globals for blogs component.
     
    7175            'root_slug'             => isset( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG,
    7276            'has_directory'         => is_multisite(), // Non-multisite installs don't need a top-level Sites directory, since there's only one site.
    73             'directory_title'       => _x( 'Sites', 'component directory title', 'buddypress' ),
     77            'directory_title'       => isset( $bp->pages->blogs->title ) ? $bp->pages->blogs->title : $default_directory_title,
    7478            'notification_callback' => 'bp_blogs_format_notifications',
    7579            'search_string'         => __( 'Search sites...', 'buddypress' ),
     
    151155     * @param array $main_nav Optional. See BP_Component::setup_nav() for
    152156     *                        description.
    153      * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
     157        * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
    154158     *                        description.
    155159     */
  • trunk/src/bp-core/bp-core-functions.php

    r11048 r11080  
    631631    }
    632632
    633     $page_titles = array(
    634         'activity' => _x( 'Activity', 'Page title for the Activity directory.',       'buddypress' ),
    635         'groups'   => _x( 'Groups',   'Page title for the Groups directory.',         'buddypress' ),
    636         'blogs'    => _x( 'Sites',    'Page title for the Sites directory.',          'buddypress' ),
    637         'members'  => _x( 'Members',  'Page title for the Members directory.',        'buddypress' ),
    638         'activate' => _x( 'Activate', 'Page title for the user activation screen.',   'buddypress' ),
    639         'register' => _x( 'Register', 'Page title for the user registration screen.', 'buddypress' ),
    640     );
     633    $page_titles = bp_core_get_directory_page_default_titles();
    641634
    642635    $pages_to_create = array();
     
    692685        restore_current_blog();
    693686    }
     687}
     688
     689/**
     690 * Get the default page titles for BP directory pages.
     691 *
     692 * @since 2.7.0
     693 *
     694 * @return array
     695 */
     696function bp_core_get_directory_page_default_titles() {
     697 return array(
     698    'activity' => _x( 'Activity', 'Page title for the Activity directory.',       'buddypress' ),
     699    'groups'   => _x( 'Groups',   'Page title for the Groups directory.',         'buddypress' ),
     700    'blogs'    => _x( 'Sites',    'Page title for the Sites directory.',          'buddypress' ),
     701    'members'  => _x( 'Members',  'Page title for the Members directory.',        'buddypress' ),
     702    'activate' => _x( 'Activate', 'Page title for the user activation screen.',   'buddypress' ),
     703    'register' => _x( 'Register', 'Page title for the user registration screen.', 'buddypress' ),
     704 );
    694705}
    695706
  • trunk/src/bp-core/bp-core-update.php

    r10941 r11080  
    266266
    267267        // Version 2.7.0.
    268         if ( $raw_db_version < 10940 ) {
     268        if ( $raw_db_version < 11079 ) {
    269269            bp_update_to_2_7();
    270270        }
     
    395395 * a manual filter) to restore it. In 1.9.2, we add an option that flags
    396396 * whether bp-default or a child theme is active at the time of upgrade; if so,
     397 *
    397398 * the theme directory will continue to be registered even if the theme is
    398399 * deactivated temporarily. Thus, new installations will not see bp-default,
     
    510511 * - Add email unsubscribe salt.
    511512 *
     513 * - Save legacy directory titles to the corresponding WP pages.
     514 *
    512515 * @since 2.7.0
    513516 */
    514517function bp_update_to_2_7() {
    515518    bp_add_option( 'bp-emails-unsubscribe-salt', base64_encode( wp_generate_password( 64, true, true ) ) );
     519
     520    // Update post_titles
     521    bp_270_migrate_directory_page_titles();
    516522}
    517523
     
    564570
    565571/**
     572 * Update WP pages so that their post_title matches the legacy component directory title.
     573 *
     574 * As of 2.7.0, component directory titles come from the `post_title` attribute of the corresponding WP post object,
     575 * instead of being hardcoded. To ensure that directory titles don't change for existing installations, we update these
     576 * WP posts with the formerly hardcoded titles.
     577 *
     578 * @since 2.7.0
     579 */
     580function bp_270_migrate_directory_page_titles() {
     581    $bp_pages = bp_core_get_directory_page_ids( 'all' );
     582
     583    $default_titles = bp_core_get_directory_page_default_titles();
     584
     585    $legacy_titles = array(
     586        'activity' => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ),
     587        'blogs'    => _x( 'Sites', 'component directory title', 'buddypress' ),
     588        'groups'   => _x( 'Groups', 'component directory title', 'buddypress' ),
     589        'members'  => _x( 'Members', 'component directory title', 'buddypress' ),
     590    );
     591
     592    foreach ( $bp_pages as $component => $page_id ) {
     593        if ( ! isset( $legacy_titles[ $component ] ) ) {
     594            continue;
     595        }
     596
     597        $page = get_post( $page_id );
     598        if ( ! $page ) {
     599            continue;
     600        }
     601
     602        // If the admin has changed the default title, don't touch it.
     603        if ( isset( $default_titles[ $component ] ) && $default_titles[ $component ] !== $page->post_title ) {
     604            continue;
     605        }
     606
     607        // If the saved page title is the same as the legacy title, there's nothing to do.
     608        if ( $legacy_titles[ $component ] == $page->post_title ) {
     609            continue;
     610        }
     611
     612        // Update the page with the legacy title.
     613        wp_update_post( array(
     614            'ID' => $page_id,
     615            'post_title' => $legacy_titles[ $component ],
     616        ) );
     617    }
     618}
     619
     620/**
    566621 * Redirect user to BP's What's New page on first page load after activation.
    567622 *
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r10794 r11080  
    169169        );
    170170
     171        // Fetch the default directory title.
     172        $default_directory_titles = bp_core_get_directory_page_default_titles();
     173        $default_directory_title  = $default_directory_titles[$this->id];
     174
    171175        // All globals for groups component.
    172176        // Note that global_tables is included in this array.
     
    175179            'root_slug'             => isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : BP_GROUPS_SLUG,
    176180            'has_directory'         => true,
    177             'directory_title'       => _x( 'Groups', 'component directory title', 'buddypress' ),
     181            'directory_title'       => isset( $bp->pages->groups->title ) ? $bp->pages->groups->title : $default_directory_title,
    178182            'notification_callback' => 'groups_format_notifications',
    179183            'search_string'         => _x( 'Search Groups...', 'Component directory search', 'buddypress' ),
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r10774 r11080  
    109109        }
    110110
     111        // Fetch the default directory title.
     112        $default_directory_titles = bp_core_get_directory_page_default_titles();
     113        $default_directory_title  = $default_directory_titles[$this->id];
     114
    111115        // Override any passed args.
    112116        $args = array(
     
    114118            'root_slug'       => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : BP_MEMBERS_SLUG,
    115119            'has_directory'   => true,
    116             'directory_title' => _x( 'Members', 'component directory title', 'buddypress' ),
     120            'directory_title' => isset( $bp->pages->members->title ) ? $bp->pages->members->title : $default_directory_title,
    117121            'search_string'   => __( 'Search Members...', 'buddypress' ),
    118122            'global_tables'   => array(
Note: See TracChangeset for help on using the changeset viewer.