-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrrze-rsvp.php
149 lines (124 loc) · 3.79 KB
/
rrze-rsvp.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
/*
Plugin Name: RRZE RSVP
Plugin URI: https://github.com/RRZE-Webteam/rrze-rsvp
Description: FAU Reservation Tool
Version: 2.7.9
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-rsvp
*/
namespace RRZE\RSVP;
use RRZE\RSVP\CPT\CPT;
defined('ABSPATH') || exit;
// Laden der Konfigurationsdatei
require_once __DIR__ . '/config/config.php';
// Autoloader (PSR-4)
spl_autoload_register(function ($class) {
$prefix = __NAMESPACE__;
$base_dir = __DIR__ . '/includes/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relativeClass = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relativeClass) . '.php';
if (file_exists($file)) {
require $file;
}
});
const RRZE_PHP_VERSION = '7.4';
const RRZE_WP_VERSION = '5.5';
register_activation_hook(__FILE__, __NAMESPACE__ . '\activation');
register_deactivation_hook(__FILE__, __NAMESPACE__ . '\deactivation');
add_action('plugins_loaded', __NAMESPACE__ . '\loaded');
/**
* [loadTextdomain description]
*/
function loadTextdomain()
{
load_plugin_textdomain('rrze-rsvp', false, sprintf('%s/languages/', dirname(plugin_basename(__FILE__))));
}
/**
* [systemRequirements description]
* @return string [description]
*/
function systemRequirements(): string
{
$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-rsvp'), 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-rsvp'), $GLOBALS['wp_version'], RRZE_WP_VERSION);
}
return $error;
}
/**
* [activation description]
*/
function activation()
{
loadTextdomain();
if ($error = systemRequirements()) {
deactivate_plugins(plugin_basename(__FILE__));
wp_die(sprintf(__('Plugins: %1$s: %2$s', 'rrze-log'), plugin_basename(__FILE__), $error));
}
Users::addRoleCaps();
Users::createBookingRole();
$cpt = new CPT;
$cpt->activation();
flush_rewrite_rules();
}
/**
* [deactivation description]
*/
function deactivation()
{
Users::removeRoleCaps();
Users::removeBookingRole();
flush_rewrite_rules();
}
/**
* [plugin description]
* @return object
*/
function plugin(): object
{
static $instance;
if (null === $instance) {
$instance = new Plugin(__FILE__);
}
return $instance;
}
/**
* [loaded description]
* @return void
*/
function loaded()
{
// add_action('init', __NAMESPACE__ . '\loadTextdomain');
loadTextdomain();
plugin()->onLoaded();
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>' . __('Plugins: %1$s: %2$s', 'rrze-rsvp') . '</p></div>',
esc_html($pluginName),
esc_html($error)
);
});
}
});
return;
}
$main = new Main(__FILE__);
$main->onLoaded();
}