diff --git a/includes/class-activator.php b/includes/class-activator.php index 517c05cd..603dd775 100644 --- a/includes/class-activator.php +++ b/includes/class-activator.php @@ -70,15 +70,27 @@ public static function update_options() { * @return void */ public static function install() { - $db_version = get_option( 'wp_notifications_db_version' ); + global $wpdb; - if ( ! $db_version ) { - self::create_tables(); - update_option( 'wp_notifications_db_version', '1' ); + // Engage multisite if in the middle of turning it on from network.php. + $is_multisite = is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ); + + if ( $is_multisite ) { + // Get all blogs in the network and uninstall the plugin on each one. + $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); + // Loop over the individual sites and create tables for each. + + foreach ( $blog_ids as $blog_id ) { + switch_to_blog( $blog_id ); + + self::create_tables(); + + restore_current_blog(); + } } - // If the options do not exist then create them - self::update_options(); + // Always create the main site database tables and options. + self::create_tables(); } /** @@ -97,24 +109,15 @@ public static function activate() { * @return void */ protected static function create_tables() { - global $wpdb; - - // Engage multisite if in the middle of turning it on from network.php. - $is_multisite = is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ); + $db_version = get_option( 'wp_notifications_db_version' ); - if ( $is_multisite ) { - // Get all blogs in the network and uninstall the plugin on each one. - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); - // Loop over the individual sites and create tables for each. - foreach ( $blog_ids as $blog_id ) { - switch_to_blog( $blog_id ); - self::create_tables_v1(); - restore_current_blog(); - } + if ( ! $db_version ) { + self::create_tables_v1(); + update_option( 'wp_notifications_db_version', WP_NOTIFICATION_CENTER_DB_VERSION ); } - // Always create a main tables for the main site. - self::create_tables_v1(); + // If the options do not exist then create them + self::update_options(); } /** diff --git a/includes/class-uninstaller.php b/includes/class-uninstaller.php index 5fabb6bf..4327d700 100644 --- a/includes/class-uninstaller.php +++ b/includes/class-uninstaller.php @@ -40,13 +40,18 @@ public static function uninstall() { if ( $is_multisite ) { // Get all blogs in the network and uninstall the plugin on each one. $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); + foreach ( $blog_ids as $blog_id ) { switch_to_blog( $blog_id ); + self::drop_tables(); + self::delete_options(); + restore_current_blog(); } } + // Always remove the main site database tables and options. self::drop_tables(); self::delete_options(); } diff --git a/wp-feature-notifications.php b/wp-feature-notifications.php index 66115054..7f2f9b51 100644 --- a/wp-feature-notifications.php +++ b/wp-feature-notifications.php @@ -25,6 +25,10 @@ define( 'WP_NOTIFICATION_CENTER_PLUGIN_VERSION', '0.0.1' ); } +if ( ! defined( 'WP_NOTIFICATION_CENTER_DB_VERSION' ) ) { + define( 'WP_NOTIFICATION_CENTER_DB_VERSION', '1' ); +} + if ( ! defined( 'WP_NOTIFICATIONS_DEBUG' ) ) { define( 'WP_NOTIFICATIONS_DEBUG', false ); }