From 8b9ce4c5707fa388fe1c582e5c5f5984c6c8211c Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Sun, 7 Jan 2018 14:14:48 +0100 Subject: [PATCH] Fixed issues with multisite installation (#11) --- README.md | 5 ++- RoboFile.php | 2 +- composer.json | 2 +- inc/class-statifyblacklist-system.php | 48 +++++++++++++++++++++++---- inc/class-statifyblacklist.php | 4 +-- package.json | 2 +- statify-blacklist.php | 2 +- 7 files changed, 51 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a987826..0d38889 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ The plugin is capable of handling multisite installations. ### Requirements ### * PHP 5.5 or above * WordPress 4.4 or above -* Statify plugin installed and activated (tested up to 1.5.1) +* Statify plugin installed and activated (tested up to 1.5.4) ## Frequently Asked Questions ## @@ -82,6 +82,9 @@ Because of this, an IP blacklist can only be applied while processing the reques ## Changelog ## +### 1.4.3 / unreleased ### +* Fix issues with multisite installation (#11) + ### 1.4.2 / 12.11.2017 ### * Minor code fixes diff --git a/RoboFile.php b/RoboFile.php index 14d94b8..1c391d0 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -8,7 +8,7 @@ * @author Stefan Kalscheuer * * @package Statify_Blacklist - * @version 1.4.2 + * @version 1.4.3-alpha */ use Robo\Exception\TaskException; diff --git a/composer.json b/composer.json index 3742519..3d88607 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "stklcode/statify-blacklist", - "version": "1.4.2", + "version": "1.4.3-alpha", "description": "A blacklist extension for the famous Statify WordPress plugin", "keywords": [ "wordpress", diff --git a/inc/class-statifyblacklist-system.php b/inc/class-statifyblacklist-system.php index 7dac2f0..5ed0d9d 100644 --- a/inc/class-statifyblacklist-system.php +++ b/inc/class-statifyblacklist-system.php @@ -39,11 +39,12 @@ class StatifyBlacklist_System extends StatifyBlacklist { } foreach ( $sites as $site ) { - switch_to_blog( $site['blog_id'] ); - add_option( - 'statify-blacklist', - self::default_options() - ); + if ( is_array( $site ) ) { + $site_id = $site['blog_id']; + } else { + $site_id = $site->blog_id; + } + self::install_site( $site_id ); } restore_current_blog(); @@ -55,6 +56,22 @@ class StatifyBlacklist_System extends StatifyBlacklist { } } + /** + * Set up the plugin for a single site on Multisite. + * + * @since 1.4.3 + * + * @param integer $site_id Site ID. + */ + public static function install_site( $site_id ) { + switch_to_blog( (int) $site_id ); + add_option( + 'statify-blacklist', + self::default_options() + ); + restore_current_blog(); + } + /** * Plugin uninstall handler. @@ -75,8 +92,12 @@ class StatifyBlacklist_System extends StatifyBlacklist { } foreach ( $sites as $site ) { - switch_to_blog( $site['blog_id'] ); - delete_option( 'statify-blacklist' ); + if ( is_array( $site ) ) { + $site_id = $site['blog_id']; + } else { + $site_id = $site->blog_id; + } + self::uninstall_site( $site_id ); } switch_to_blog( $old ); @@ -85,6 +106,19 @@ class StatifyBlacklist_System extends StatifyBlacklist { delete_option( 'statify-blacklist' ); } + /** + * Remove the plugin for a single site on Multisite. + * + * @since 1.4.3 + * + * @param integer $site_id Site ID. + */ + public static function uninstall_site( $site_id ) { + $old = get_current_blog_id(); + switch_to_blog( (int) $site_id ); + delete_option( 'statify-blacklist' ); + switch_to_blog( $old ); + } /** * Upgrade plugin options. diff --git a/inc/class-statifyblacklist.php b/inc/class-statifyblacklist.php index 58ef305..a1c93cc 100644 --- a/inc/class-statifyblacklist.php +++ b/inc/class-statifyblacklist.php @@ -90,8 +90,8 @@ class StatifyBlacklist { load_plugin_textdomain( 'statifyblacklist', false, STATIFYBLACKLIST_DIR . '/lang/' ); // Add actions. - add_action( 'wpmu_new_blog', array( 'StatifyBlacklist_Install', 'init_site' ) ); - add_action( 'delete_blog', array( 'StatifyBlacklist_System', 'init_site' ) ); + add_action( 'wpmu_new_blog', array( 'StatifyBlacklist_System', 'install_site' ) ); + add_action( 'delete_blog', array( 'StatifyBlacklist_System', 'uninstall_site' ) ); add_filter( 'plugin_row_meta', array( 'StatifyBlacklist_Admin', 'plugin_meta_link' ), 10, 2 ); if ( is_multisite() ) { diff --git a/package.json b/package.json index 5d3a76c..dcfd51d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "statify-blacklist", - "version": "1.4.2", + "version": "1.4.3-alpha", "description": "A blacklist extension for the famous Statify WordPress plugin", "author": "Stefan Kalscheuer", "license": "GPL-2.0+", diff --git a/statify-blacklist.php b/statify-blacklist.php index 9d322c2..2c76301 100644 --- a/statify-blacklist.php +++ b/statify-blacklist.php @@ -10,7 +10,7 @@ * Plugin Name: Statify Blacklist * Plugin URI: https://wordpress.org/plugins/statify-blacklist/ * Description: Extension for the Statify plugin to add a customizable blacklists. - * Version: 1.4.2 + * Version: 1.4.3-alpha * Author: Stefan Kalscheuer (@stklcode) * Author URI: https://www.stklcode.de * Text Domain: statify-blacklist