-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrrze-servicekatalog.php
161 lines (143 loc) · 4.21 KB
/
rrze-servicekatalog.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
<?php
/*
Plugin Name: RRZE Servicekatalog
Plugin URI: https://github.com/RRZE-Webteam/rrze-servicekatalog
Description: Presentation of RRZE Services
Version: 1.3.0
Author: RRZE Webteam
Author URI: https://blogs.fau.de/webworking/
License: GNU General Public License v3.0
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
Domain Path: /languages
Text Domain: rrze-servicekatalog
*/
namespace RRZE\Servicekatalog;
defined('ABSPATH') || exit;
use RRZE\Servicekatalog\CPT\Service;
use RRZE\WP\Plugin;
const RRZE_PHP_VERSION = '8.0';
const RRZE_WP_VERSION = '6.2';
// Autoloader
require_once 'vendor/autoload.php';
require_once 'config/config.php';
register_activation_hook(__FILE__, __NAMESPACE__ . '\activation');
register_deactivation_hook(__FILE__, __NAMESPACE__ . '\deactivation');
add_action('plugins_loaded', __NAMESPACE__ . '\loaded');
add_action('init', __NAMESPACE__ . '\init');
/**
* loadTextdomain
*/
function loadTextdomain()
{
load_plugin_textdomain(
'rrze-servicekatalog',
false,
sprintf('%s/languages/', dirname(plugin_basename(__FILE__)))
);
}
/**
* System requirements verification.
* @return string Return an error message.
*/
function systemRequirements(): string
{
global $wp_version;
// Strip off any -alpha, -RC, -beta, -src suffixes.
[$wpVersion] = explode('-', $wp_version);
$phpVersion = phpversion();
$error = '';
if (!is_php_version_compatible(RRZE_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-servicekatalog'),
$phpVersion,
RRZE_PHP_VERSION
);
} elseif (!is_wp_version_compatible(RRZE_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-servicekatalog'),
$wpVersion,
RRZE_WP_VERSION
);
}
return $error;
}
/**
* Activation callback function.
*/
function activation()
{
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-servicekatalog'),
plugin_basename(__FILE__),
$error
)
);
}
add_action(
'init',
function () {
Service::registerPostType();
flush_rewrite_rules(false);
}
);
flush_rewrite_rules(false);
}
/**
* Deactivation callback function.
*/
function deactivation()
{
flush_rewrite_rules(false);
}
/**
* Instantiate Plugin class.
* @return object Plugin
*/
function plugin()
{
static $instance;
if (null === $instance) {
$instance = new Plugin(__FILE__);
}
return $instance;
}
/**
* Execute on 'plugins_loaded' API/action.
* @return void
*/
function loaded()
{
plugin()->loaded();
if ($error = systemRequirements()) {
add_action('admin_init', function () use ($error) {
if (current_user_can('activate_plugins')) {
$pluginData = get_plugin_data(plugin()->getFile());
$pluginName = $pluginData['Name'];
$tag = is_plugin_active_for_network(plugin()->getBaseName()) ? 'network_admin_notices' : 'admin_notices';
add_action($tag, function () use ($pluginName, $error) {
printf(
'<div class="notice notice-error"><p>' .
/* translators: 1: The plugin name, 2: The error string. */
__('Plugins: %1$s: %2$s', 'rrze-servicekatalog') .
'</p></div>',
esc_html($pluginName),
esc_html($error)
);
});
}
});
return;
}
new Main;
}
function init()
{
loadTextdomain();
}