-
Notifications
You must be signed in to change notification settings - Fork 2
/
rrze-video.php
executable file
·185 lines (165 loc) · 5.26 KB
/
rrze-video.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/*
Plugin Name: RRZE Video
Plugin URI: https://github.com/RRZE-Webteam/rrze-video
Description: Embedding videos via a shortcode or widget based on the Plyr video player.
Version: 5.0.5
Author: RRZE-Webteam
Author URI: http://blogs.fau.de/webworking/
License: GNU General Public License Version 3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Domain Path: /languages
Text Domain: rrze-video
*/
namespace RRZE\Video;
defined('ABSPATH') || exit;
use RRZE\Video\Utils\Plugin;
use RRZE\Video\WordPress\Gutenberg;
const RRZE_PHP_VERSION = '7.4';
const RRZE_WP_VERSION = '6.0';
/**
* Composer autoload
*/
// require_once __DIR__ . '/vendor/autoload.php';
/**
* 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');
/**
* Loads a plugin’s translated strings.
*/
function loadTextdomain()
{
load_plugin_textdomain('rrze-video', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
/**
* System requirements verification.
* @return string Return an error message.
*/
function systemRequirements(): string
{
$error = '';
if (version_compare(PHP_VERSION, 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-legal'),
PHP_VERSION,
RRZE_PHP_VERSION
);
} elseif (version_compare($GLOBALS['wp_version'], 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-legal'),
$GLOBALS['wp_version'],
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-legal'),
plugin_basename(__FILE__),
$error
)
);
} else {
WordPress\Roles::addRoleCaps();
flush_rewrite_rules();
}
}
/**
* Deactivation callback function.
* Remove Roles and Caps.
*/
function deactivation()
{
WordPress\Roles::removeRoleCaps();
flush_rewrite_rules();
}
/**
* Instantiate Plugin class.
* @return object Plugin
*/
function plugin()
{
static $instance;
if (null === $instance) {
$instance = new Plugin(__FILE__);
}
return $instance;
}
/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function create_block_rrze_video_block_init()
{
$gutenberg_instance = new Gutenberg();
register_block_type(__DIR__ . '/build/blocks', [
'render_callback' => [$gutenberg_instance, 'rrze_video_render_block']
]);
$script_handle = generate_block_asset_handle( 'rrze/rrze-video', 'editorScript' );
wp_set_script_translations( $script_handle, 'rrze-video', plugin_dir_path( __FILE__ ) . 'languages' );
}
/**
* Execute on 'plugins_loaded' API/action.
* @return void
*/
function loaded()
{
loadTextdomain();
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-legal') .
'</p></div>',
esc_html($pluginName),
esc_html($error)
);
});
}
});
return;
}
new Main;
add_action('init', __NAMESPACE__ . '\create_block_rrze_video_block_init');
}