PluginProbe
Statify Filter / 1.8.0
Statify Filter v1.8.0
1.4.4 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.8.0 trunk 1.1.1 1.1.2 1.2.0 1.2.1 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3
statify-blacklist / statify-blacklist.php

statify-blacklist.php in Statify Filter 1.8.0, at statify-blacklist.php

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