-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcms-workflow.php
168 lines (144 loc) · 5.21 KB
/
cms-workflow.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/*
Plugin Name: CMS-Workflow
Plugin URI: https://github.com/RRZE-Webteam/cms-workflow
Version: 2.0.2
Description: Redaktioneller Workflow.
Author: RRZE-Webteam
Author URI: https://blogs.fau.de/webworking/
License: GNU General Public License Version 3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Text Domain: cms-workflow
Domain Path: /languages
Requires at least: 6.7
Requires PHP: 8.2
*/
namespace RRZE\Workflow;
defined('ABSPATH') || exit;
/**
* 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 plugin hooks.
register_activation_hook(__FILE__, __NAMESPACE__ . '\activation');
register_deactivation_hook(__FILE__, __NAMESPACE__ . '\deactivation');
add_action('plugins_loaded', __NAMESPACE__ . '\loaded');
// Load the plugin's text domain for localization.
add_action('init', fn() => load_plugin_textdomain('cms-workflow', false, dirname(plugin_basename(__FILE__)) . '/languages'));
/**
* Activation callback function.
*/
function activation()
{
//
}
/**
* Deactivation callback function.
*/
function deactivation()
{
Module::resetEditorRole();
Module::resetAuthorRole();
}
/**
* Instantiate Plugin class.
* @return object Plugin
*/
function plugin()
{
static $instance;
if (null === $instance) {
$instance = new Plugin(__FILE__);
}
return $instance;
}
/**
* Check system requirements for the plugin.
*
* This method checks if the server environment meets the minimum WordPress and PHP version requirements
* for the plugin to function properly.
*
* @return string An error message string if requirements are not met, or an empty string if requirements are satisfied.
*/
function systemRequirements(): string
{
// Get the global WordPress version.
global $wp_version;
// Get the PHP version.
$phpVersion = phpversion();
// Initialize an error message string.
$error = '';
// Check if the WordPress version is compatible with the plugin's requirement.
if (!is_wp_version_compatible(plugin()->getRequiresWP())) {
$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.', 'cms-workflow'),
$wp_version,
plugin()->getRequiresWP()
);
} elseif (!is_php_version_compatible(plugin()->getRequiresPHP())) {
// Check if the PHP version is compatible with the plugin's requirement.
$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.', 'cms-workflow'),
$phpVersion,
plugin()->getRequiresPHP()
);
}
// Return the error message string, which will be empty if requirements are satisfied.
return $error;
}
/**
* Handle the loading of the plugin.
*
* This function is responsible for initializing the plugin, loading text domains for localization,
* checking system requirements, and displaying error notices if necessary.
*/
function loaded()
{
// Trigger the 'loaded' method of the main plugin instance.
plugin()->loaded();
// Check system requirements.
if (systemRequirements()) {
// If there is an error, add an action to display an admin notice with the error message.
add_action('admin_init', function () {
$error = systemRequirements();
// Check if the current user has the capability to activate plugins.
if (current_user_can('activate_plugins')) {
// Get plugin data to retrieve the plugin's name.
$pluginName = plugin()->getName();
// Determine the admin notice tag based on network-wide activation.
$tag = is_plugin_active_for_network(plugin()->getBaseName()) ? 'network_admin_notices' : 'admin_notices';
// Add an action to display the admin notice.
add_action($tag, function () use ($pluginName, $error) {
printf(
'<div class="notice notice-error"><p>' .
/* translators: 1: The plugin name, 2: The error string. */
esc_html__('Plugins: %1$s: %2$s', 'cms-workflow') .
'</p></div>',
$pluginName,
$error
);
});
}
});
// Return to prevent further initialization if there is an error.
return;
}
// If there are no errors, create an instance of the 'Main' class and trigger its 'loaded' method.
new Main;
}