-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrrze-elements-blocks.php
118 lines (99 loc) · 3.56 KB
/
rrze-elements-blocks.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
<?php
/*
Plugin Name: RRZE Elements Blocks
Plugin URI: https://github.com/RRZE-Webteam/rrze-elements
Description: Advanced design elements for WordPress BlockEditor.
Version: 1.0.15
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-elements-blocks
*/
namespace RRZE\ElementsBlocks;
defined('ABSPATH') || exit('No direct script access allowed');
use RRZE\Elements\News\News;
// Require necessary configuration files.
require_once 'config/config.php';
use RRZE\ElementsBlocks\Main;
// Define plugin version requirements.
const RRZE_PHP_VERSION = '8.0';
const RRZE_WP_VERSION = '6.0';
const RRZE_ELEMENTSB_VERSION = '1.0.15';
// Autoloads plugin classes.
spl_autoload_register(function ($class) {
$prefix = __NAMESPACE__;
$base_dir = __DIR__ . '/includes/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
// Register activation and deactivation hooks.
register_activation_hook(__FILE__, __NAMESPACE__ . '\activation');
// register_deactivation_hook(__FILE__, __NAMESPACE__ . '\deactivation');
add_action('plugins_loaded', __NAMESPACE__ . '\loaded');
/**
* Loads the plugin text domain for translation.
* @return void
*/
function loadTextdomain()
{
unload_textdomain('rrze-elements-blocks');
load_plugin_textdomain('rrze-elements-blocks', false, sprintf('%s/languages/', dirname(plugin_basename(__FILE__))));
}
/**
* Checks system requirements like PHP and WordPress version.
*
* @return string Error message if requirements are not met.
*/
function systemRequirements()
{
$error = '';
if (version_compare(PHP_VERSION, RRZE_PHP_VERSION, '<')) {
/* translators: 1: current PHP version, 2: required PHP version */
$error = sprintf(__('The server is running PHP version %1$s. The Plugin requires at least PHP version %2$s.', 'rrze-elements-blocks'), PHP_VERSION, RRZE_PHP_VERSION);
} elseif (version_compare($GLOBALS['wp_version'], RRZE_WP_VERSION, '<')) {
/* translators: 1: current WordPress version, 2: required WordPress version */
$error = sprintf(__('The server is running WordPress version %1$s. The Plugin requires at least WordPress version %2$s.', 'rrze-elements-blocks'), $GLOBALS['wp_version'], RRZE_WP_VERSION);
}
return $error;
}
/**
* Plugin activation callback
*/
function activation()
{
loadTextdomain();
if ($error = systemRequirements()) {
deactivate_plugins(plugin_basename(__FILE__), false, true);
wp_die(esc_html($error));
}
}
/**
* Plugin loaded actions including system requirement checks and initialization.
* @return void
*/
function loaded()
{
loadTextdomain();
if ($error = systemRequirements()) {
if (!function_exists('get_plugin_data')) {
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
}
$plugin_data = get_plugin_data(__FILE__);
$plugin_name = $plugin_data['Name'];
$tag = is_network_admin() ? 'network_admin_notices' : 'admin_notices';
add_action($tag, function () use ($plugin_name, $error) {
printf('<div class="notice notice-error"><p>%1$s: %2$s</p></div>', esc_html($plugin_name), esc_html($error));
});
} else {
new Main(__FILE__);
}
}