-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrrze-events.php
275 lines (246 loc) · 8.54 KB
/
rrze-events.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
/*
Plugin Name: RRZE Events
Plugin URI: https://github.com/RRZE-Webteam/rrze-events
Description: Manage and display talks and speakers
Version: 1.0.1
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-events
*/
namespace RRZE\Events;
defined('ABSPATH') || exit;
use RRZE\Events\CPT\Speaker;
use RRZE\Events\CPT\Talk;
use RRZE\WP\Plugin\Plugin;
const RRZE_PHP_VERSION = '8.2';
const RRZE_WP_VERSION = '6.6';
require_once 'config/defaults.php';
// Autoloader
require_once 'vendor/autoload.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-events',
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();
$theme = wp_get_theme();
$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-events'),
$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-events'),
$wpVersion,
RRZE_WP_VERSION
);
} elseif ( 'FAU Events' == $theme->name || 'FAU Events' == $theme->parent_theme ) {
$error = __('RRZE Events plugin does not work with FAU Events Theme as the event features are already included in the theme. Please activate another theme before activating RRZE Events. The plugin will preserve your existing speakers, talks and shortcodes.', 'rrze-events');
}
return $error;
}
/**
* Activation callback function.
*/
function activation()
{
loadTextdomain();
if ($error = systemRequirements()) {
deactivate_plugins(plugin_basename(__FILE__));
wp_die(
esc_html(sprintf(
/* translators: 1: The plugin name, 2: The error string. */
__('Plugins: %1$s: %2$s', 'rrze-events'),
plugin_basename(__FILE__),
$error
))
);
}
add_action(
'init',
function () {
Speaker::registerPostType();
Talk::registerPostType();
flush_rewrite_rules(false);
}
);
// Import existing theme mods and social media profiles from FAU-Events Theme
importThemeMods();
$speakers = get_posts([
'post_type' => 'speaker',
'posts_per_page' => -1,
]);
$urlFields = array(
'speaker_blog',
'speaker_twitter',
'speaker_xing',
'speaker_linkedin',
'speaker_facebook',
'speaker_other_profile',
);
foreach ($speakers as $speaker) {
$socialMediaURLs = [];
foreach ($urlFields as $field) {
$value = get_post_meta($speaker->ID, $field, true);
if ($value != '') {
$socialMediaURLs[] = ($field == 'speaker_twitter' ? 'https://twitter.com/' . $value : $value);
}
}
if (!empty($socialMediaURLs)) {
update_post_meta($speaker->ID, 'speaker_social_media', $socialMediaURLs);
}
}
// Flush rewrite rules
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;
}
/**
* Instantiate Settings class.
* @return object Settings
*/
function settings()
{
static $instance;
if (null === $instance) {
$instance = new Settings();
}
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. */
esc_html(__('Plugins: %1$s: %2$s', 'rrze-events') .
'</p></div>'),
esc_html($pluginName),
esc_html($error)
);
});
}
});
return;
}
new Main;
add_action('init', __NAMESPACE__ . '\createBlocks');
add_filter('block_categories_all', __NAMESPACE__ . '\rrze_block_category', 10, 2);
}
function init() {
loadTextdomain();
}
function createBlocks(): void {
register_block_type( __DIR__ . '/build/blocks/speaker' );
$script_handle_speaker = generate_block_asset_handle( 'rrze-events/speaker', 'editorScript' );
wp_set_script_translations( $script_handle_speaker, 'rrze-events', plugin_dir_path( __FILE__ ) . 'languages' );
register_block_type( __DIR__ . '/build/blocks/talk' );
$script_handle_talk = generate_block_asset_handle( 'rrze-events/talk', 'editorScript' );
wp_set_script_translations( $script_handle_talk, 'rrze-events', plugin_dir_path( __FILE__ ) . 'languages' );
}
function rrze_block_category($categories, $post) {
$custom_category = [
'slug' => 'rrze',
'title' => __('RRZE Plugins', 'rrze-events'),
'icon' => 'layout',
];
array_unshift($categories, $custom_category);
return $categories;
}
add_filter('block_categories_all', __NAMESPACE__ . '\rrze_block_category', 10, 2);
function importThemeMods() {
$themeMods = [
'speaker-image-format' => 'speaker|image-format',
'speaker_link_icons' => 'speaker|show-link-icons',
'speaker_talk_list' => 'speaker|show-talk-list',
'show_speaker_categories' => 'speaker|show-categories',
'talk_order' => 'speaker|talk-order',
'label-talk' => 'label|label-talk',
'label-talk-pl' => 'label|label-talk-plural',
'label-speaker' => 'label|label-speaker',
'label-speaker-pl' => 'label|label-speaker-plural',
'label-short' => 'label|label-short',
'cfp-form-id' => 'cfp|form-id',
'cfp-talk_title' => 'cfp|talk-title',
'cfp-talk_excerpt' => 'cfp|talk-excerpt',
'cfp-talk_description' => 'cfp|talk-description',
'cfp-speaker-title' => 'cfp|speaker-title',
'cfp-speaker-firstname' => 'cfp|speaker-firstname',
'cfp-speaker-lastname' => 'cfp|speaker-lastname',
'cfp-speaker-cv' => 'cfp|speaker-cv',
'cfp-speaker-organisation' => 'cfp|speaker-organisation',
'cfp-speaker-email' => 'cfp|speaker-email',
'cfp-speaker-website' => 'cfp|speaker-website',
];
foreach ($themeMods as $key => $settings) {
$mod = get_theme_mod($key);
if ($mod === false) {
continue;
}
if ($key == 'talk_order') {
$mod = 'by-' . $mod; // renamed because of CMB2 problems with value 'date'
}
$settingsParts = explode('|', $settings);
$settingsCat = $settingsParts[0];
$settingsKey = $settingsParts[1];
$settingsNew = Settings::getOption('rrze-events-' . $settingsCat . '-settings');
$settingsNew[$settingsKey] = $mod;
update_option('rrze-events-' . $settingsCat . '-settings', $settingsNew);
}
}