Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/21/2010 04:06:48 PM (16 years ago)
Author:
boonebgorges
Message:

Adds Upgrade routine for WP MS activation. Fixes #2732. Moves site options loading functions to ensure that they're loaded at activation. Fixes #2717, props DJPaul. Modifies the way that bp-pages data is stored in and fetched from options tables on multisite. References #2518. The only thing this patch does not do is bake pie.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-upgrade.php

    r3451 r3463  
    11<?php
    22
     3if ( !defined( 'BP_ROOT_BLOG' ) )
     4        define( 'BP_ROOT_BLOG', 1 );
     5
    36require_once( dirname( dirname( __FILE__ ) ) . '/bp-core-wpabstraction.php' );
    47
    58register_theme_directory( WP_PLUGIN_DIR . '/buddypress/bp-themes' );
     9
     10// Install site options on activation
     11bp_core_activate_site_options( array( 'bp-disable-account-deletion' => 0, 'bp-disable-avatar-uploads' => 0, 'bp-disable-blogforum-comments' => 0,  'bp-disable-forum-directory' => 0,  'bp-disable-profile-sync' => 0 ) );
     12 
     13/**
     14 * bp_core_activate_site_options()
     15 *
     16 * When switching from single to multisite we need to copy blog options to
     17 * site options.
     18 *
     19 * @package BuddyPress Core
     20 */
     21function bp_core_activate_site_options( $keys = array() ) {
     22        global $bp;
     23
     24        $bp->site_options = bp_core_get_site_options();
     25
     26        if ( !empty( $keys ) && is_array( $keys ) ) {
     27                $errors = false;
     28
     29                foreach ( $keys as $key => $default ) {
     30                        if ( empty( $bp->site_options[ $key ] ) ) {
     31                                $bp->site_options[ $key ] = get_blog_option( BP_ROOT_BLOG, $key, $default );
     32
     33                                if ( !update_site_option( $key, $bp->site_options[ $key ] ) )
     34                                        $errors = true;
     35                        }
     36                }
     37
     38                if ( empty( $errors ) )
     39                        return true;
     40        }
     41
     42        return false;
     43}
    644
    745class BP_Core_Setup_Wizard {
    … …  
    1048
    1149        var $current_version;
     50        var $is_network_activate;
    1251        var $new_version;
    1352        var $setup_type;
    1453
    1554        function bp_core_setup_wizard() {
    16                 $this->current_version = get_site_option( 'bp-db-version' );
     55                if ( !$this->current_version = get_site_option( 'bp-db-version' ) )
     56                        if ( $this->current_version = get_option( 'bp-db-version' ) )
     57                                $this->is_network_activate = true;
     58               
    1759                $this->new_version = constant( 'BP_DB_VERSION' );
    1860                $this->setup_type = ( empty( $this->current_version ) && !(int)get_site_option( 'bp-core-db-version' ) ) ? 'new' : 'upgrade';
    … …  
    4486
    4587                if ( 'new' == $this->setup_type ) {
    46                         /* Setup wizard steps */
     88                        // Setup wizard steps
    4789                        $steps = array(
    4890                                __( 'Components', 'buddypress' ),
    … …  
    61103                        }
    62104                } else {
    63                         /* Upgrade wizard steps */
    64                         $steps[] = __( 'Database Upgrade', 'buddypress' );
     105                        // Upgrade wizard steps
     106                       
     107                        if ( $this->is_network_activate )
     108                                $steps[] = __( 'Multisite Upgrade', 'buddypress' );
     109                       
     110                        if ( $this->current_version < $this->new_version )
     111                                $steps[] = __( 'Database Upgrade', 'buddypress' );
    65112
    66113                        if ( $this->current_version < 1225 )
    … …  
    78125                        case 'db_upgrade': default:
    79126                                $result = $this->step_db_upgrade_save();
     127                                break;
     128                        case 'ms_upgrade': default:
     129                                $result = $this->step_ms_upgrade_save();
     130                                break;
     131                        case 'ms_pages': default:
     132                                $result = $this->step_ms_upgrade_save();
    80133                                break;
    81134                        case 'components': default:
    … …  
    139192                                                case __( 'Database Upgrade', 'buddypress'):
    140193                                                        $this->step_db_upgrade();
     194                                                        break;
     195                                                case __( 'Multisite Upgrade', 'buddypress'):
     196                                                        $this->step_ms_upgrade();
     197                                                        break;
     198                                                case __( 'Blog Directory', 'buddypress'):
     199                                                        $this->step_ms_upgrade();
    141200                                                        break;
    142201                                                case __( 'Components', 'buddypress'):
    … …  
    184243        <?php
    185244        }
     245       
     246        function step_ms_upgrade() {
     247                if ( !current_user_can( 'activate_plugins' ) )
     248                        return false;
     249
     250                if ( defined( 'BP_BLOGS_SLUG' ) )
     251                        $blogs_slug = constant( 'BP_BLOGS_SLUG' );
     252                else
     253                        $blogs_slug = __( 'blogs', 'buddypress' );
     254               
     255                if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
     256                        $existing_pages = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
     257                else
     258                        $existing_pages = get_option( 'bp-pages' );
     259
     260        ?>
     261                <div class="prev-next submit clear">
     262                        <p><input type="submit" value="<?php _e( 'Save &amp; Next &rarr;', 'buddypress' ) ?>" name="submit" /></p>
     263                </div>
     264               
     265                <p><?php printf( __( 'It looks like you have just activated WordPress Multisite mode, which allows members of your BuddyPress community to have their own WordPress blogs. You can enable or disable this feature at any time at <a href="%s">Network Options</a>.', 'buddypress' ), admin_url( 'ms-options.php' ) ); ?></p>
     266               
     267                <p><?php _e( "Please select the WordPress page you would like to use to display the blog directory. You can either choose an existing page or let BuddyPress auto-create a page for you. If you'd like to manually create pages, please go ahead and do that now, you can come back to this step once you are finished.", 'buddypress' ) ?></p>
     268
     269                <p><strong><?php _e( 'Please Note:', 'buddypress' ) ?></strong> <?php _e( "If you have manually added BuddyPress navigation links in your theme you may need to remove these from your header.php to avoid duplicate links.", 'buddypress' ) ?></p>
     270
     271                <table class="form-table">
     272
     273                        <tr valign="top">
     274                                <th scope="row">
     275                                        <h5><?php _e( 'Blogs', 'buddypress' ) ?></h5>
     276                                        <p><?php _e( 'Displays individual groups as well as a directory of groups.', 'buddypress' ) ?></p>
     277                                </th>
     278                                <td>
     279                                        <p><input type="radio" name="bp_pages[blogs]" value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ) ?> <?php echo wp_dropdown_pages("name=bp-blogs-page&echo=0&show_option_none=".__('- Select -')."&selected=" . $existing_pages['blogs'] ) ?></p>
     280                                        <p><input type="radio" name="bp_pages[blogs]" checked="checked" value="<?php echo $blogs_slug ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ) ?> <?php echo site_url( $blogs_slug ) ?>/</p>
     281                                </td>
     282                        </tr>
     283                       
     284                </table>
     285               
     286                <p><?php _e( 'Would you like to enable blog tracking, which tracks blog activity across your network?', 'buddypress' ); ?></p>
     287               
     288                <div class="left-col">
     289                       
     290                        <div class="component">
     291                                <h5><?php _e( "Blog Tracking", 'buddypress' ) ?></h5>
     292
     293                                <div class="radio">
     294                                        <input type="radio" name="bp_components[bp-blogs.php]" value="1"<?php if ( !isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> &nbsp;
     295                                        <input type="radio" name="bp_components[bp-blogs.php]" value="0"<?php if ( isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
     296                                </div>
     297
     298                                <img src="<?php echo plugins_url( 'buddypress/screenshot-7.gif' ) ?>" alt="Activity Streams" />
     299                                        <p><?php _e( "Track new blogs, new posts and new comments across your entire blog network.", 'buddypress' ) ?></p>
     300                        </div>         
     301                </div>
     302               
     303                <div class="submit clear">
     304                        <p><input type="submit" value="<?php _e( 'Save &amp; Next &rarr;', 'buddypress' ) ?>" name="submit" /></p>
     305
     306                        <input type="hidden" name="save" value="ms_upgrade" />
     307                        <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ) ?>" />
     308                        <?php wp_nonce_field( 'bpwizard_ms_upgrade' ) ?>
     309                </div>
     310               
     311                <script type="text/javascript">
     312                        jQuery('select').click( function() {
     313                                jQuery(this).parent().children('input').attr( 'checked', 'checked' );
     314                        });
     315                </script>
     316        <?php
     317        }
     318
    186319
    187320        function step_components() {
    … …  
    307440                        return false;
    308441
    309                 $existing_pages = get_site_option( 'bp-pages' );
     442                if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
     443                        $existing_pages = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
     444                else
     445                        $existing_pages = get_option( 'bp-pages' );
     446
    310447                $disabled_components = apply_filters( 'bp_deactivated_components', get_site_option( 'bp-deactivated-components' ) );
    311448
    … …  
    645782                <?php endif; ?>
    646783
    647                 <?php?>
    648784                <p><?php printf( __( "You've now completed all of the %s steps and BuddyPress is ready to be activated. Please hit the 'Finish &amp; Activate' button to complete the %s procedure.", 'buddypress' ), $type, $type ) ?></p>
    649785
    … …  
    676812                return false;
    677813        }
     814
     815        function step_ms_upgrade_save() {
     816                global $current_blog;
     817
     818                if ( isset( $_POST['submit'] ) ) {
     819                        check_admin_referer( 'bpwizard_ms_upgrade' );
     820
     821                        if ( !$disabled = get_option( 'bp-deactivated-components' ) )
     822                                $disabled = array();
     823
     824                        // Transfer important settings from blog options to site options
     825                        $options = array(
     826                                'bp-db-version' => $this->current_version,
     827                                'bp-deactivated-components' => $disabled
     828                        );
     829                        bp_core_activate_site_options( $options );
     830
     831                        if ( !(int) $_POST['bp_components']['bp-blogs.php'] ) {
     832                                if ( !$disabled )
     833                                        $disabled = array();
     834                                $disabled['bp-blogs.php'] = 1;
     835                        } else {
     836                                // Make sure that the pages are created on the BP_ROOT_BLOG, no matter which Dashboard the setup is being run on
     837                                if ( $current_blog->blog_id != BP_ROOT_BLOG && !defined( 'BP_ENABLE_MULTIBLOG' ) )
     838                                        switch_to_blog( BP_ROOT_BLOG );
     839       
     840                                $existing_pages = get_option( 'bp-pages' );
     841
     842                                $bp_pages = $this->setup_pages( (array)$_POST['bp_pages'] );
     843                               
     844                                $bp_pages = array_merge( (array)$existing_pages, (array)$bp_pages );
     845       
     846                                update_option( 'bp-pages', $bp_pages );
     847
     848                                if ( $current_blog->blog_id != BP_ROOT_BLOG )
     849                                        restore_current_blog();
     850                       
     851                                unset( $disabled['bp-blogs.php'] );
     852                               
     853                                bp_core_install( $disabled );
     854                        }
     855                       
     856                        update_site_option( 'bp-deactivated-components', $disabled );
     857
     858                        return true;
     859                }
     860
     861                return false;
     862        }
     863
    678864
    679865        function step_components_save() {
    … …  
    698884
    699885        function step_pages_save() {
     886                global $current_blog;
     887
    700888                if ( isset( $_POST['submit'] ) && isset( $_POST['bp_pages'] ) ) {
    701889                        check_admin_referer( 'bpwizard_pages' );
    702890
    703                         /* Delete any existing pages */
    704                         $existing_pages = get_site_option( 'bp-pages' );
     891                        // Make sure that the pages are created on the BP_ROOT_BLOG, no matter which Dashboard the setup is being run on
     892                        if ( $current_blog->blog_id != BP_ROOT_BLOG && !defined( 'BP_ENABLE_MULTIBLOG' ) )
     893                                switch_to_blog( BP_ROOT_BLOG );
     894
     895                        // Delete any existing pages
     896                        $existing_pages = get_option( 'bp-pages' );
    705897
    706898                        foreach ( (array)$existing_pages as $page_id )
    707899                                wp_delete_post( $page_id, true );
    708900
    709                         // Settings form submitted, now save the settings.
    710                         foreach ( (array)$_POST['bp_pages'] as $key => $value ) {
    711                                 if ( 'page' == $value ) {
    712                                         /* Check for the selected page */
    713                                         if ( !empty( $_POST['bp-' . $key . '-page'] ) )
    714                                                 $bp_pages[$key] = (int)$_POST['bp-' . $key . '-page'];
    715                                         else
    716                                                 $bp_pages[$key] = wp_insert_post( array( 'post_title' => ucwords( $key ), 'post_status' => 'publish', 'post_type' => 'page' ) );
    717                                 } else {
    718                                         /* Create a new page */
    719                                         $bp_pages[$key] = wp_insert_post( array( 'post_title' => ucwords( $value ), 'post_status' => 'publish', 'post_type' => 'page' ) );
    720                                 }
    721                         }
    722                         update_site_option( 'bp-pages', $bp_pages );
     901                        $bp_pages = $this->setup_pages( (array)$_POST['bp_pages'] );
     902
     903                        update_option( 'bp-pages', $bp_pages );
     904
     905                        if ( $current_blog->blog_id != BP_ROOT_BLOG )
     906                                restore_current_blog();
    723907
    724908                        return true;
    … …  
    8511035
    8521036                        /* Redirect to the BuddyPress dashboard */
    853                         wp_redirect( site_url( 'wp-admin/admin.php?page=bp-general-settings' ) );
     1037                        wp_redirect( admin_url( 'admin.php?page=bp-general-settings' ) );
    8541038
    8551039                        return true;
    … …  
    8571041
    8581042                return false;
     1043        }
     1044       
     1045        function setup_pages( $pages ) {
     1046                foreach ( $pages as $key => $value ) {
     1047                        if ( 'page' == $value ) {
     1048                                /* Check for the selected page */
     1049                                if ( !empty( $_POST['bp-' . $key . '-page'] ) )
     1050                                        $bp_pages[$key] = (int)$_POST['bp-' . $key . '-page'];
     1051                                else
     1052                                        $bp_pages[$key] = wp_insert_post( array( 'post_title' => ucwords( $key ), 'post_status' => 'publish', 'post_type' => 'page' ) );
     1053                        } else {
     1054                                /* Create a new page */
     1055                                $bp_pages[$key] = wp_insert_post( array( 'post_title' => ucwords( $value ), 'post_status' => 'publish', 'post_type' => 'page' ) );
     1056                        }
     1057                }
     1058               
     1059                return $bp_pages;
    8591060        }
    8601061
    … …  
    10521253                return false;
    10531254
    1054         if ( '' == get_site_option( 'bp-db-version' ) && !(int)get_site_option( 'bp-core-db-version' ) )
     1255        if ( '' == get_site_option( 'bp-db-version' ) && !(int)get_site_option( 'bp-core-db-version' ) && !$bp_wizard->is_network_activate )
    10551256                $status = __( 'Setup', 'buddypress' );
    10561257        else
    … …  
    10851286<?php
    10861287}
    1087 
    10881288?>
Note: See TracChangeset for help on using the changeset viewer.