-
Notifications
You must be signed in to change notification settings - Fork 5
/
rrze-elements.php
121 lines (101 loc) · 3.24 KB
/
rrze-elements.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
<?php
/*
Plugin Name: RRZE Elements
Plugin URI: https://github.com/RRZE-Webteam/rrze-elements
Description: Advanced design elements for WordPress websites.
Version: 1.31.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-elements
*/
namespace RRZE\Elements;
defined('ABSPATH') || exit;
require_once 'config/config.php';
use RRZE\Elements\Main;
const RRZE_PHP_VERSION = '8.1';
const RRZE_WP_VERSION = '5.9';
const RRZE_ELEMENTS_VERSION = '1.31.2';
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_hook(__FILE__, __NAMESPACE__ . '\activation');
register_deactivation_hook(__FILE__, __NAMESPACE__ . '\deactivation');
add_action('plugins_loaded', __NAMESPACE__ . '\loaded');
register_activation_hook(__FILE__, 'RRZE\Elements\activation');
register_deactivation_hook(__FILE__, 'RRZE\Elements\deactivation');
add_action('plugins_loaded', 'RRZE\Elements\loaded');
/**
* [loadTextdomain description]
* @return void
*/
function loadTextdomain()
{
load_plugin_textdomain('rrze-elements', false, sprintf('%s/languages/', dirname(plugin_basename(__FILE__))));
}
/**
* [systemRequirements description]
* @return string [description]
*/
function systemRequirements()
{
$error = '';
if (version_compare(PHP_VERSION, RRZE_PHP_VERSION, '<')) {
$error = sprintf(__('The server is running PHP version %1$s. The Plugin requires at least PHP version %2$s.', 'rrze-elements'), PHP_VERSION, RRZE_PHP_VERSION);
} elseif (version_compare($GLOBALS['wp_version'], RRZE_WP_VERSION, '<')) {
$error = sprintf(__('The server is running WordPress version %1$s. The Plugin requires at least WordPress version %2$s.', 'rrze-elements'), $GLOBALS['wp_version'], RRZE_WP_VERSION);
}
return $error;
}
/**
* [activation description]
* @return void
*/
function activation()
{
loadTextdomain();
if ($error = systemRequirements()) {
deactivate_plugins(plugin_basename(__FILE__), false, true);
wp_die($error);
}
}
/**
* [deactivation description]
* @return [type] [description]
*/
function deactivation()
{
}
/**
* [loaded description]
* @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__);
}
}