Changeset 3463
- Timestamp:
- 11/21/2010 04:06:48 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
bp-core.php (modified) (5 diffs)
-
bp-core/admin/bp-core-upgrade.php (modified) (15 diffs)
-
bp-loader.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core.php
r3451 r3463 83 83 // Set up the members id and active components entry 84 84 $bp->members->id = 'members'; 85 85 86 $bp->members->slug = $bp->pages->members->slug; 86 87 $bp->active_components[$bp->members->slug] = $bp->members->id; … … 212 213 add_action( 'bp_setup_globals', 'bp_core_define_slugs' ); 213 214 215 216 /** 217 * bp_core_get_page_meta() 218 * 219 * Fetches BP pages from the meta table, depending on setup 220 * 221 * @package BuddyPress Core Core 222 */ 223 function bp_core_get_page_meta() { 224 if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() ) 225 $page_ids = get_blog_option( BP_ROOT_BLOG, 'bp-pages' ); 226 else 227 $page_ids = get_option( 'bp-pages' ); 228 229 return $page_ids; 230 } 231 232 /** 233 * bp_core_update_page_meta() 234 * 235 * Stores BP pages in the meta table, depending on setup 236 * 237 * @package BuddyPress Core Core 238 */ 239 function bp_core_update_page_meta( $page_ids ) { 240 if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() ) 241 update_blog_option( BP_ROOT_BLOG, 'bp-pages', $page_ids ); 242 else 243 update_option( 'bp-pages', $page_ids ); 244 } 245 246 214 247 function bp_core_get_page_names() { 215 global $wpdb, $current_blog; 216 217 if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) 218 $page_ids = get_blog_option( $current_blog->blog_id, 'bp-pages' ); 219 else 220 $page_ids = get_blog_option( BP_ROOT_BLOG, 'bp-pages' ); 248 global $wpdb; 249 250 $page_ids = bp_core_get_page_meta(); 221 251 222 252 if ( empty( $page_ids ) ) … … 633 663 * 634 664 * @package BuddyPress Core 635 * @global $current_blog WordPress global containing information and settings for the current blog being viewed.636 665 * @uses bp_core_get_userid_from_user_login() Returns the user id for the username passed 637 666 * @return The user id for the user that is currently being displayed, return zero if this is not a user home and just a normal blog. … … 1553 1582 1554 1583 return apply_filters( 'bp_core_get_site_path', $site_path ); 1555 }1556 1557 /**1558 * bp_core_get_site_options()1559 *1560 * BuddyPress uses site options to store configuration settings. Many of these settings are needed1561 * at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch1562 * them all in one go.1563 *1564 * @package BuddyPress Core1565 */1566 function bp_core_get_site_options() {1567 global $bp, $wpdb;1568 1569 $options = apply_filters( 'bp_core_site_options', array(1570 'bp-deactivated-components',1571 'bp-blogs-first-install',1572 'bp-disable-blog-forum-comments',1573 'bp-xprofile-base-group-name',1574 'bp-xprofile-fullname-field-name',1575 'bp-disable-profile-sync',1576 'bp-disable-avatar-uploads',1577 'bp-disable-account-deletion',1578 'bp-disable-forum-directory',1579 'bp-disable-blogforum-comments',1580 'bb-config-location',1581 'hide-loggedout-adminbar',1582 1583 // Useful WordPress settings used often1584 'avatar_default',1585 'tags_blog_id',1586 'registration',1587 'fileupload_maxk'1588 ) );1589 1590 $meta_keys = "'" . implode( "','", (array)$options ) ."'";1591 1592 if ( is_multisite() )1593 $meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys}) AND site_id = {$wpdb->siteid}" );1594 else1595 $meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );1596 1597 $site_options = array();1598 if ( !empty( $meta ) ) {1599 foreach( (array)$meta as $meta_item )1600 $site_options[$meta_item->name] = $meta_item->value;1601 }1602 1603 return apply_filters( 'bp_core_get_site_options', $site_options );1604 1584 } 1605 1585 … … 2164 2144 $new_page_ids[$slug] = wp_insert_post( array( 'post_title' => ucwords( $slug ), 'post_status' => 'publish', 'post_type' => 'page' ) ); 2165 2145 2166 $page_ids = get_site_option( 'bp-pages' ); 2146 $page_ids = bp_core_get_page_meta(); 2147 2167 2148 $page_ids = (array) $page_ids; 2168 2149 $page_ids = array_merge( (array) $new_page_ids, (array) $page_ids ); 2169 update_site_option( 'bp-pages', $page_ids ); 2150 2151 bp_core_update_page_meta( $page_ids ); 2170 2152 } 2171 2153 ?> -
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 ?> -
trunk/bp-loader.php
r3315 r3463 77 77 } 78 78 79 /** 80 * bp_core_get_site_options() 81 * 82 * BuddyPress uses site options to store configuration settings. Many of these settings are needed 83 * at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch 84 * them all in one go. 85 * 86 * @package BuddyPress Core 87 */ 88 function bp_core_get_site_options() { 89 global $bp, $wpdb; 90 91 $options = apply_filters( 'bp_core_site_options', array( 92 'bp-deactivated-components', 93 'bp-blogs-first-install', 94 'bp-disable-blog-forum-comments', 95 'bp-xprofile-base-group-name', 96 'bp-xprofile-fullname-field-name', 97 'bp-disable-profile-sync', 98 'bp-disable-avatar-uploads', 99 'bp-disable-account-deletion', 100 'bp-disable-forum-directory', 101 'bp-disable-blogforum-comments', 102 'bb-config-location', 103 'hide-loggedout-adminbar', 104 105 /* Useful WordPress settings used often */ 106 'user-avatar-default', 107 'tags_blog_id', 108 'registration', 109 'fileupload_maxk' 110 ) ); 111 112 $meta_keys = "'" . implode( "','", (array)$options ) ."'"; 113 114 if ( is_multisite() ) 115 $meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys}) AND site_id = {$wpdb->siteid}" ); 116 else 117 $meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" ); 118 119 $site_options = array(); 120 if ( !empty( $meta ) ) { 121 foreach( (array)$meta as $meta_item ) 122 $site_options[$meta_item->name] = $meta_item->value; 123 } 124 125 return apply_filters( 'bp_core_get_site_options', $site_options ); 126 } 127 79 128 /* Activation Function */ 80 129 function bp_loader_activate() { … … 85 134 if ( 'bp-sn-parent' == get_blog_option( BP_ROOT_BLOG, 'template' ) && 'bp-default' == get_blog_option( BP_ROOT_BLOG, 'stylesheet' ) ) 86 135 switch_theme( 'bp-default', 'bp-default' ); 87 88 /* Install site options on activation */89 //TODO: Find where to put this back. Here is no good because bp-core.php isn't loaded on new installation.90 //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 ) );91 136 92 137 do_action( 'bp_loader_activate' ); … … 108 153 delete_site_option( 'bp-deactivated-components' ); 109 154 delete_site_option( 'bp-blogs-first-install' ); 110 delete_site_option( 'bp-pages' );111 155 112 156 do_action( 'bp_loader_deactivate' );
Note: See TracChangeset
for help on using the changeset viewer.