Skip to content

Instantly share code, notes, and snippets.

@earnjam
Created April 18, 2014 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earnjam/11019679 to your computer and use it in GitHub Desktop.
Save earnjam/11019679 to your computer and use it in GitHub Desktop.
Multisite Problem Example
if ( is_admin() ) {
$this->install(is_multisite() ? true : false); //we run this here because activation hooks aren't triggered when updating - see http://wp.mu/8kv
$this->init_admin_pages();
}
function install( $network_activate ) {
global $wpdb;
// Move wiki_version option from blog table to sitemeta table
if ( $wiki_version = get_option('wiki_version') ) {
update_site_option('wiki_version', $wiki_version);
delete_option('wiki_version');
}
if ( get_site_option('wiki_version', false) == $this->version )
return;
// WordPress database upgrade/creation functions
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
// Get the correct character collate
$charset_collate = '';
if ( ! empty($wpdb->charset) )
$charset_collate .= "DEFAULT CHARSET $wpdb->charset";
if ( ! empty($wpdb->collate) )
$charset_collate .= " COLLATE $wpdb->collate";
// Setup the subscription table
dbDelta("
CREATE TABLE {$this->db_prefix}wiki_subscriptions (
ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
blog_id BIGINT(20) NOT NULL,
wiki_id BIGINT(20) NOT NULL,
user_id BIGINT(20),
email VARCHAR(255),
PRIMARY KEY (ID)
) ENGINE=InnoDB $charset_collate;");
// Setup blog(s)
if ( $network_activate ) {
$results = $wpdb->get_results("
SELECT blog_id
FROM $wpdb->blogs
");
foreach ( $results as $row ) {
$this->setup_blog($row->blog_id);
}
} else {
$this->setup_blog();
}
update_site_option('wiki_version', $this->version);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment