Skip to:
Content

BuddyPress.org

Ticket #6765: 6765-02a+migration+defaults.diff

File 6765-02a+migration+defaults.diff, 9.7 KB (added by dcavins, 4 years ago)

Uses @imath's 02a and @boonebgorges' migration and uses master page default titles list.

  • src/bp-activity/classes/class-bp-activity-component.php

    diff --git src/bp-activity/classes/class-bp-activity-component.php src/bp-activity/classes/class-bp-activity-component.php
    index 39ae94f..848562d 100644
    class BP_Activity_Component extends BP_Component { 
    116116                        'activity' => $bp->table_prefix . 'bp_activity_meta',
    117117                );
    118118
     119                // Fetch the default directory title.
     120                $default_directory_titles = bp_core_get_directory_page_default_titles();
     121                $default_directory_title  = $default_directory_titles[$this->id];
     122
    119123                // All globals for activity component.
    120124                // Note that global_tables is included in this array.
    121125                $args = array(
    122126                        'slug'                  => BP_ACTIVITY_SLUG,
    123127                        'root_slug'             => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG,
    124128                        'has_directory'         => true,
    125                         'directory_title'       => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ),
     129                        'directory_title'       => isset( $bp->pages->activity->title ) ? $bp->pages->activity->title : $default_directory_title,
    126130                        'notification_callback' => 'bp_activity_format_notifications',
    127131                        'search_string'         => __( 'Search Activity...', 'buddypress' ),
    128132                        'global_tables'         => $global_tables,
  • src/bp-blogs/classes/class-bp-blogs-component.php

    diff --git src/bp-blogs/classes/class-bp-blogs-component.php src/bp-blogs/classes/class-bp-blogs-component.php
    index 69dfe37..bb12f0d 100644
    class BP_Blogs_Component extends BP_Component { 
    6565                        'blog' => $bp->table_prefix . 'bp_user_blogs_blogmeta',
    6666                );
    6767
     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];
     71
    6872                // All globals for blogs component.
    6973                $args = array(
    7074                        'slug'                  => BP_BLOGS_SLUG,
    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' ),
    7680                        'autocomplete_all'      => defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ),
  • src/bp-core/bp-core-functions.php

    diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php
    index 7cf28aa..3cbb381 100644
    function bp_core_add_page_mappings( $components, $existing = 'keep' ) { 
    630630                $pages = array();
    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                 'sites'    => _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();
    643636        foreach ( array_keys( $components ) as $component_name ) {
    function bp_core_add_page_mappings( $components, $existing = 'keep' ) { 
    694687}
    695688
    696689/**
     690 * Get the default page titles for BP directory pages.
     691 *
     692 * @since 2.6.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                'sites'    => _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        );
     705}
     706
     707/**
    697708 * Remove the entry from bp_pages when the corresponding WP page is deleted.
    698709 *
    699710 * 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 081b1ff..3d14425 100644
    function bp_version_updater() { 
    263263                if ( $raw_db_version < 10440 ) {
    264264                        bp_update_to_2_5();
    265265                }
     266
     267                // 2.6.0
     268                if ( $raw_db_version < 10772 ) {
     269                        bp_update_to_2_6();
     270                }
    266271        }
    267272
    268273        /* All done! *************************************************************/
    function bp_update_to_2_5() { 
    502507}
    503508
    504509/**
     510 * 2.6.0 update routine.
     511 *
     512 * - Save legacy directory titles to the corresponding WP pages.
     513 *
     514 * @since 2.6.0
     515 */
     516function bp_update_to_2_6() {
     517        bp_260_migrate_directory_page_titles();
     518}
     519
     520/**
    505521 * Updates the component field for new_members type.
    506522 *
    507523 * @since 2.2.0
    function bp_cleanup_friendship_activities() { 
    550566}
    551567
    552568/**
     569 * Update WP pages so that their post_title matches the legacy component directory title.
     570 *
     571 * As of 2.6.0, component directory titles come from the `post_title` attribute of the corresponding WP post object,
     572 * instead of being hardcoded. To ensure that directory titles don't change for existing installations, we update these
     573 * WP posts with the formerly hardcoded titles.
     574 *
     575 * @since 2.6.0
     576 */
     577function bp_260_migrate_directory_page_titles() {
     578        $bp_pages = bp_core_get_directory_page_ids( 'all' );
     579
     580        $default_titles = bp_core_get_directory_page_default_titles();
     581
     582        $legacy_titles = array(
     583                'activity' => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ),
     584                'blogs'    => _x( 'Sites', 'component directory title', 'buddypress' ),
     585                'groups'   => _x( 'Groups', 'component directory title', 'buddypress' ),
     586                'members'  => _x( 'Members', 'component directory title', 'buddypress' ),
     587        );
     588
     589        foreach ( $bp_pages as $component => $page_id ) {
     590                if ( ! isset( $legacy_titles[ $component ] ) ) {
     591                        continue;
     592                }
     593
     594                $page = get_post( $page_id );
     595                if ( ! $page ) {
     596                        continue;
     597                }
     598
     599                // If the admin has changed the default title, don't touch it.
     600                if ( isset( $default_titles[ $component ] ) && $default_titles[ $component ] !== $page->post_title ) {
     601                        continue;
     602                }
     603
     604                // If the saved page title is the same as the legacy title, there's nothing to do.
     605                if ( $legacy_titles[ $component ] == $page->post_title ) {
     606                        continue;
     607                }
     608
     609                // Update the page with the legacy title.
     610                wp_update_post( array(
     611                        'ID' => $page_id,
     612                        'post_title' => $legacy_titles[ $component ],
     613                ) );
     614        }
     615}
     616
     617/**
    553618 * Redirect user to BP's What's New page on first page load after activation.
    554619 *
    555620 * @since 1.7.0
  • src/bp-groups/classes/class-bp-groups-component.php

    diff --git src/bp-groups/classes/class-bp-groups-component.php src/bp-groups/classes/class-bp-groups-component.php
    index 93bb9b7..d60278c 100644
    class BP_Groups_Component extends BP_Component { 
    168168                        'group' => $bp->table_prefix . 'bp_groups_groupmeta',
    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.
    173177                $args = array(
    174178                        'slug'                  => BP_GROUPS_SLUG,
    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' ),
    180184                        'global_tables'         => $global_tables,
  • src/bp-members/classes/class-bp-members-component.php

    diff --git src/bp-members/classes/class-bp-members-component.php src/bp-members/classes/class-bp-members-component.php
    index 73b45e0..712f80d 100644
    class BP_Members_Component extends BP_Component { 
    108108                        define( 'BP_MEMBERS_SLUG', $this->id );
    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(
    113117                        'slug'            => BP_MEMBERS_SLUG,
    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(
    119123                                'table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity',