-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrrze-hello-lenny.php
149 lines (133 loc) · 4.4 KB
/
rrze-hello-lenny.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace RRZE\HelloLenny;
/**
* Plugin Name: RRZE Hello Lenny
* Plugin URI: https://github.com/RRZE-Webteam/rrze-hello-lenny/
* Description: A plugin inspired by Hello Dolly, using both a shortcode and a Gutenberg block.
* Version: 1.4.0
* Requires at least: 6.6
* Requires PHP: 8.2
* Author: RRZE Webteam
* Author URI: https://blogs.fau.de/webworking/
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Domain Path: /languages
* Text Domain: rrze-hello-lenny
*/
// Prevent direct access to this file.
defined('ABSPATH') || exit;
// Plugin requirements.
const REQUIRED_PHP_VERSION = '8.2';
const REQUIRED_WP_VERSION = '6.6';
/**
* SPL Autoloader (PSR-4).
* @param string $class The fully-qualified class name.
* @return void
*/
spl_autoload_register(function ($class) {
$prefix = __NAMESPACE__;
$baseDir = __DIR__ . '/includes/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relativeClass = substr($class, $len);
$file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';
if (file_exists($file)) {
require $file;
}
});
// Register activation and deactivation hooks.
register_activation_hook(__FILE__, __NAMESPACE__ . '\activate');
register_deactivation_hook(__FILE__, __NAMESPACE__ . '\deactivate');
// Loaded action hook.
add_action('plugins_loaded', __NAMESPACE__ . '\onLoaded');
/**
* Load the plugin text domain for translation.
*/
function loadTextdomain()
{
load_plugin_textdomain('rrze-hello-lenny', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
/**
* System requirements verification.
* @return string Return an error message or an empty string.
*/
function systemRequirements(): string
{
global $wp_version;
// Strip off any -alpha, -RC, -beta, -src suffixes.
list($wpVersion) = explode('-', $wp_version);
$phpVersion = phpversion();
$error = '';
if (!is_php_version_compatible(REQUIRED_PHP_VERSION)) {
$error = sprintf(
/* translators: 1: Server PHP version number, 2: Required PHP version number. */
__('The server is running PHP version %1$s. The Plugin requires at least PHP version %2$s.', 'rrze-hello-lenny'),
$phpVersion,
REQUIRED_PHP_VERSION
);
} elseif (!is_wp_version_compatible(REQUIRED_WP_VERSION)) {
$error = sprintf(
/* translators: 1: Server WordPress version number, 2: Required WordPress version number. */
__('The server is running WordPress version %1$s. The Plugin requires at least WordPress version %2$s.', 'rrze-hello-lenny'),
$wpVersion,
REQUIRED_WP_VERSION
);
}
return $error;
}
/**
* Activation hook.
*/
function activate()
{
loadTextdomain();
if ($error = systemRequirements()) {
deactivate_plugins(plugin_basename(__FILE__));
wp_die(
sprintf(
/* translators: 1: The plugin name, 2: The error string. */
__('Plugins: %1$s: %2$s', 'rrze-hello-lenny'),
plugin_basename(__FILE__),
$error
)
);
}
}
/**
* Deactivation hook.
*/
function deactivate()
{
// Any deactivation tasks can be added here.
}
/**
* Execute on 'plugins_loaded' API/action.
*/
function onLoaded()
{
loadTextdomain();
if ($error = systemRequirements()) {
add_action('admin_init', function () use ($error) {
if (current_user_can('activate_plugins')) {
$pluginName = plugin_basename(__FILE__);
$tag = is_plugin_active_for_network(plugin_basename(__FILE__)) ? 'network_admin_notices' : 'admin_notices';
add_action($tag, function () use ($pluginName, $error) {
printf(
'<div class="notice notice-error"><p>%s</p></div>',
sprintf(
/* translators: 1: The plugin name, 2: The error string. */
esc_html__('Plugins: %1$s: %2$s', 'rrze-hello-lenny'),
esc_html($pluginName),
esc_html($error)
)
);
});
}
});
return;
}
// Initialize Main class && call onLoaded method.
(new Main(__FILE__))->onLoaded();
}