Skip to:
Content

BuddyPress.org

Ticket #6765: 6765-migration.diff

File 6765-migration.diff, 4.6 KB (added by boonebgorges, 4 years ago)
  • src/bp-core/bp-core-functions.php

    diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php
    index abd4400..56f8ac1 100644
    function bp_core_add_page_mappings( $components, $existing = 'keep' ) { 
    636636                $pages = array();
    637637        }
    638638
    639         $page_titles = array(
    640                 'activity' => _x( 'Activity', 'Page title for the Activity directory.',       'buddypress' ),
    641                 'groups'   => _x( 'Groups',   'Page title for the Groups directory.',         'buddypress' ),
    642                 'sites'    => _x( 'Sites',    'Page title for the Sites directory.',          'buddypress' ),
    643                 'members'  => _x( 'Members',  'Page title for the Members directory.',        'buddypress' ),
    644                 'activate' => _x( 'Activate', 'Page title for the user activation screen.',   'buddypress' ),
    645                 'register' => _x( 'Register', 'Page title for the user registration screen.', 'buddypress' ),
    646         );
     639        $page_titles = bp_core_get_directory_page_default_titles();
    647640
    648641        $pages_to_create = array();
    649642        foreach ( array_keys( $components ) as $component_name ) {
    function bp_core_add_page_mappings( $components, $existing = 'keep' ) { 
    700693}
    701694
    702695/**
     696 * Get the default page titles for BP directory pages.
     697 *
     698 * @since 2.6.0
     699 *
     700 * @return array
     701 */
     702function bp_core_get_directory_page_default_titles() {
     703        return array(
     704                'activity' => _x( 'Activity', 'Page title for the Activity directory.',       'buddypress' ),
     705                'groups'   => _x( 'Groups',   'Page title for the Groups directory.',         'buddypress' ),
     706                'sites'    => _x( 'Sites',    'Page title for the Sites directory.',          'buddypress' ),
     707                'members'  => _x( 'Members',  'Page title for the Members directory.',        'buddypress' ),
     708                'activate' => _x( 'Activate', 'Page title for the user activation screen.',   'buddypress' ),
     709                'register' => _x( 'Register', 'Page title for the user registration screen.', 'buddypress' ),
     710        );
     711}
     712
     713/**
    703714 * Remove the entry from bp_pages when the corresponding WP page is deleted.
    704715 *
    705716 * Bails early on multisite installations when not viewing the root site.
  • src/bp-core/bp-core-update.php

    diff --git src/bp-core/bp-core-update.php src/bp-core/bp-core-update.php
    index 7fbdd30..71a0808 100644
    function bp_version_updater() { 
    275275                if ( $raw_db_version < 10440 ) {
    276276                        bp_update_to_2_5();
    277277                }
     278
     279                // 2.6.0
     280                if ( $raw_db_version < 10772 ) {
     281                        bp_update_to_2_6();
     282                }
    278283        }
    279284
    280285        /* All done! *************************************************************/
    function bp_update_to_2_5() { 
    514519}
    515520
    516521/**
     522 * 2.6.0 update routine.
     523 *
     524 * - Save legacy directory titles to the corresponding WP pages.
     525 *
     526 * @since 2.6.0
     527 */
     528function bp_update_to_2_6() {
     529        bp_260_migrate_directory_page_titles();
     530}
     531
     532/**
    517533 * Updates the component field for new_members type.
    518534 *
    519535 * @since 2.2.0
    function bp_cleanup_friendship_activities() { 
    564580}
    565581
    566582/**
     583 * Update WP pages so that their post_title matches the legacy component directory title.
     584 *
     585 * As of 2.6.0, component directory titles come from the `post_title` attribute of the corresponding WP post object,
     586 * instead of being hardcoded. To ensure that directory titles don't change for existing installations, we update these
     587 * WP posts with the formerly hardcoded titles.
     588 *
     589 * @since 2.6.0
     590 */
     591function bp_260_migrate_directory_page_titles() {
     592        $bp_pages = bp_core_get_directory_page_ids( 'all' );
     593
     594        $default_titles = bp_core_get_directory_page_default_titles();
     595
     596        $legacy_titles = array(
     597                'activity' => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ),
     598                'blogs'    => _x( 'Sites', 'component directory title', 'buddypress' ),
     599                'groups'   => _x( 'Groups', 'component directory title', 'buddypress' ),
     600                'members'  => _x( 'Members', 'component directory title', 'buddypress' ),
     601        );
     602
     603        foreach ( $bp_pages as $component => $page_id ) {
     604                if ( ! isset( $legacy_titles[ $component ] ) ) {
     605                        continue;
     606                }
     607
     608                $page = get_post( $page_id );
     609                if ( ! $page ) {
     610                        continue;
     611                }
     612
     613                // If the admin has changed the default title, don't touch it.
     614                if ( isset( $default_titles[ $component ] ) && $default_titles[ $component ] !== $page->post_title ) {
     615                        continue;
     616                }
     617
     618                // If the saved page title is the same as the legacy title, there's nothing to do.
     619                if ( $legacy_titles[ $component ] == $page->post_title ) {
     620                        continue;
     621                }
     622
     623                // Update the page with the legacy title.
     624                wp_update_post( array(
     625                        'ID' => $page_id,
     626                        'post_title' => $legacy_titles[ $component ],
     627                ) );
     628        }
     629}
     630
     631/**
    567632 * Redirect user to BP's What's New page on first page load after activation.
    568633 *
    569634 * @since 1.7.0