Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/10/2016 02:25:50 PM (8 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 *
Note: See TracChangeset for help on using the changeset viewer.