Changeset 3463 for trunk/bp-core/admin/bp-core-upgrade.php
- Timestamp:
- 11/21/2010 04:06:48 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/bp-core/admin/bp-core-upgrade.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/admin/bp-core-upgrade.php
r3451 r3463 1 1 <?php 2 2 3 if ( !defined( 'BP_ROOT_BLOG' ) ) 4 define( 'BP_ROOT_BLOG', 1 ); 5 3 6 require_once( dirname( dirname( __FILE__ ) ) . '/bp-core-wpabstraction.php' ); 4 7 5 8 register_theme_directory( WP_PLUGIN_DIR . '/buddypress/bp-themes' ); 9 10 // Install site options on activation 11 bp_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 */ 21 function 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 } 6 44 7 45 class BP_Core_Setup_Wizard { … … 10 48 11 49 var $current_version; 50 var $is_network_activate; 12 51 var $new_version; 13 52 var $setup_type; 14 53 15 54 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 17 59 $this->new_version = constant( 'BP_DB_VERSION' ); 18 60 $this->setup_type = ( empty( $this->current_version ) && !(int)get_site_option( 'bp-core-db-version' ) ) ? 'new' : 'upgrade'; … … 44 86 45 87 if ( 'new' == $this->setup_type ) { 46 / * Setup wizard steps */88 // Setup wizard steps 47 89 $steps = array( 48 90 __( 'Components', 'buddypress' ), … … 61 103 } 62 104 } 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' ); 65 112 66 113 if ( $this->current_version < 1225 ) … … 78 125 case 'db_upgrade': default: 79 126 $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(); 80 133 break; 81 134 case 'components': default: … … 139 192 case __( 'Database Upgrade', 'buddypress'): 140 193 $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(); 141 200 break; 142 201 case __( 'Components', 'buddypress'): … … 184 243 <?php 185 244 } 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 & Next →', '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' ) ?> 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 & Next →', '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 186 319 187 320 function step_components() { … … 307 440 return false; 308 441 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 310 447 $disabled_components = apply_filters( 'bp_deactivated_components', get_site_option( 'bp-deactivated-components' ) ); 311 448 … … 645 782 <?php endif; ?> 646 783 647 <?php?>648 784 <p><?php printf( __( "You've now completed all of the %s steps and BuddyPress is ready to be activated. Please hit the 'Finish & Activate' button to complete the %s procedure.", 'buddypress' ), $type, $type ) ?></p> 649 785 … … 676 812 return false; 677 813 } 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 678 864 679 865 function step_components_save() { … … 698 884 699 885 function step_pages_save() { 886 global $current_blog; 887 700 888 if ( isset( $_POST['submit'] ) && isset( $_POST['bp_pages'] ) ) { 701 889 check_admin_referer( 'bpwizard_pages' ); 702 890 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' ); 705 897 706 898 foreach ( (array)$existing_pages as $page_id ) 707 899 wp_delete_post( $page_id, true ); 708 900 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(); 723 907 724 908 return true; … … 851 1035 852 1036 /* 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' ) ); 854 1038 855 1039 return true; … … 857 1041 858 1042 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; 859 1060 } 860 1061 … … 1052 1253 return false; 1053 1254 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 ) 1055 1256 $status = __( 'Setup', 'buddypress' ); 1056 1257 else … … 1085 1286 <?php 1086 1287 } 1087 1088 1288 ?>
Note: See TracChangeset
for help on using the changeset viewer.