| 1 |
<?php |
| 2 |
/** |
| 3 |
* Statify Filter |
| 4 |
* |
| 5 |
* @package PluginPackage |
| 6 |
* @author Stefan Kalscheuer <stefan@stklcode.de> |
| 7 |
* @license GPL-2.0+ |
| 8 |
* |
| 9 |
* @wordpress-plugin |
| 10 |
* Plugin Name: Statify Filter |
| 11 |
* Plugin URI: https://wordpress.org/plugins/statify-blacklist/ |
| 12 |
* Description: Extension for the Statify plugin to add customizable filters. (formerly "Statify Blacklist) |
| 13 |
* Version: 1.6.1 |
| 14 |
* Author: Stefan Kalscheuer (@stklcode) |
| 15 |
* Author URI: https://www.stklcode.de |
| 16 |
* Text Domain: statify-blacklist |
| 17 |
* License: GPLv2 or later |
| 18 |
* |
| 19 |
* Statify Filter is free software: you can redistribute it and/or modify |
| 20 |
* it under the terms of the GNU General Public License as published by |
| 21 |
* the Free Software Foundation, either version 2 of the License, or |
| 22 |
* any later version. |
| 23 |
* |
| 24 |
* Statify Filter is distributed in the hope that it will be useful, |
| 25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 |
* GNU General Public License for more details. |
| 28 |
* |
| 29 |
* You should have received a copy of the GNU General Public License |
| 30 |
* along with Statify Filter. If not, see https://www.gnu.org/licenses/gpl-2.0.html. |
| 31 |
*/ |
| 32 |
|
| 33 |
// Quit if accessed directly. |
| 34 |
if ( ! defined( 'ABSPATH' ) ) { |
| 35 |
exit; |
| 36 |
} |
| 37 |
|
| 38 |
// Constants. |
| 39 |
define( 'STATIFYBLACKLIST_FILE', __FILE__ ); |
| 40 |
define( 'STATIFYBLACKLIST_DIR', dirname( __FILE__ ) ); |
| 41 |
define( 'STATIFYBLACKLIST_BASE', plugin_basename( __FILE__ ) ); |
| 42 |
|
| 43 |
// Check for compatibility. |
| 44 |
if ( statify_blacklist_compatibility_check() ) { |
| 45 |
// System Hooks. |
| 46 |
add_action( 'plugins_loaded', array( 'StatifyBlacklist', 'init' ) ); |
| 47 |
|
| 48 |
register_activation_hook( STATIFYBLACKLIST_FILE, array( 'StatifyBlacklist_System', 'install' ) ); |
| 49 |
|
| 50 |
register_uninstall_hook( STATIFYBLACKLIST_FILE, array( 'StatifyBlacklist_System', 'uninstall' ) ); |
| 51 |
|
| 52 |
// Upgrade hook. |
| 53 |
register_activation_hook( STATIFYBLACKLIST_FILE, array( 'StatifyBlacklist_System', 'upgrade' ) ); |
| 54 |
|
| 55 |
// Autoload. |
| 56 |
spl_autoload_register( 'statify_blacklist_autoload' ); |
| 57 |
} else { |
| 58 |
// Disable plugin, if active. |
| 59 |
add_action( 'admin_init', 'statify_blacklist_disable' ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Autoloader for StatifyBlacklist classes. |
| 64 |
* |
| 65 |
* @param string $class Name of the class to load. |
| 66 |
* |
| 67 |
* @since 1.0.0 |
| 68 |
*/ |
| 69 |
function statify_blacklist_autoload( $class ) { |
| 70 |
$plugin_classes = array( |
| 71 |
'StatifyBlacklist', |
| 72 |
'StatifyBlacklist_Admin', |
| 73 |
'StatifyBlacklist_System', |
| 74 |
); |
| 75 |
|
| 76 |
if ( in_array( $class, $plugin_classes, true ) ) { |
| 77 |
require_once sprintf( |
| 78 |
'%s/inc/class-%s.php', |
| 79 |
STATIFYBLACKLIST_DIR, |
| 80 |
strtolower( str_replace( '_', '-', $class ) ) |
| 81 |
); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Check for compatibility with PHP and WP version. |
| 87 |
* |
| 88 |
* @since 1.5.0 |
| 89 |
* |
| 90 |
* @return boolean Whether minimum WP and PHP versions are met. |
| 91 |
*/ |
| 92 |
function statify_blacklist_compatibility_check() { |
| 93 |
return version_compare( $GLOBALS['wp_version'], '4.7', '>=' ) && |
| 94 |
version_compare( phpversion(), '5.5', '>=' ); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Disable plugin if active and incompatible. |
| 99 |
* |
| 100 |
* @since 1.5.0 |
| 101 |
* |
| 102 |
* @return void |
| 103 |
*/ |
| 104 |
function statify_blacklist_disable() { |
| 105 |
if ( is_plugin_active( STATIFYBLACKLIST_BASE ) ) { |
| 106 |
deactivate_plugins( STATIFYBLACKLIST_BASE ); |
| 107 |
add_action( 'admin_notices', 'statify_blacklist_disabled_notice' ); |
| 108 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended |
| 109 |
if ( isset( $_GET['activate'] ) ) { |
| 110 |
unset( $_GET['activate'] ); |
| 111 |
} |
| 112 |
// phpcs:enable |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Admin notification for unmet requirements. |
| 118 |
* |
| 119 |
* @since 1.5.0 |
| 120 |
* |
| 121 |
* @return void |
| 122 |
*/ |
| 123 |
function statify_blacklist_disabled_notice() { |
| 124 |
echo '<div class="notice notice-error is-dismissible"><p><strong>'; |
| 125 |
printf( |
| 126 |
/* translators: minimum version numbers for WordPress and PHP inserted at placeholders */ |
| 127 |
esc_html__( 'Statify Filter requires at least WordPress %1$s and PHP %2$s.', 'statify-blacklist' ), |
| 128 |
'4.7', |
| 129 |
'5.5' |
| 130 |
); |
| 131 |
echo '<br>'; |
| 132 |
printf( |
| 133 |
/* translators: current version numbers for WordPress and PHP inserted at placeholders */ |
| 134 |
esc_html__( 'Your site is running WordPress %1$s on PHP %2$s, thus the plugin has been disabled.', 'statify-blacklist' ), |
| 135 |
esc_html( $GLOBALS['wp_version'] ), |
| 136 |
esc_html( phpversion() ) |
| 137 |
); |
| 138 |
echo '</strong></p></div>'; |
| 139 |
} |
| 140 |
|