|
3 | 3 | /*
|
4 | 4 | Plugin Name: RRZE Legal
|
5 | 5 | Plugin URI: https://gitlab.rrze.fau.de/rrze-webteam/rrze-legal
|
6 |
| -Version: 2.7.8 |
| 6 | +Version: 2.7.9 |
7 | 7 | Description: Legal Mandatory Information & GDPR.
|
8 | 8 | Author: RRZE Webteam
|
9 | 9 | Author URI: https://www.rrze.fau.de
|
10 | 10 | License: GNU General Public License Version 3
|
11 | 11 | License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
12 | 12 | Text Domain: rrze-legal
|
13 | 13 | Domain Path: /languages
|
14 |
| -Requires at least: 6.6 |
| 14 | +Requires at least: 6.7 |
15 | 15 | Requires PHP: 8.2
|
16 | 16 | */
|
17 | 17 |
|
|
25 | 25 | use RRZE\Legal\Consent\Categories\Options as ConsentCategoriesOptions;
|
26 | 26 | use RRZE\Legal\Consent\Cookies\Options as ConsentCookiesOptions;
|
27 | 27 |
|
28 |
| -const RRZE_PHP_VERSION = '8.2'; |
29 |
| -const RRZE_WP_VERSION = '6.6'; |
30 |
| - |
31 | 28 | /**
|
32 | 29 | * SPL Autoloader (PSR-4).
|
33 | 30 | * @param string $class The fully-qualified class name.
|
|
50 | 47 | }
|
51 | 48 | });
|
52 | 49 |
|
53 |
| -// Register plugin hooks. |
54 |
| -register_activation_hook(__FILE__, __NAMESPACE__ . '\activation'); |
55 |
| -register_deactivation_hook(__FILE__, __NAMESPACE__ . '\deactivation'); |
| 50 | +// Load the plugin's text domain for localization. |
| 51 | +add_action('init', fn() => load_plugin_textdomain('rrze-legal', false, dirname(plugin_basename(__FILE__)) . '/languages')); |
56 | 52 |
|
57 |
| -add_action('plugins_loaded', __NAMESPACE__ . '\loaded'); |
58 | 53 |
|
59 |
| -/** |
60 |
| - * Loads a plugin’s translated strings. |
61 |
| - */ |
62 |
| -function loadTextdomain() |
63 |
| -{ |
64 |
| - load_plugin_textdomain('rrze-legal', false, dirname(plugin_basename(__FILE__)) . '/languages'); |
65 |
| -} |
| 54 | +// Register activation hook for the plugin |
| 55 | +register_activation_hook(__FILE__, __NAMESPACE__ . '\activation'); |
| 56 | + |
| 57 | +// Register deactivation hook for the plugin |
| 58 | +register_deactivation_hook(__FILE__, __NAMESPACE__ . '\deactivation'); |
66 | 59 |
|
67 | 60 | /**
|
68 |
| - * System requirements verification. |
69 |
| - * @return string Return an error message. |
| 61 | + * Add an action hook for the 'plugins_loaded' hook. |
| 62 | + * |
| 63 | + * This code hooks into the 'plugins_loaded' action hook to execute a callback function when |
| 64 | + * WordPress has fully loaded all active plugins and the theme's functions.php file. |
70 | 65 | */
|
71 |
| -function systemRequirements(): string |
72 |
| -{ |
73 |
| - $error = ''; |
74 |
| - if (version_compare(PHP_VERSION, RRZE_PHP_VERSION, '<')) { |
75 |
| - $error = sprintf( |
76 |
| - /* translators: 1: Server PHP version number, 2: Required PHP version number. */ |
77 |
| - __('The server is running PHP version %1$s. The Plugin requires at least PHP version %2$s.', 'rrze-legal'), |
78 |
| - PHP_VERSION, |
79 |
| - RRZE_PHP_VERSION |
80 |
| - ); |
81 |
| - } elseif (version_compare($GLOBALS['wp_version'], RRZE_WP_VERSION, '<')) { |
82 |
| - $error = sprintf( |
83 |
| - /* translators: 1: Server WordPress version number, 2: Required WordPress version number. */ |
84 |
| - __('The server is running WordPress version %1$s. The Plugin requires at least WordPress version %2$s.', 'rrze-legal'), |
85 |
| - $GLOBALS['wp_version'], |
86 |
| - RRZE_WP_VERSION |
87 |
| - ); |
88 |
| - } |
89 |
| - return $error; |
90 |
| -} |
| 66 | +add_action('plugins_loaded', __NAMESPACE__ . '\loaded'); |
91 | 67 |
|
92 | 68 | /**
|
93 | 69 | * Activation callback function.
|
94 | 70 | */
|
95 | 71 | function activation()
|
96 | 72 | {
|
97 |
| - loadTextdomain(); |
98 | 73 | if ($error = systemRequirements()) {
|
99 | 74 | deactivate_plugins(plugin_basename(__FILE__));
|
100 | 75 | wp_die(
|
101 |
| - esc_html(sprintf( |
| 76 | + sprintf( |
102 | 77 | /* translators: 1: The plugin name, 2: The error string. */
|
103 | 78 | __('Plugins: %1$s: %2$s', 'rrze-legal'),
|
104 | 79 | plugin_basename(__FILE__),
|
105 | 80 | $error
|
106 |
| - ), 'post') |
| 81 | + ) |
107 | 82 | );
|
108 | 83 | }
|
109 | 84 | }
|
@@ -232,35 +207,89 @@ function fauDomains(): array
|
232 | 207 | }
|
233 | 208 |
|
234 | 209 | /**
|
235 |
| - * Execute on 'plugins_loaded' API/action. |
236 |
| - * @return void |
| 210 | + * Check system requirements for the plugin. |
| 211 | + * |
| 212 | + * This method checks if the server environment meets the minimum WordPress and PHP version requirements |
| 213 | + * for the plugin to function properly. |
| 214 | + * |
| 215 | + * @return string An error message string if requirements are not met, or an empty string if requirements are satisfied. |
| 216 | + */ |
| 217 | +function systemRequirements(): string |
| 218 | +{ |
| 219 | + // Get the global WordPress version. |
| 220 | + global $wp_version; |
| 221 | + |
| 222 | + // Get the PHP version. |
| 223 | + $phpVersion = phpversion(); |
| 224 | + |
| 225 | + // Initialize an error message string. |
| 226 | + $error = ''; |
| 227 | + |
| 228 | + // Check if the WordPress version is compatible with the plugin's requirement. |
| 229 | + if (!is_wp_version_compatible(plugin()->getRequiresWP())) { |
| 230 | + $error = sprintf( |
| 231 | + /* translators: 1: Server WordPress version number, 2: Required WordPress version number. */ |
| 232 | + __('The server is running WordPress version %1$s. The plugin requires at least WordPress version %2$s.', 'rrze-legal'), |
| 233 | + $wp_version, |
| 234 | + plugin()->getRequiresWP() |
| 235 | + ); |
| 236 | + } elseif (!is_php_version_compatible(plugin()->getRequiresPHP())) { |
| 237 | + // Check if the PHP version is compatible with the plugin's requirement. |
| 238 | + $error = sprintf( |
| 239 | + /* translators: 1: Server PHP version number, 2: Required PHP version number. */ |
| 240 | + __('The server is running PHP version %1$s. The plugin requires at least PHP version %2$s.', 'rrze-legal'), |
| 241 | + $phpVersion, |
| 242 | + plugin()->getRequiresPHP() |
| 243 | + ); |
| 244 | + } |
| 245 | + |
| 246 | + // Return the error message string, which will be empty if requirements are satisfied. |
| 247 | + return $error; |
| 248 | +} |
| 249 | + |
| 250 | +/** |
| 251 | + * Handle the loading of the plugin. |
| 252 | + * |
| 253 | + * This function is responsible for initializing the plugin, loading text domains for localization, |
| 254 | + * checking system requirements, and displaying error notices if necessary. |
237 | 255 | */
|
238 | 256 | function loaded()
|
239 | 257 | {
|
240 | 258 | if (!tosPluginDeactivation()) {
|
241 | 259 | return;
|
242 | 260 | }
|
243 |
| - loadTextdomain(); |
| 261 | + // Trigger the 'loaded' method of the main plugin instance. |
244 | 262 | plugin()->loaded();
|
| 263 | + // Check system requirements and store any error messages. |
245 | 264 | if ($error = systemRequirements()) {
|
| 265 | + // If there is an error, add an action to display an admin notice with the error message. |
246 | 266 | add_action('admin_init', function () use ($error) {
|
| 267 | + // Check if the current user has the capability to activate plugins. |
247 | 268 | if (current_user_can('activate_plugins')) {
|
248 |
| - $pluginData = get_plugin_data(plugin()->getFile()); |
249 |
| - $pluginName = $pluginData['Name']; |
| 269 | + // Get plugin data to retrieve the plugin's name. |
| 270 | + $pluginName = plugin()->getName(); |
| 271 | + |
| 272 | + // Determine the admin notice tag based on network-wide activation. |
250 | 273 | $tag = is_plugin_active_for_network(plugin()->getBaseName()) ? 'network_admin_notices' : 'admin_notices';
|
| 274 | + |
| 275 | + // Add an action to display the admin notice. |
251 | 276 | add_action($tag, function () use ($pluginName, $error) {
|
252 | 277 | printf(
|
253 | 278 | '<div class="notice notice-error"><p>' .
|
254 | 279 | /* translators: 1: The plugin name, 2: The error string. */
|
255 |
| - esc_html(__('Plugins: %1$s: %2$s', 'rrze-legal'), 'post') . |
| 280 | + esc_html__('Plugins: %1$s: %2$s', 'rrze-legal') . |
256 | 281 | '</p></div>',
|
257 |
| - esc_html($pluginName), |
258 |
| - esc_html($error) |
| 282 | + $pluginName, |
| 283 | + $error |
259 | 284 | );
|
260 | 285 | });
|
261 | 286 | }
|
262 | 287 | });
|
| 288 | + |
| 289 | + // Return to prevent further initialization if there is an error. |
263 | 290 | return;
|
264 | 291 | }
|
| 292 | + |
| 293 | + // If there are no errors, create an instance of the 'Main' class |
265 | 294 | new Main;
|
266 | 295 | }
|
0 commit comments