database_version < 1801 )
$this->update_1_5();
// Update the active components option early if we're updating
if ( 'update' == $this->setup_type )
bp_update_option( 'bp-active-components', $bp->active_components );
return true;
}
return false;
}
function step_ms_update_save() {
global $wpdb;
if ( isset( $_POST['submit'] ) ) {
check_admin_referer( 'bpwizard_ms_update' );
if ( !$active_components = bp_get_option( 'bp-active-components' ) )
$active_components = array();
// Transfer important settings from blog options to site options
$options = array(
'bp-db-version' => $this->database_version,
'bp-active-components' => $active_components,
'avatar-default' => get_option( 'avatar-default' )
);
bp_core_activate_site_options( $options );
if ( isset( $_POST['bp_components']['blogs'] ) ) {
$active_components['blogs'] = 1;
// Make sure that the pages are created on the bp_get_root_blog_id(), no matter which Dashboard the setup is being run on
if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
switch_to_blog( bp_get_root_blog_id() );
// Move bp-pages data from the blog options table to site options
$existing_pages = bp_get_option( 'bp-pages' );
$bp_pages = $this->setup_pages( (array)$_POST['bp_pages'] );
$bp_pages = array_merge( (array)$existing_pages, (array)$bp_pages );
bp_update_option( 'bp-pages', $bp_pages );
if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
restore_current_blog();
bp_core_install( $active_components );
}
bp_update_option( 'bp-active-components', $active_components );
return true;
}
return false;
}
function step_components_save() {
if ( isset( $_POST['submit'] ) && isset( $_POST['bp_components'] ) ) {
check_admin_referer( 'bpwizard_components' );
$active_components = array();
// Settings form submitted, now save the settings.
foreach ( (array)$_POST['bp_components'] as $key => $value )
$active_components[$key] = 1;
bp_update_option( 'bp-active-components', $active_components );
wp_cache_flush();
bp_core_install();
return true;
}
return false;
}
function step_pages_save() {
global $wpdb;
if ( isset( $_POST['submit'] ) && isset( $_POST['bp_pages'] ) ) {
check_admin_referer( 'bpwizard_pages' );
// Make sure that the pages are created on the bp_get_root_blog_id(), no matter which Dashboard the setup is being run on
if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
switch_to_blog( bp_get_root_blog_id() );
// Delete any existing pages
$existing_pages = bp_core_update_get_page_meta( 'bp-pages' );
foreach ( (array)$existing_pages as $page_id )
wp_delete_post( $page_id, true );
$blog_pages = $this->setup_pages( (array)$_POST['bp_pages'] );
bp_update_option( 'bp-pages', $blog_pages );
if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
restore_current_blog();
return true;
}
return false;
}
function step_permalinks_save() {
global $wp_rewrite, $current_site, $current_blog;
// Prevent debug notices
$iis7_permalinks = $usingpi = $writable = false;
if ( isset( $_POST['submit'] ) ) {
check_admin_referer( 'bpwizard_permalinks' );
$home_path = get_home_path();
$iis7_permalinks = iis7_supports_permalinks();
if ( isset( $_POST['permalink_structure'] ) ) {
$permalink_structure = $_POST['permalink_structure'];
if ( !empty( $permalink_structure ) )
$permalink_structure = preg_replace( '#/+#', '/', '/' . $_POST['permalink_structure'] );
if ( ( defined( 'VHOST' ) && constant( 'VHOST' ) == 'no' ) && $permalink_structure != '' && $current_site->domain . $current_site->path == $current_blog->domain . $current_blog->path )
$permalink_structure = '/blog' . $permalink_structure;
$wp_rewrite->set_permalink_structure( $permalink_structure );
}
if ( !empty( $iis7_permalinks ) ) {
if ( ( !file_exists( $home_path . 'web.config' ) && win_is_writable( $home_path ) ) || win_is_writable( $home_path . 'web.config' ) ) {
$writable = true;
}
} else {
if ( ( !file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) {
$writable = true;
}
}
if ( $wp_rewrite->using_index_permalinks() )
$usingpi = true;
$wp_rewrite->flush_rules();
if ( !empty( $iis7_permalinks ) || ( empty( $usingpi ) && empty( $writable ) ) ) {
function _bp_core_wizard_step_permalinks_message() {
global $wp_rewrite; ?>
web.config file were writable, we could do this automatically, but it isn’t so this is the url rewrite rule you should have in your web.config file. Click in the field and press CTRL + a to select all. Then insert this rule inside of the /<configuration>/<system.webServer>/<rewrite>/<rules> element in web.config file.' ); ?>
.htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press CTRL + a to select all.' ); ?>
.htaccess file in the root of your WordPress installation and save the file. Once you\'re done, please hit the "Save and Next" button to continue.', 'buddypress' );
?>
$plugin ) {
if ( 'BuddyPress Template Pack' == $plugin['Name'] ) {
activate_plugin( $key );
}
}
break;
// Pick a theme from the repo
case '3rd_party' :
if ( empty( $_POST['3rd_party_theme'] ) )
return false;
$theme = explode( ',', $_POST['3rd_party_theme'] );
switch_theme( $theme[0], $theme[1] );
break;
// Keep existing theme
case 'do_not_change' :
return true;
break;
}
if ( is_multisite() )
restore_current_blog();
return true;
}
return false;
}
function step_finish_save() {
if ( isset( $_POST['submit'] ) ) {
check_admin_referer( 'bpwizard_finish' );
// Update the DB version in the database
// Stored in sitemeta. Do not use bp_update_option()
update_site_option( 'bp-db-version', $this->new_version );
delete_site_option( 'bp-core-db-version' );
// Delete the setup cookie
@setcookie( 'bp-wizard-step', '', time() - 3600, COOKIEPATH );
// Load BP and hook the admin menu, so that the redirect is successful
if ( !function_exists( 'bp_core_update_message' ) )
require( WP_PLUGIN_DIR . '/buddypress/bp-core/admin/bp-core-admin.php' );
bp_core_add_admin_menu();
// Redirect to the BuddyPress dashboard
$redirect = bp_core_update_do_network_admin() ? add_query_arg( array( 'page' => 'bp-general-settings' ), network_admin_url( 'admin.php' ) ) : add_query_arg( array( 'page' => 'bp-general-settings' ), admin_url( 'admin.php' ) );
wp_redirect( $redirect );
return true;
}
return false;
}
function setup_pages( $pages ) {
foreach ( $pages as $key => $value ) {
if ( 'page' == $value ) {
// Check for the selected page
if ( !empty( $_POST['bp-' . $key . '-page'] ) )
$bp_pages[$key] = (int)$_POST['bp-' . $key . '-page'];
else
$bp_pages[$key] = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords( $key ), 'post_status' => 'publish', 'post_type' => 'page' ) );
} else {
// Create a new page
$bp_pages[$key] = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords( $value ), 'post_status' => 'publish', 'post_type' => 'page' ) );
}
}
return $bp_pages;
}
// Database update methods based on version numbers
function update_1_5() {
// Delete old database version options
delete_site_option( 'bp-activity-db-version' );
delete_site_option( 'bp-blogs-db-version' );
delete_site_option( 'bp-friends-db-version' );
delete_site_option( 'bp-groups-db-version' );
delete_site_option( 'bp-messages-db-version' );
delete_site_option( 'bp-xprofile-db-version' );
}
/**
* Reset the cookie so the install script starts over
*/
function reset_cookie() {
@setcookie( 'bp-wizard-step', '', time() - 3600, COOKIEPATH );
}
}
function bp_core_setup_wizard_init() {
global $bp_wizard;
$bp_wizard = new BP_Core_Setup_Wizard;
}
add_action( bp_core_update_admin_hook(), 'bp_core_setup_wizard_init', 7 );
function bp_core_install( $active_components = false ) {
global $wpdb;
if ( empty( $active_components ) )
$active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
require( dirname( __FILE__ ) . '/bp-core-schema.php' );
// Core DB Tables
bp_core_install_notifications();
// Activity Streams
if ( !empty( $active_components['activity'] ) )
bp_core_install_activity_streams();
// Friend Connections
if ( !empty( $active_components['friends'] ) )
bp_core_install_friends();
// Extensible Groups
if ( !empty( $active_components['groups'] ) )
bp_core_install_groups();
// Private Messaging
if ( !empty( $active_components['messages'] ) )
bp_core_install_private_messaging();
// Extended Profiles
if ( !empty( $active_components['xprofile'] ) )
bp_core_install_extended_profiles();
// Blog tracking
if ( !empty( $active_components['blogs'] ) )
bp_core_install_blog_tracking();
}
function bp_core_update( $disabled ) {
global $wpdb;
require( dirname( __FILE__ ) . '/bp-core-schema.php' );
}
function bp_update_db_stuff() {
$bp_prefix = bp_core_get_table_prefix();
// Rename the old user activity cached table if needed.
if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp_prefix}bp_activity_user_activity_cached%'" ) )
$wpdb->query( "RENAME TABLE {$bp_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
// Rename fields from pre BP 1.2
if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) {
if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'" ) )
$wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL" );
if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'" ) )
$wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL" );
}
// On first installation - record all existing blogs in the system.
if ( !(int)$bp->site_options['bp-blogs-first-install'] ) {
bp_blogs_record_existing_blogs();
bp_update_option( 'bp-blogs-first-install', 1 );
}
if ( is_multisite() )
bp_core_add_illegal_names();
// Update and remove the message threads table if it exists
if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp_prefix}bp_messages_threads%'" ) ) {
$update = BP_Messages_Thread::update_tables();
if ( $update )
$wpdb->query( "DROP TABLE {$bp_prefix}bp_messages_threads" );
}
}
function bp_core_wizard_message() {
if ( isset( $_GET['updated'] ) )
$message = __( 'Installation was successful. The available options have now been updated, please continue with your selection.', 'buddypress' );
else
return false; ?>