Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
075441d6f3 | |||
92f8496926 | |||
66ddada63e | |||
fcba292698 | |||
1e811957f8 | |||
b9017a7b8d | |||
7329574d09 | |||
b8b1dc83de | |||
5956059327 | |||
c2ad908481 | |||
9e3dc8fb86 | |||
8b9ce4c570 | |||
8a35182d81 | |||
0b7c9c07e2 | |||
d82de3547b |
@ -7,9 +7,6 @@ php:
|
|||||||
- '7.1'
|
- '7.1'
|
||||||
- '7.2'
|
- '7.2'
|
||||||
before_script:
|
before_script:
|
||||||
- composer install --no-interaction
|
- composer install
|
||||||
- vendor/bin/phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs
|
|
||||||
script:
|
script:
|
||||||
- vendor/bin/phpunit ./test/statifyblacklist-test.php
|
- composer test-all
|
||||||
- vendor/bin/phpcs statify-blacklist.php --standard=phpcs.xml
|
|
||||||
- vendor/bin/phpcs ./inc/ --standard=phpcs.xml --extensions=php
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
As for all great Open Source projects, contributions in form of bug reports and code are welcome and important to keep the project alive.
|
As for all great Open Source projects, contributions in form of bug reports and code are welcome and important to keep the project alive.
|
||||||
|
|
||||||
In general, this project follows the [Git Flow](https://guides.github.com/introduction/flow/).
|
In general, this project follows the [GitHub Flow](https://guides.github.com/introduction/flow/).
|
||||||
Fork the project, commit your changes to your branch, open a pull request and it will probably be merged.
|
Fork the project, commit your changes to your branch, open a pull request and it will probably be merged.
|
||||||
However, to ensure maintainability and quality of the code, there are some guidelines you might be more or less familiar with.
|
However, to ensure maintainability and quality of the code, there are some guidelines you might be more or less familiar with.
|
||||||
For that purpose, this document describes the important points.
|
For that purpose, this document describes the important points.
|
||||||
@ -14,7 +14,7 @@ If you experience any issues with the plugin or the code, don't hesitate to file
|
|||||||
### Bug Reports
|
### Bug Reports
|
||||||
|
|
||||||
Think you found a bug?
|
Think you found a bug?
|
||||||
Please clearly state what happens and describe your environment.
|
Please clearly state what happens and describe your environment to help tracking down the issue.
|
||||||
|
|
||||||
* Which version of the plugin are you running?
|
* Which version of the plugin are you running?
|
||||||
* Which version of WordPress?
|
* Which version of WordPress?
|
||||||
@ -31,7 +31,7 @@ No problem, please open an issue and describe what and why you think this change
|
|||||||
If you want to contribute your code to solve an issue or implement a desired feature yourself, you might open a pull request.
|
If you want to contribute your code to solve an issue or implement a desired feature yourself, you might open a pull request.
|
||||||
If the changes introduce new functionality or affect major parts of existing code, please consider opening an issue for discussion first.
|
If the changes introduce new functionality or affect major parts of existing code, please consider opening an issue for discussion first.
|
||||||
|
|
||||||
For adding new functionality a new test case the corresponding PHPUnit test would be nice (no hard criterion).
|
For adding new functionality a new test case the corresponding PHPUnit test would be nice (no hard criterion though).
|
||||||
|
|
||||||
### Branches
|
### Branches
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ The `master` branch represents the current state of development.
|
|||||||
Please ensure your initial code is up to date with it at the time you start development.
|
Please ensure your initial code is up to date with it at the time you start development.
|
||||||
The `master` should also be target for most pull requests.
|
The `master` should also be target for most pull requests.
|
||||||
|
|
||||||
In addition, this project features a `develop` branch, which hold cutting edge developments, not necessarily considered stable or even compatible.
|
In addition, this project features a `develop` branch, which holds bleeding edge developments, not necessarily considered stable or even compatible.
|
||||||
Do not expect this code to run smoothly, but you might have a look into the history to see if some work on an issue has already been started there.
|
Do not expect this code to run smoothly, but you might have a look into the history to see if some work on an issue has already been started there.
|
||||||
|
|
||||||
For fixes and features, there might be additional branches, likely prefixed by `ft-` (feature) or `hf-` (hotfix) followed by an issue number (if applicable) and/or a title.
|
For fixes and features, there might be additional branches, likely prefixed by `ft-` (feature) or `hf-` (hotfix) followed by an issue number (if applicable) and/or a title.
|
||||||
@ -62,7 +62,7 @@ If your patch fixes an issue, reference the ID in the first line.
|
|||||||
If you feel like you have to _briefly_ explain your changes, do it (for long explanations and discussion, consider opening an issue or describe in the PR).
|
If you feel like you have to _briefly_ explain your changes, do it (for long explanations and discussion, consider opening an issue or describe in the PR).
|
||||||
|
|
||||||
**Example commit:**
|
**Example commit:**
|
||||||
```
|
```text
|
||||||
Fix nasty bug from #1337
|
Fix nasty bug from #1337
|
||||||
|
|
||||||
This example commit fixes the issue that some people write non-speaking commit messages like 'done magic'.
|
This example commit fixes the issue that some people write non-speaking commit messages like 'done magic'.
|
||||||
@ -75,7 +75,7 @@ You might sign your work, although that's no must.
|
|||||||
|
|
||||||
Short answer: When it makes sense.
|
Short answer: When it makes sense.
|
||||||
|
|
||||||
Bugfixes should be merges in time - assuming they pass the above criteria.
|
Bugfixes should be merged in time - assuming they pass the above criteria.
|
||||||
New features might be assigned to a certain milestone and as a result of this be scheduled according to the planned release cycle.
|
New features might be assigned to a certain milestone and as a result of this be scheduled according to the planned release cycle.
|
||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
@ -88,9 +88,17 @@ If you are unsure if your code matches these versions, the test will probably te
|
|||||||
In case you think, your change is more important than maintaining backwards compatibility, please start a discussion to see,
|
In case you think, your change is more important than maintaining backwards compatibility, please start a discussion to see,
|
||||||
if we might increase the minimum version or find a workaround for legacy systems.
|
if we might increase the minimum version or find a workaround for legacy systems.
|
||||||
|
|
||||||
|
## Build Environment
|
||||||
|
|
||||||
|
All you need to start off - besides your favorite IDE of course - is [Composer](https://getcomposer.org).
|
||||||
|
Running `composer install` will fetch all dependencies and build tools required.
|
||||||
|
You might have noticed that this project contains a [Robo](http://robo.li) build script.
|
||||||
|
Running the _build_-task (`./vendor/bin/robo build`) executes the full chain from cleanup over test to bundling the final product in the `dist` directory.
|
||||||
|
A complete list of the available tasks and options can be shown by running `robo list`.
|
||||||
|
|
||||||
## Unit Tests
|
## Unit Tests
|
||||||
|
|
||||||
The PHP code is tested by a PHPUnit test.
|
The PHP code is tested by a PHPUnit tests.
|
||||||
All test files are located in the `test` directory.
|
All test files are located in the `test` directory.
|
||||||
Files ending with `-test.php` will be automatically included into the test suite.
|
Files ending with `-test.php` will be automatically included into the test suite.
|
||||||
The coverage is not yet perfect, but be invited to write tests for methods not yet covered or newly introduced by your patch.
|
The coverage is not yet perfect, but be invited to write tests for methods not yet covered or newly introduced by your patch.
|
||||||
@ -102,7 +110,7 @@ Please make sure that you are at least roughly familiar with those guidelines.
|
|||||||
|
|
||||||
The code style is automatically checked for commits (including pull requests) using [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer).
|
The code style is automatically checked for commits (including pull requests) using [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer).
|
||||||
You can check your code against the configured ruleset yourself by running
|
You can check your code against the configured ruleset yourself by running
|
||||||
`./vendor/bin/phpcs --standard=phpcs.xml your-edited-file.php` (assuming `composer install` has been executed).
|
`./vendor/bin/phpcs --standard=phpcs.xml your-edited-file.php` (assuming `composer install` has been executed) or the Robo task `robo test:cs` for a complete scan.
|
||||||
|
|
||||||
Please see these standards as guidelines.
|
Please see these standards as guidelines.
|
||||||
If code style this is the only test that fails and your code's semantics are fine, don't hesitate to submit your pull request anyway.
|
If code style this is the only test that fails and your code's semantics are fine, don't hesitate to submit your pull request anyway.
|
||||||
@ -113,6 +121,9 @@ We probably find a solution for that.
|
|||||||
Automated tests are run using [Travis CI](https://travis-ci.org/stklcode/statify-blacklist) for every commit including pull requests.
|
Automated tests are run using [Travis CI](https://travis-ci.org/stklcode/statify-blacklist) for every commit including pull requests.
|
||||||
They ensure compatibility with the supported PHP versions and the WP Coding Standards.
|
They ensure compatibility with the supported PHP versions and the WP Coding Standards.
|
||||||
|
|
||||||
|
There is also a semi-automated code quality analysis pushing results to [SonarCloud](https://sonarcloud.io/dashboard?id=de.stklcode.web.wordpress.plugins%3Astatify-blacklist).
|
||||||
|
Keep in mind that the ruleset is not yet perfect, so not every minor issue has to be fixed immediately.
|
||||||
|
|
||||||
## Still Open Questions?
|
## Still Open Questions?
|
||||||
|
|
||||||
If anything is still left unanswered and you're unsure if you got it right, don't hesitate to contact a team member.
|
If anything is still left unanswered and you're unsure if you got it right, don't hesitate to contact a team member.
|
||||||
|
@ -30,11 +30,15 @@ gulp.task('test', ['compose'], function () {
|
|||||||
|
|
||||||
// Execute PHP Code Sniffer.
|
// Execute PHP Code Sniffer.
|
||||||
gulp.task('test-cs', function (cb) {
|
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(stdout);
|
||||||
console.log(stderr);
|
console.log(stderr);
|
||||||
if (null === err) {
|
if (null === err) {
|
||||||
console.log('Running PHP Code Sniffer tests ...');
|
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'])
|
gulp.src(['statify-blacklist.php', 'inc/**/*.php'])
|
||||||
.pipe(phpcs({bin: './vendor/bin/phpcs', standard: 'phpcs.xml'}))
|
.pipe(phpcs({bin: './vendor/bin/phpcs', standard: 'phpcs.xml'}))
|
||||||
.pipe(phpcs.reporter('log'));
|
.pipe(phpcs.reporter('log'));
|
||||||
@ -46,7 +50,7 @@ gulp.task('test-cs', function (cb) {
|
|||||||
// Bundle files as required for plugin distribution..
|
// Bundle files as required for plugin distribution..
|
||||||
gulp.task('bundle', ['clean'], function () {
|
gulp.task('bundle', ['clean'], function () {
|
||||||
console.log('Collecting files for package dist/' + config.name + config.version + ' ...');
|
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));
|
.pipe(copy('./dist/' + config.name + '.' + config.version + '/' + config.name));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -358,4 +358,4 @@ you may consider it more useful to permit linking proprietary
|
|||||||
applications with the library. If this is what you want to do, use the
|
applications with the library. If this is what you want to do, use the
|
||||||
[GNU Lesser General Public
|
[GNU Lesser General Public
|
||||||
License](http://www.gnu.org/licenses/lgpl.html) instead of this
|
License](http://www.gnu.org/licenses/lgpl.html) instead of this
|
||||||
License.
|
License.
|
||||||
|
10
README.md
10
README.md
@ -3,7 +3,7 @@
|
|||||||
* Requires at least: 4.4
|
* Requires at least: 4.4
|
||||||
* Tested up to: 4.9
|
* Tested up to: 4.9
|
||||||
* Requires PHP: 5.5
|
* Requires PHP: 5.5
|
||||||
* Stable tag: 1.4.2
|
* Stable tag: 1.4.4
|
||||||
* License: GPLv2 or later
|
* License: GPLv2 or later
|
||||||
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ The plugin is capable of handling multisite installations.
|
|||||||
### Requirements ###
|
### Requirements ###
|
||||||
* PHP 5.5 or above
|
* PHP 5.5 or above
|
||||||
* WordPress 4.4 or above
|
* WordPress 4.4 or above
|
||||||
* Statify plugin installed and activated (tested up to 1.5.1)
|
* Statify plugin installed and activated (1.5.0 or above)
|
||||||
|
|
||||||
## Frequently Asked Questions ##
|
## Frequently Asked Questions ##
|
||||||
|
|
||||||
@ -82,6 +82,12 @@ Because of this, an IP blacklist can only be applied while processing the reques
|
|||||||
|
|
||||||
## Changelog ##
|
## Changelog ##
|
||||||
|
|
||||||
|
### 1.4.4 / 19.05.2018 ###
|
||||||
|
* Fix live filter chain when regular expressions are active (#12)
|
||||||
|
|
||||||
|
### 1.4.3 / 09.01.2018 ###
|
||||||
|
* Fix issues with multisite installation (#11)
|
||||||
|
|
||||||
### 1.4.2 / 12.11.2017 ###
|
### 1.4.2 / 12.11.2017 ###
|
||||||
* Minor code fixes
|
* 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.4
|
||||||
|
*/
|
||||||
|
|
||||||
|
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",
|
"name": "stklcode/statify-blacklist",
|
||||||
"version": "1.4.2",
|
"version": "1.4.4",
|
||||||
"description": "A blacklist extension for the famous Statify WordPress plugin",
|
"description": "A blacklist extension for the famous Statify WordPress plugin",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"wordpress",
|
"wordpress",
|
||||||
@ -8,7 +8,7 @@
|
|||||||
"statistics",
|
"statistics",
|
||||||
"blacklist"
|
"blacklist"
|
||||||
],
|
],
|
||||||
"license": "GPL-2.0+",
|
"license": "GPL-2.0-or-later",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Stefan Kalscheuer",
|
"name": "Stefan Kalscheuer",
|
||||||
@ -22,9 +22,37 @@
|
|||||||
"composer/installers": "~1.0"
|
"composer/installers": "~1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"php": ">=5.5",
|
"dealerdirect/phpcodesniffer-composer-installer": "^0.4",
|
||||||
|
"consolidation/robo": "^1.0.0",
|
||||||
"phpunit/phpunit": "*",
|
"phpunit/phpunit": "*",
|
||||||
"phpunit/php-code-coverage": "*",
|
"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.
|
// 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 );
|
update_site_option( 'statify-blacklist', $options );
|
||||||
} else {
|
} else {
|
||||||
update_option( 'statify-blacklist', $options );
|
update_option( 'statify-blacklist', $options );
|
||||||
|
@ -28,7 +28,7 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
|||||||
*/
|
*/
|
||||||
public static function install( $network_wide = false ) {
|
public static function install( $network_wide = false ) {
|
||||||
// Create tables for each site in a network.
|
// Create tables for each site in a network.
|
||||||
if ( is_multisite() && $network_wide ) {
|
if ( $network_wide && is_multisite() ) {
|
||||||
if ( function_exists( 'get_sites' ) ) {
|
if ( function_exists( 'get_sites' ) ) {
|
||||||
$sites = get_sites();
|
$sites = get_sites();
|
||||||
} elseif ( function_exists( 'wp_get_sites' ) ) {
|
} elseif ( function_exists( 'wp_get_sites' ) ) {
|
||||||
@ -39,11 +39,12 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $sites as $site ) {
|
foreach ( $sites as $site ) {
|
||||||
switch_to_blog( $site['blog_id'] );
|
if ( is_array( $site ) ) {
|
||||||
add_option(
|
$site_id = $site['blog_id'];
|
||||||
'statify-blacklist',
|
} else {
|
||||||
self::default_options()
|
$site_id = $site->blog_id;
|
||||||
);
|
}
|
||||||
|
self::install_site( $site_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_current_blog();
|
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.
|
* Plugin uninstall handler.
|
||||||
@ -75,8 +92,12 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $sites as $site ) {
|
foreach ( $sites as $site ) {
|
||||||
switch_to_blog( $site['blog_id'] );
|
if ( is_array( $site ) ) {
|
||||||
delete_option( 'statify-blacklist' );
|
$site_id = $site['blog_id'];
|
||||||
|
} else {
|
||||||
|
$site_id = $site->blog_id;
|
||||||
|
}
|
||||||
|
self::uninstall_site( $site_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_to_blog( $old );
|
switch_to_blog( $old );
|
||||||
@ -85,6 +106,19 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
|||||||
delete_option( 'statify-blacklist' );
|
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.
|
* Upgrade plugin options.
|
||||||
@ -98,7 +132,7 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
|||||||
// Flip referer array to make domains keys.
|
// Flip referer array to make domains keys.
|
||||||
$options = self::$_options;
|
$options = self::$_options;
|
||||||
$options['referer'] = array_flip( self::$_options['referer'] );
|
$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 );
|
update_site_option( 'statify-blacklist', $options );
|
||||||
} else {
|
} else {
|
||||||
update_option( 'statify-blacklist', $options );
|
update_option( 'statify-blacklist', $options );
|
||||||
@ -127,7 +161,7 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
|||||||
),
|
),
|
||||||
'version' => 1.4,
|
'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 );
|
update_site_option( 'statify-blacklist', $options );
|
||||||
} else {
|
} else {
|
||||||
update_option( 'statify-blacklist', $options );
|
update_option( 'statify-blacklist', $options );
|
||||||
@ -140,7 +174,7 @@ class StatifyBlacklist_System extends StatifyBlacklist {
|
|||||||
// Merge default options with current config, assuming only additive changes.
|
// Merge default options with current config, assuming only additive changes.
|
||||||
$options = array_merge_recursive( self::default_options(), self::$_options );
|
$options = array_merge_recursive( self::default_options(), self::$_options );
|
||||||
$options['version'] = self::VERSION_MAIN;
|
$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 );
|
update_site_option( 'statify-blacklist', $options );
|
||||||
} else {
|
} else {
|
||||||
update_option( 'statify-blacklist', $options );
|
update_option( 'statify-blacklist', $options );
|
||||||
|
@ -73,12 +73,12 @@ class StatifyBlacklist {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin options.
|
|
||||||
self::update_options();
|
|
||||||
|
|
||||||
// Get multisite status.
|
// Get multisite status.
|
||||||
self::$multisite = ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) );
|
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.
|
// Add Filter to statify hook if enabled.
|
||||||
if ( 0 !== self::$_options['referer']['active'] || 0 !== self::$_options['target']['active'] || 0 !== self::$_options['ip']['active'] ) {
|
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' ) );
|
add_filter( 'statify__skip_tracking', array( 'StatifyBlacklist', 'apply_blacklist_filter' ) );
|
||||||
@ -90,11 +90,11 @@ class StatifyBlacklist {
|
|||||||
load_plugin_textdomain( 'statifyblacklist', false, STATIFYBLACKLIST_DIR . '/lang/' );
|
load_plugin_textdomain( 'statifyblacklist', false, STATIFYBLACKLIST_DIR . '/lang/' );
|
||||||
|
|
||||||
// Add actions.
|
// Add actions.
|
||||||
add_action( 'wpmu_new_blog', array( 'StatifyBlacklist_Install', 'init_site' ) );
|
add_action( 'wpmu_new_blog', array( 'StatifyBlacklist_System', 'install_site' ) );
|
||||||
add_action( 'delete_blog', array( 'StatifyBlacklist_System', 'init_site' ) );
|
add_action( 'delete_blog', array( 'StatifyBlacklist_System', 'uninstall_site' ) );
|
||||||
add_filter( 'plugin_row_meta', array( 'StatifyBlacklist_Admin', 'plugin_meta_link' ), 10, 2 );
|
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_action( 'network_admin_menu', array( 'StatifyBlacklist_Admin', 'add_menu_page' ) );
|
||||||
add_filter(
|
add_filter(
|
||||||
'network_admin_plugin_action_links', array(
|
'network_admin_plugin_action_links', array(
|
||||||
@ -127,10 +127,12 @@ class StatifyBlacklist {
|
|||||||
* @param array $options Optional. New options to save.
|
* @param array $options Optional. New options to save.
|
||||||
*/
|
*/
|
||||||
public static function update_options( $options = null ) {
|
public static function update_options( $options = null ) {
|
||||||
self::$_options = wp_parse_args(
|
if ( self::$multisite ) {
|
||||||
get_option( 'statify-blacklist' ),
|
$o = get_site_option( 'statify-blacklist' );
|
||||||
self::default_options()
|
} else {
|
||||||
);
|
$o = get_option( 'statify-blacklist' );
|
||||||
|
}
|
||||||
|
self::$_options = wp_parse_args( $o, self::default_options() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -185,8 +187,10 @@ class StatifyBlacklist {
|
|||||||
$regexp .= 'i';
|
$regexp .= 'i';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check blacklist (return NULL to continue filtering).
|
// Check blacklist (no return to continue filtering #12).
|
||||||
return ( 1 === preg_match( $regexp, $referer ) ) ? true : null;
|
if ( 1 === preg_match( $regexp, $referer ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Extract relevant domain parts.
|
// Extract relevant domain parts.
|
||||||
$referer = wp_parse_url( wp_get_raw_referer() );
|
$referer = wp_parse_url( wp_get_raw_referer() );
|
||||||
@ -216,8 +220,10 @@ class StatifyBlacklist {
|
|||||||
$regexp .= 'i';
|
$regexp .= 'i';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check blacklist (return NULL to continue filtering).
|
// Check blacklist (no return to continue filtering #12).
|
||||||
return ( 1 === preg_match( $regexp, $target ) ) ? true : null;
|
if ( 1 === preg_match( $regexp, $target ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Extract target page.
|
// Extract target page.
|
||||||
// @codingStandardsIgnoreStart The globals are checked.
|
// @codingStandardsIgnoreStart The globals are checked.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "statify-blacklist",
|
"name": "statify-blacklist",
|
||||||
"version": "1.4.2",
|
"version": "1.4.4",
|
||||||
"description": "A blacklist extension for the famous Statify WordPress plugin",
|
"description": "A blacklist extension for the famous Statify WordPress plugin",
|
||||||
"author": "Stefan Kalscheuer",
|
"author": "Stefan Kalscheuer",
|
||||||
"license": "GPL-2.0+",
|
"license": "GPL-2.0+",
|
||||||
|
16
phpcs.xml
16
phpcs.xml
@ -2,10 +2,16 @@
|
|||||||
<ruleset name="StatifyBlacklist">
|
<ruleset name="StatifyBlacklist">
|
||||||
<description>Derived from WordPress Coding Standard</description>
|
<description>Derived from WordPress Coding Standard</description>
|
||||||
|
|
||||||
<rule ref="WordPress">
|
<arg value="psvn"/>
|
||||||
<!-- Type hint checks mess up PHP 7 checks, while this plugin has compatibility level 5.5 and above. -->
|
<arg name="colors"/>
|
||||||
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing"/>
|
|
||||||
|
|
||||||
|
<!-- 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. -->
|
<!-- 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"/>
|
||||||
<exclude name="WordPress.VIP.RestrictedFunctions.switch_to_blog_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.DirectQuery"/>
|
||||||
<exclude name="WordPress.VIP.DirectDatabaseQuery.NoCaching"/>
|
<exclude name="WordPress.VIP.DirectDatabaseQuery.NoCaching"/>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
|
<!-- PHP compatibility level -->
|
||||||
|
<config name="testVersion" value="5.5-"/>
|
||||||
|
<rule ref="PHPCompatibility"/>
|
||||||
</ruleset>
|
</ruleset>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* Plugin Name: Statify Blacklist
|
* Plugin Name: Statify Blacklist
|
||||||
* Plugin URI: https://wordpress.org/plugins/statify-blacklist/
|
* Plugin URI: https://wordpress.org/plugins/statify-blacklist/
|
||||||
* Description: Extension for the Statify plugin to add a customizable blacklists.
|
* Description: Extension for the Statify plugin to add a customizable blacklists.
|
||||||
* Version: 1.4.2
|
* Version: 1.4.4
|
||||||
* Author: Stefan Kalscheuer (@stklcode)
|
* Author: Stefan Kalscheuer (@stklcode)
|
||||||
* Author URI: https://www.stklcode.de
|
* Author URI: https://www.stklcode.de
|
||||||
* Text Domain: statify-blacklist
|
* Text Domain: statify-blacklist
|
||||||
|
@ -472,6 +472,86 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Test target regex filter.
|
// TODO: Test target regex filter.
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test combined filters.
|
||||||
|
*
|
||||||
|
* @since 1.4.4
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function test_combined_filters() {
|
||||||
|
// Prepare Options: simple referer + simple target + ip.
|
||||||
|
StatifyBlacklist::$_options = array(
|
||||||
|
'referer' => array(
|
||||||
|
'active' => 1,
|
||||||
|
'cron' => 0,
|
||||||
|
'regexp' => 0,
|
||||||
|
'blacklist' => array(
|
||||||
|
'example.com' => 0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'target' => array(
|
||||||
|
'active' => 1,
|
||||||
|
'cron' => 0,
|
||||||
|
'regexp' => 0,
|
||||||
|
'blacklist' => array(
|
||||||
|
'/excluded/page/' => 0
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'ip' => array(
|
||||||
|
'active' => 1,
|
||||||
|
'blacklist' => array(
|
||||||
|
'192.0.2.123'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'version' => StatifyBlacklist::VERSION_MAIN,
|
||||||
|
);
|
||||||
|
|
||||||
|
// No multisite.
|
||||||
|
StatifyBlacklist::$multisite = false;
|
||||||
|
|
||||||
|
// No match.
|
||||||
|
$_SERVER['HTTP_REFERER'] = 'https://example.net';
|
||||||
|
$_SERVER['REQUEST_URI'] = '/normal/page/';
|
||||||
|
$_SERVER['REMOTE_ADDR'] = '192.0.2.234';
|
||||||
|
unset( $_SERVER['HTTP_X_FORWARDED_FOR'] );
|
||||||
|
unset( $_SERVER['HTTP_X_REAL_IP'] );
|
||||||
|
|
||||||
|
// Matching Referer.
|
||||||
|
$_SERVER['HTTP_REFERER'] = 'https://example.com';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
|
||||||
|
// Matching target.
|
||||||
|
$_SERVER['HTTP_REFERER'] = 'https://example.net';
|
||||||
|
$_SERVER['REQUEST_URI'] = '/excluded/page/';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
|
||||||
|
// Matching IP.
|
||||||
|
$_SERVER['REQUEST_URI'] = '/normal/page/';
|
||||||
|
$_SERVER['REMOTE_ADDR'] = '192.0.2.123';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['REMOTE_ADDR'] = '192.0.2.234';
|
||||||
|
|
||||||
|
// Same for RegExp filters.
|
||||||
|
StatifyBlacklist::$_options['referer']['regexp'] = 1;
|
||||||
|
StatifyBlacklist::$_options['referer']['blacklist'] = array( 'example\.com' => 0 );
|
||||||
|
StatifyBlacklist::$_options['target']['regexp'] = 1;
|
||||||
|
StatifyBlacklist::$_options['target']['blacklist'] = array( '\/excluded\/.*' => 0 );
|
||||||
|
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['HTTP_REFERER'] = 'https://example.com';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['HTTP_REFERER'] = 'https://example.net';
|
||||||
|
$_SERVER['REQUEST_URI'] = '/excluded/page/';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['REQUEST_URI'] = '/normal/page/';
|
||||||
|
$_SERVER['REMOTE_ADDR'] = '192.0.2.123';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['REMOTE_ADDR'] = '192.0.2.234';
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,19 +51,26 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
$statifyblacklist_update_result = StatifyBlacklist_Admin::update_options(
|
$statifyblacklist_update_result = StatifyBlacklist_Admin::update_options(
|
||||||
array(
|
array(
|
||||||
'referer' => array(
|
'referer' => array(
|
||||||
'active' => (int) $_POST['statifyblacklist']['referer']['active'],
|
'active' => isset( $_POST['statifyblacklist']['referer']['active'] )
|
||||||
'cron' => (int) $_POST['statifyblacklist']['referer']['cron'],
|
? (int) $_POST['statifyblacklist']['referer']['active'] : 0,
|
||||||
'regexp' => (int) $_POST['statifyblacklist']['referer']['regexp'],
|
'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 ),
|
'blacklist' => array_flip( $referer ),
|
||||||
),
|
),
|
||||||
'target' => array(
|
'target' => array(
|
||||||
'active' => (int) $_POST['statifyblacklist']['target']['active'],
|
'active' => isset( $_POST['statifyblacklist']['target']['active'] )
|
||||||
'cron' => (int) $_POST['statifyblacklist']['target']['cron'],
|
? (int) $_POST['statifyblacklist']['target']['active'] : 0,
|
||||||
'regexp' => (int) $_POST['statifyblacklist']['target']['regexp'],
|
'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 ),
|
'blacklist' => array_flip( $target ),
|
||||||
),
|
),
|
||||||
'ip' => array(
|
'ip' => array(
|
||||||
'active' => (int) $_POST['statifyblacklist']['ip']['active'],
|
'active' => isset( $_POST['statifyblacklist']['ip']['active'] )
|
||||||
|
? (int) $_POST['statifyblacklist']['ip']['active'] : 0,
|
||||||
'blacklist' => $ip,
|
'blacklist' => $ip,
|
||||||
),
|
),
|
||||||
'version' => StatifyBlacklist::VERSION_MAIN,
|
'version' => StatifyBlacklist::VERSION_MAIN,
|
||||||
@ -90,7 +97,7 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
<?php
|
<?php
|
||||||
if ( is_plugin_inactive( 'statify/statify.php' ) ) {
|
if ( is_plugin_inactive( 'statify/statify.php' ) ) {
|
||||||
print '<div class="notice notice-warning"><p>';
|
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>';
|
print '</p></div>';
|
||||||
}
|
}
|
||||||
if ( isset( $statifyblacklist_post_warning ) ) {
|
if ( isset( $statifyblacklist_post_warning ) ) {
|
||||||
|
Reference in New Issue
Block a user