Skip to:
Content

BuddyPress.org

Changeset 6693


Ignore:
Timestamp:
12/30/2012 02:33:47 PM (12 years ago)
Author:
djpaul
Message:

Make new BuddyPress installs (and <1.5 upgrades) automatically create pages for component mapping. See #4671.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-update.php

    r6673 r6693  
    177177    $raw_db_version = (int) bp_get_db_version_raw();
    178178
     179    $default_components = apply_filters( 'bp_new_install_default_components', array( 'activity' => 1, 'xprofile' => 1, ) );
    179180    require_once( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-schema.php' );
    180181
     
    182183    if ( bp_is_install() ) {
    183184
    184         $default_components = apply_filters( 'bp_new_install_default_components', array( 'activity' => 1, 'xprofile' => 1, ) );
     185        // Apply schema and set Activity and XProfile components as active
    185186        bp_core_install( $default_components );
    186187        bp_update_option( 'bp-active-components', $default_components );
     188        bp_updater_add_page_mappings( $default_components );
     189
    187190
    188191    // Upgrades
     
    193196
    194197        // 1.5
    195         if ( $raw_db_version < 1801 )
     198        if ( $raw_db_version < 1801 ) {
    196199            bp_update_to_1_5();
     200            bp_updater_add_page_mappings( $default_components );
     201        }
    197202
    198203        // 1.6
    199         if ( $raw_db_version < 6067 )
     204        if ( $raw_db_version < 6067 ) {
    200205            bp_update_to_1_6();
     206        }
    201207    }
    202208
     
    244250
    245251/**
     252 * Add the pages for the component mapping. These are most often used by components with directories (e.g. groups, members).
     253 *
     254 * @param array $default_components Optional components to create pages for
     255 * @since BuddyPress (1.7)
     256 */
     257function bp_updater_add_page_mappings( $default_components ) {
     258
     259    // Make sure that the pages are created on the root blog no matter which Dashboard the setup is being run on
     260    if ( ! bp_is_root_blog() )
     261        switch_to_blog( bp_get_root_blog_id() );
     262
     263    // Delete any existing pages
     264    $pages = bp_core_get_directory_page_ids();
     265    foreach ( (array) $pages as $page_id )
     266        wp_delete_post( $page_id, true );
     267
     268    $pages = array();
     269    foreach ( array_keys( $default_components ) as $component_name ) {
     270        if ( $component_name == 'activity' ) {
     271            $pages[$component_name] = _x( 'Activity', 'Page title for the Activity directory.', 'buddypress' );
     272
     273        } elseif ( $component_name == 'groups') {
     274            $pages[$component_name] = _x( 'Groups', 'Page title for the Groups directory.', 'buddypress' );
     275
     276        // Blogs component only needs a directory page when multisite is enabled
     277        } elseif ( $component_name == 'blogs' && is_multisite() ) {
     278            $pages[$component_name] = _x( 'Sites', 'Page title for the Sites directory.', 'buddypress' );
     279        }
     280    }
     281
     282    // Mandatory components/pages
     283    $pages['activate'] = _x( 'Activate', 'Page title for the user account activation screen.', 'buddypress' );
     284    $pages['members']  = _x( 'Members',  'Page title for the Members directory.',              'buddypress' );
     285    $pages['register'] = _x( 'Register', 'Page title for the user registration screen.',       'buddypress' );
     286
     287    // Create the pages
     288    foreach ( $pages as $component_name => $page_name ) {
     289        $pages[$component_name] = wp_insert_post( array(
     290            'comment_status' => 'closed',
     291            'ping_status'    => 'closed',
     292            'post_status'    => 'publish',
     293            'post_title'     => $page_name,
     294            'post_type'      => 'page',
     295        ) );
     296    }
     297
     298    // Save the page mapping
     299    bp_update_option( 'bp-pages', $pages );
     300
     301    // If we had to switch_to_blog, go back to the original site.
     302    if ( ! bp_is_root_blog() )
     303        restore_current_blog();
     304}
     305
     306/**
    246307 * Redirect user to BuddyPress's What's New page on activation
    247308 *
Note: See TracChangeset for help on using the changeset viewer.