Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
b8b1dc83de | |||
5956059327 | |||
c2ad908481 | |||
9e3dc8fb86 | |||
8b9ce4c570 | |||
8a35182d81 | |||
0b7c9c07e2 | |||
d82de3547b |
@ -7,9 +7,6 @@ php:
|
||||
- '7.1'
|
||||
- '7.2'
|
||||
before_script:
|
||||
- composer install --no-interaction
|
||||
- vendor/bin/phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs
|
||||
- composer install
|
||||
script:
|
||||
- vendor/bin/phpunit ./test/statifyblacklist-test.php
|
||||
- vendor/bin/phpcs statify-blacklist.php --standard=phpcs.xml
|
||||
- vendor/bin/phpcs ./inc/ --standard=phpcs.xml --extensions=php
|
||||
- composer test-all
|
||||
|
@ -30,11 +30,15 @@ gulp.task('test', ['compose'], function () {
|
||||
|
||||
// Execute PHP Code Sniffer.
|
||||
gulp.task('test-cs', function (cb) {
|
||||
return exec('./vendor/bin/phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs', function (err, stdout, stderr) {
|
||||
return exec('./vendor/bin/phpcs --config-set installed_paths vendor/wimg/php-compatibility,vendor/wp-coding-standards/wpcs', function (err, stdout, stderr) {
|
||||
console.log(stdout);
|
||||
console.log(stderr);
|
||||
if (null === err) {
|
||||
console.log('Running PHP Code Sniffer tests ...');
|
||||
// exec('./vendor/bin/phpcs --standard=phpcs.xml', function(err, stdout, stderr) {
|
||||
// console.log(stdout);
|
||||
// console.log(stderr);
|
||||
// });
|
||||
gulp.src(['statify-blacklist.php', 'inc/**/*.php'])
|
||||
.pipe(phpcs({bin: './vendor/bin/phpcs', standard: 'phpcs.xml'}))
|
||||
.pipe(phpcs.reporter('log'));
|
||||
@ -46,7 +50,7 @@ gulp.task('test-cs', function (cb) {
|
||||
// Bundle files as required for plugin distribution..
|
||||
gulp.task('bundle', ['clean'], function () {
|
||||
console.log('Collecting files for package dist/' + config.name + config.version + ' ...');
|
||||
return gulp.src(['**/*.php', '!test/**', '!vendor/**', 'README.md', 'LICENSE.md'], {base: './'})
|
||||
return gulp.src(['**/*.php', '!RoboFile.php', '!test/**', '!vendor/**', 'README.md', 'LICENSE.md'], {base: './'})
|
||||
.pipe(copy('./dist/' + config.name + '.' + config.version + '/' + config.name));
|
||||
});
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
* Requires at least: 4.4
|
||||
* Tested up to: 4.9
|
||||
* Requires PHP: 5.5
|
||||
* Stable tag: 1.4.2
|
||||
* Stable tag: 1.4.3
|
||||
* License: GPLv2 or later
|
||||
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
@ -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 / 09.01.2018 ###
|
||||
* Fix issues with multisite installation (#11)
|
||||
|
||||
### 1.4.2 / 12.11.2017 ###
|
||||
* Minor code fixes
|
||||
|
||||
|
388
RoboFile.php
Normal file
388
RoboFile.php
Normal file
@ -0,0 +1,388 @@
|
||||
<?php
|
||||
/**
|
||||
* Statify Blacklist Robo build script.
|
||||
*
|
||||
* This file contains the Robo tasks for building a distributable plugin package.
|
||||
* Should not be included in final package.
|
||||
*
|
||||
* @author Stefan Kalscheuer <stefan@stklcode.de>
|
||||
*
|
||||
* @package Statify_Blacklist
|
||||
* @version 1.4.3
|
||||
*/
|
||||
|
||||
use Robo\Exception\TaskException;
|
||||
use Robo\Tasks;
|
||||
|
||||
/**
|
||||
* Class RoboFile
|
||||
*/
|
||||
class RoboFile extends Tasks {
|
||||
const PROJECT_NAME = 'statify-blacklist';
|
||||
const SVN_URL = 'https://plugins.svn.wordpress.org/statify-blacklist';
|
||||
|
||||
const OPT_TARGET = 'target';
|
||||
const OPT_SKIPTEST = 'skipTests';
|
||||
const OPT_SKIPSTYLE = 'skipStyle';
|
||||
|
||||
/**
|
||||
* Version tag (read from composer.json).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* Target directory path.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $target_dir;
|
||||
|
||||
/**
|
||||
* Final package name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $final_name;
|
||||
|
||||
/**
|
||||
* RoboFile constructor
|
||||
*
|
||||
* @param array $opts Options.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $opts = [ self::OPT_TARGET => 'dist' ] ) {
|
||||
// Read composer configuration and extract version number..
|
||||
$composer = json_decode( file_get_contents( __DIR__ . '/composer.json' ) );
|
||||
// Extract parameter from options.
|
||||
$this->version = $composer->version;
|
||||
$this->target_dir = $opts[ self::OPT_TARGET ];
|
||||
$this->final_name = self::PROJECT_NAME . '.' . $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up target directory
|
||||
*
|
||||
* @param array $opts Options.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clean( $opts = [ self::OPT_TARGET => 'dist' ] ) {
|
||||
$this->say( 'Cleaning target directory...' );
|
||||
if ( is_dir( $this->target_dir . '/' . $this->final_name ) ) {
|
||||
$this->_deleteDir( [ $this->target_dir . '/' . $this->final_name ] );
|
||||
}
|
||||
if ( is_file( $this->target_dir . '/' . $this->final_name . '.zip' ) ) {
|
||||
$this->_remove( $this->target_dir . '/' . $this->final_name . '.zip' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run PHPUnit tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test() {
|
||||
$this->say( 'Executing PHPUnit tests...' );
|
||||
$this->taskPhpUnit()->configFile( __DIR__ . '/phpunit.xml' )->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run code style tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCS() {
|
||||
$this->say( 'Executing PHPCS tests...' );
|
||||
$this->_exec( __DIR__ . '/vendor/bin/phpcs --standard=phpcs.xml -s' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a distributable bundle.
|
||||
*
|
||||
* @param array $opts Options.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function build(
|
||||
$opts = [
|
||||
self::OPT_TARGET => 'dist',
|
||||
self::OPT_SKIPTEST => false,
|
||||
self::OPT_SKIPSTYLE => false,
|
||||
]
|
||||
) {
|
||||
$this->clean( $opts );
|
||||
if ( isset( $opts[ self::OPT_SKIPTEST ] ) && true === $opts[ self::OPT_SKIPTEST ] ) {
|
||||
$this->say( 'Tests skipped' );
|
||||
} else {
|
||||
$this->test();
|
||||
}
|
||||
if ( isset( $opts[ self::OPT_SKIPSTYLE ] ) && true === $opts[ self::OPT_SKIPSTYLE ] ) {
|
||||
$this->say( 'Style checks skipped' );
|
||||
} else {
|
||||
$this->testCS();
|
||||
}
|
||||
$this->bundle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Bundle global resources.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function bundle() {
|
||||
$this->say( 'Bundling resources...' );
|
||||
$this->taskCopyDir( [
|
||||
'inc' => $this->target_dir . '/' . $this->final_name . '/inc',
|
||||
'views' => $this->target_dir . '/' . $this->final_name . '/views',
|
||||
] )->run();
|
||||
$this->_copy( 'statify-blacklist.php', $this->target_dir . '/' . $this->final_name . '/statify-blacklist.php' );
|
||||
$this->_copy( 'README.md', $this->target_dir . '/' . $this->final_name . '/README.md' );
|
||||
$this->_copy( 'LICENSE.md', $this->target_dir . '/' . $this->final_name . '/LICENSE.md' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create ZIP package from distribution bundle.
|
||||
*
|
||||
* @param array $opts Options.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function package(
|
||||
$opts = [
|
||||
self::OPT_TARGET => 'dist',
|
||||
self::OPT_SKIPTEST => false,
|
||||
self::OPT_SKIPSTYLE => false,
|
||||
]
|
||||
) {
|
||||
$this->build( $opts );
|
||||
$this->say( 'Packaging...' );
|
||||
$this->taskPack( $this->target_dir . '/' . $this->final_name . '.zip' )
|
||||
->addDir( '', $this->target_dir . '/' . $this->final_name )
|
||||
->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy development version (trunk).
|
||||
*
|
||||
* @param array $opts Options.
|
||||
*
|
||||
* @return void
|
||||
* @throws TaskException On errors.
|
||||
*/
|
||||
public function deployTrunk(
|
||||
$opts = [
|
||||
self::OPT_TARGET => 'dist',
|
||||
self::OPT_SKIPTEST => false,
|
||||
self::OPT_SKIPSTYLE => false,
|
||||
]
|
||||
) {
|
||||
// First execute build job.
|
||||
$this->build( $opts );
|
||||
|
||||
// Prepare VCS, either checkout or update local copy.
|
||||
$this->prepareVCS();
|
||||
|
||||
$this->say( 'Preparing deployment directory...' );
|
||||
$this->updateVCStrunk();
|
||||
|
||||
// Update remote repository.
|
||||
$this->say( 'Deploying...' );
|
||||
$this->commitVCS(
|
||||
'--force trunk/*',
|
||||
'Updated ' . self::PROJECT_NAME . ' trunk'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy current version tag.
|
||||
*
|
||||
* @param array $opts Options.
|
||||
*
|
||||
* @return void
|
||||
* @throws TaskException On errors.
|
||||
*/
|
||||
public function deployTag(
|
||||
$opts = [
|
||||
self::OPT_TARGET => 'dist',
|
||||
self::OPT_SKIPTEST => false,
|
||||
self::OPT_SKIPSTYLE => false,
|
||||
]
|
||||
) {
|
||||
// First execute build job.
|
||||
$this->build( $opts );
|
||||
|
||||
// Prepare VCS, either checkout or update local copy.
|
||||
$this->prepareVCS();
|
||||
|
||||
$this->say( 'Preparing deployment directory...' );
|
||||
$this->updateVCStag();
|
||||
|
||||
// Update remote repository.
|
||||
$this->say( 'Deploying...' );
|
||||
$this->commitVCS(
|
||||
'tags/' . $this->version,
|
||||
'Updated ' . self::PROJECT_NAME . ' v' . $this->version
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy current version tag.
|
||||
*
|
||||
* @param array $opts Options.
|
||||
*
|
||||
* @return void
|
||||
* @throws TaskException On errors.
|
||||
*/
|
||||
public function deployReadme(
|
||||
$opts = [
|
||||
self::OPT_TARGET => 'dist',
|
||||
self::OPT_SKIPTEST => false,
|
||||
self::OPT_SKIPSTYLE => false,
|
||||
]
|
||||
) {
|
||||
// First execute build job.
|
||||
$this->build( $opts );
|
||||
|
||||
// Prepare VCS, either checkout or update local copy.
|
||||
$this->prepareVCS();
|
||||
|
||||
$this->updateVCSreadme();
|
||||
|
||||
// Update remote repository.
|
||||
$this->say( 'Deploying...' );
|
||||
$this->commitVCS(
|
||||
'--force trunk/README.md',
|
||||
'Updated ' . self::PROJECT_NAME . ' ReadMe'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy current version tag and trunk.
|
||||
*
|
||||
* @param array $opts Options.
|
||||
*
|
||||
* @return void
|
||||
* @throws TaskException On errors.
|
||||
*/
|
||||
public function deployAll(
|
||||
$opts = [
|
||||
self::OPT_TARGET => 'dist',
|
||||
self::OPT_SKIPTEST => false,
|
||||
self::OPT_SKIPSTYLE => false,
|
||||
]
|
||||
) {
|
||||
// First execute build job.
|
||||
$this->build( $opts );
|
||||
|
||||
// Prepare VCS, either checkout or update local copy.
|
||||
$this->prepareVCS();
|
||||
|
||||
$this->say( 'Preparing deployment directory...' );
|
||||
$this->updateVCStrunk();
|
||||
$this->updateVCStag();
|
||||
|
||||
// Update remote repository.
|
||||
$this->say( 'Deploying...' );
|
||||
$this->commitVCS(
|
||||
[
|
||||
'--force trunk/*',
|
||||
'--force tags/' . $this->version,
|
||||
],
|
||||
'Updated ' . self::PROJECT_NAME . ' v' . $this->version
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare VCS direcory.
|
||||
*
|
||||
* Checkout or update local copy of SVN repository.
|
||||
*
|
||||
* @return void
|
||||
* @throws TaskException On errors.
|
||||
*/
|
||||
private function prepareVCS() {
|
||||
if ( is_dir( $this->target_dir . '/svn' ) ) {
|
||||
$this->taskSvnStack()
|
||||
->stopOnFail()
|
||||
->dir( $this->target_dir . '/svn/statify-blacklist' )
|
||||
->update()
|
||||
->run();
|
||||
} else {
|
||||
$this->_mkdir( $this->target_dir . '/svn' );
|
||||
$this->taskSvnStack()
|
||||
->dir( $this->target_dir . '/svn' )
|
||||
->checkout( self::SVN_URL )
|
||||
->run();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit VCS changes
|
||||
*
|
||||
* @param string|array $to_add Files to add.
|
||||
* @param string $msg Commit message.
|
||||
*
|
||||
* @return void
|
||||
* @throws TaskException On errors.
|
||||
*/
|
||||
private function commitVCS( $to_add, $msg ) {
|
||||
$task = $this->taskSvnStack()
|
||||
->stopOnFail()
|
||||
->dir( $this->target_dir . '/svn/statify-blacklist' );
|
||||
|
||||
if ( is_array( $to_add ) ) {
|
||||
foreach ( $to_add as $ta ) {
|
||||
$task = $task->add( $ta );
|
||||
}
|
||||
} else {
|
||||
$task = $task->add( $to_add );
|
||||
}
|
||||
|
||||
$task->commit( $msg )->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update SVN readme file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function updateVCSreadme() {
|
||||
$trunk_dir = $this->target_dir . '/svn/statify-blacklist/trunk';
|
||||
$this->_copy( $this->target_dir . '/' . $this->final_name . 'README.md', $trunk_dir . 'README.md' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update SVN development version (trunk).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function updateVCStrunk() {
|
||||
// Clean trunk directory.
|
||||
$trunk_dir = $this->target_dir . '/svn/statify-blacklist/trunk';
|
||||
$this->taskCleanDir( $trunk_dir )->run();
|
||||
|
||||
// Copy built bundle to trunk.
|
||||
$this->taskCopyDir( [ $this->target_dir . '/' . $this->final_name => $trunk_dir ] )->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update current SVN version tag.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function updateVCStag() {
|
||||
// Clean tag directory if it exists.
|
||||
$tag_dir = $this->target_dir . '/svn/statify-blacklist/tags/' . $this->version;
|
||||
if ( is_dir( $tag_dir ) ) {
|
||||
$this->taskCleanDir( $this->target_dir . '/svn/statify-blacklist/tags/' . $this->version )->run();
|
||||
} else {
|
||||
$this->_mkdir( $tag_dir );
|
||||
}
|
||||
|
||||
// Copy built bundle to trunk.
|
||||
$this->taskCopyDir( [ $this->target_dir . '/' . $this->final_name => $tag_dir ] )->run();
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "stklcode/statify-blacklist",
|
||||
"version": "1.4.2",
|
||||
"version": "1.4.3",
|
||||
"description": "A blacklist extension for the famous Statify WordPress plugin",
|
||||
"keywords": [
|
||||
"wordpress",
|
||||
@ -22,9 +22,38 @@
|
||||
"composer/installers": "~1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.4",
|
||||
"php": ">=5.5",
|
||||
"consolidation/robo": "^1.0.0",
|
||||
"phpunit/phpunit": "*",
|
||||
"phpunit/php-code-coverage": "*",
|
||||
"wp-coding-standards/wpcs": "~0.14.0"
|
||||
"slowprog/composer-copy-file": "~0.2",
|
||||
"squizlabs/php_codesniffer": "^3.1",
|
||||
"wimg/php-compatibility": "^8.0",
|
||||
"wp-coding-standards/wpcs": "~0.14"
|
||||
},
|
||||
"scripts": {
|
||||
"build": [
|
||||
"robo build"
|
||||
],
|
||||
"package": [
|
||||
"robo package"
|
||||
],
|
||||
"deploy": [
|
||||
"robo deploy:all"
|
||||
],
|
||||
"test-all": [
|
||||
"@test",
|
||||
"@test-cs"
|
||||
],
|
||||
"test": [
|
||||
"phpunit"
|
||||
],
|
||||
"test-cs": [
|
||||
"phpcs --standard=phpcs.xml -s"
|
||||
],
|
||||
"fix-cs": [
|
||||
"phpcbf --standard=phpcs.xml"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||
}
|
||||
|
||||
// Update database on success.
|
||||
if ( ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) ) ) {
|
||||
if ( self::$multisite ) {
|
||||
update_site_option( 'statify-blacklist', $options );
|
||||
} else {
|
||||
update_option( 'statify-blacklist', $options );
|
||||
|
@ -28,7 +28,7 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
||||
*/
|
||||
public static function install( $network_wide = false ) {
|
||||
// Create tables for each site in a network.
|
||||
if ( is_multisite() && $network_wide ) {
|
||||
if ( $network_wide && is_multisite() ) {
|
||||
if ( function_exists( 'get_sites' ) ) {
|
||||
$sites = get_sites();
|
||||
} elseif ( function_exists( 'wp_get_sites' ) ) {
|
||||
@ -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.
|
||||
@ -98,7 +132,7 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
||||
// Flip referer array to make domains keys.
|
||||
$options = self::$_options;
|
||||
$options['referer'] = array_flip( self::$_options['referer'] );
|
||||
if ( ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) ) ) {
|
||||
if ( self::$multisite ) {
|
||||
update_site_option( 'statify-blacklist', $options );
|
||||
} else {
|
||||
update_option( 'statify-blacklist', $options );
|
||||
@ -127,7 +161,7 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
||||
),
|
||||
'version' => 1.4,
|
||||
);
|
||||
if ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) ) {
|
||||
if ( self::$multisite ) {
|
||||
update_site_option( 'statify-blacklist', $options );
|
||||
} else {
|
||||
update_option( 'statify-blacklist', $options );
|
||||
@ -140,7 +174,7 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
||||
// Merge default options with current config, assuming only additive changes.
|
||||
$options = array_merge_recursive( self::default_options(), self::$_options );
|
||||
$options['version'] = self::VERSION_MAIN;
|
||||
if ( ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) ) ) {
|
||||
if ( self::$multisite ) {
|
||||
update_site_option( 'statify-blacklist', $options );
|
||||
} else {
|
||||
update_option( 'statify-blacklist', $options );
|
||||
|
@ -73,12 +73,12 @@ class StatifyBlacklist {
|
||||
return;
|
||||
}
|
||||
|
||||
// Plugin options.
|
||||
self::update_options();
|
||||
|
||||
// Get multisite status.
|
||||
self::$multisite = ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) );
|
||||
|
||||
// Plugin options.
|
||||
self::update_options();
|
||||
|
||||
// Add Filter to statify hook if enabled.
|
||||
if ( 0 !== self::$_options['referer']['active'] || 0 !== self::$_options['target']['active'] || 0 !== self::$_options['ip']['active'] ) {
|
||||
add_filter( 'statify__skip_tracking', array( 'StatifyBlacklist', 'apply_blacklist_filter' ) );
|
||||
@ -90,11 +90,11 @@ 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() ) {
|
||||
if ( self::$multisite ) {
|
||||
add_action( 'network_admin_menu', array( 'StatifyBlacklist_Admin', 'add_menu_page' ) );
|
||||
add_filter(
|
||||
'network_admin_plugin_action_links', array(
|
||||
@ -127,10 +127,12 @@ class StatifyBlacklist {
|
||||
* @param array $options Optional. New options to save.
|
||||
*/
|
||||
public static function update_options( $options = null ) {
|
||||
self::$_options = wp_parse_args(
|
||||
get_option( 'statify-blacklist' ),
|
||||
self::default_options()
|
||||
);
|
||||
if ( self::$multisite ) {
|
||||
$o = get_site_option( 'statify-blacklist' );
|
||||
} else {
|
||||
$o = get_option( 'statify-blacklist' );
|
||||
}
|
||||
self::$_options = wp_parse_args( $o, self::default_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "statify-blacklist",
|
||||
"version": "1.4.2",
|
||||
"version": "1.4.3",
|
||||
"description": "A blacklist extension for the famous Statify WordPress plugin",
|
||||
"author": "Stefan Kalscheuer",
|
||||
"license": "GPL-2.0+",
|
||||
|
16
phpcs.xml
16
phpcs.xml
@ -2,10 +2,16 @@
|
||||
<ruleset name="StatifyBlacklist">
|
||||
<description>Derived from WordPress Coding Standard</description>
|
||||
|
||||
<rule ref="WordPress">
|
||||
<!-- Type hint checks mess up PHP 7 checks, while this plugin has compatibility level 5.5 and above. -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing"/>
|
||||
<arg value="psvn"/>
|
||||
<arg name="colors"/>
|
||||
|
||||
<!-- Files to sniff -->
|
||||
<file>inc</file>
|
||||
<file>statify-blacklist.php</file>
|
||||
|
||||
<!-- Compliance with WordPress Coding Standard -->
|
||||
<config name="minimum_supported_wp_version" value="4.4"/>
|
||||
<rule ref="WordPress">
|
||||
<!-- The plugin uses switch_to_blog for multisite handling. -->
|
||||
<exclude name="WordPress.VIP.RestrictedFunctions.switch_to_blog"/>
|
||||
<exclude name="WordPress.VIP.RestrictedFunctions.switch_to_blog_switch_to_blog"/>
|
||||
@ -14,4 +20,8 @@
|
||||
<exclude name="WordPress.VIP.DirectDatabaseQuery.DirectQuery"/>
|
||||
<exclude name="WordPress.VIP.DirectDatabaseQuery.NoCaching"/>
|
||||
</rule>
|
||||
|
||||
<!-- PHP compatibility level -->
|
||||
<config name="testVersion" value="5.5-"/>
|
||||
<rule ref="PHPCompatibility"/>
|
||||
</ruleset>
|
||||
|
@ -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
|
||||
* Author: Stefan Kalscheuer (@stklcode)
|
||||
* Author URI: https://www.stklcode.de
|
||||
* Text Domain: statify-blacklist
|
||||
|
@ -51,19 +51,26 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
||||
$statifyblacklist_update_result = StatifyBlacklist_Admin::update_options(
|
||||
array(
|
||||
'referer' => array(
|
||||
'active' => (int) $_POST['statifyblacklist']['referer']['active'],
|
||||
'cron' => (int) $_POST['statifyblacklist']['referer']['cron'],
|
||||
'regexp' => (int) $_POST['statifyblacklist']['referer']['regexp'],
|
||||
'active' => isset( $_POST['statifyblacklist']['referer']['active'] )
|
||||
? (int) $_POST['statifyblacklist']['referer']['active'] : 0,
|
||||
'cron' => isset( $_POST['statifyblacklist']['referer']['cron'] )
|
||||
? (int) $_POST['statifyblacklist']['referer']['cron'] : 0,
|
||||
'regexp' => isset( $_POST['statifyblacklist']['referer']['regexp'] )
|
||||
? (int) $_POST['statifyblacklist']['referer']['regexp'] : 0,
|
||||
'blacklist' => array_flip( $referer ),
|
||||
),
|
||||
'target' => array(
|
||||
'active' => (int) $_POST['statifyblacklist']['target']['active'],
|
||||
'cron' => (int) $_POST['statifyblacklist']['target']['cron'],
|
||||
'regexp' => (int) $_POST['statifyblacklist']['target']['regexp'],
|
||||
'active' => isset( $_POST['statifyblacklist']['target']['active'] )
|
||||
? (int) $_POST['statifyblacklist']['target']['active'] : 0,
|
||||
'cron' => isset( $_POST['statifyblacklist']['target']['cron'] )
|
||||
? (int) $_POST['statifyblacklist']['target']['cron'] : 0,
|
||||
'regexp' => isset( $_POST['statifyblacklist']['target']['regexp'] )
|
||||
? (int) $_POST['statifyblacklist']['target']['regexp'] : 0,
|
||||
'blacklist' => array_flip( $target ),
|
||||
),
|
||||
'ip' => array(
|
||||
'active' => (int) $_POST['statifyblacklist']['ip']['active'],
|
||||
'active' => isset( $_POST['statifyblacklist']['ip']['active'] )
|
||||
? (int) $_POST['statifyblacklist']['ip']['active'] : 0,
|
||||
'blacklist' => $ip,
|
||||
),
|
||||
'version' => StatifyBlacklist::VERSION_MAIN,
|
||||
@ -90,7 +97,7 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
||||
<?php
|
||||
if ( is_plugin_inactive( 'statify/statify.php' ) ) {
|
||||
print '<div class="notice notice-warning"><p>';
|
||||
esc_html( 'Statify plugin is not active.' );
|
||||
esc_html_e( 'Statify plugin is not active.', 'statify-blacklist' );
|
||||
print '</p></div>';
|
||||
}
|
||||
if ( isset( $statifyblacklist_post_warning ) ) {
|
||||
|
Reference in New Issue
Block a user