-
Notifications
You must be signed in to change notification settings - Fork 30
/
simple-podcasting.php
345 lines (303 loc) · 8.85 KB
/
simple-podcasting.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<?php
/**
* Plugin Name: Simple Podcasting
* Plugin URI: https://github.com/10up/simple-podcasting
* Description: Easily set up multiple podcast feeds using built-in WordPress posts. Includes a podcast block for the new WordPress editor.
* Version: 1.8.1
* Requires at least: 6.5
* Requires PHP: 7.4
* Author: 10up
* Author URI: http://10up.com/
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: simple-podcasting
*
* @package tenup_podcasting
*/
namespace tenup_podcasting;
/**
* Get the minimum version of PHP required by this plugin.
*
* @since 1.6.0
*
* @return string Minimum version required.
*/
function minimum_php_requirement() {
return '7.4';
}
/**
* Whether PHP installation meets the minimum requirements
*
* @since 1.6.0
*
* @return bool True if meets minimum requirements, false otherwise.
*/
function site_meets_php_requirements() {
return version_compare( phpversion(), minimum_php_requirement(), '>=' );
}
// Try to load the plugin files, ensuring our PHP version is met first.
if ( ! site_meets_php_requirements() ) {
add_action(
'admin_notices',
function () {
?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %s: Minimum required PHP version */
__( 'Simple Podcasting requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'simple-podcasting' ),
esc_html( minimum_php_requirement() )
)
);
?>
</p>
</div>
<?php
}
);
return;
}
define( 'PODCASTING_VERSION', '1.8.1' );
define( 'PODCASTING_PATH', __DIR__ . '/' );
define( 'PODCASTING_URL', plugin_dir_url( __FILE__ ) );
define( 'PODCASTING_TAXONOMY_NAME', 'podcasting_podcasts' );
define( 'PODCASTING_ITEMS_PER_PAGE', 250 );
require_once PODCASTING_PATH . 'includes/create-podcast.php';
require_once PODCASTING_PATH . 'includes/admin/onboarding.php';
require_once PODCASTING_PATH . 'includes/admin/create-podcast-component.php';
require_once PODCASTING_PATH . 'includes/datatypes.php';
require_once PODCASTING_PATH . 'includes/helpers.php';
require_once PODCASTING_PATH . 'includes/rest-external-url.php';
require_once PODCASTING_PATH . 'includes/transcripts.php';
require_once PODCASTING_PATH . 'includes/upgrade.php';
// Init the endpoint.
endpoints\externalurl\setup();
/**
* Flush rewrite rules on plugin activation.
*
* `flush_rewrite_rules()` cannot just be hooked on directly
* because the taxonomy is not yet registered at that point.
* So we call the taxonomy registration function ourselves first.
*
* @return void
*/
function activate_plugin() {
create_podcasts_taxonomy();
\flush_rewrite_rules();
$terms = get_terms(
array(
'taxonomy' => 'podcasting_podcasts',
'hide_empty' => false,
)
);
$has_podcast = is_array( $terms ) && ! empty( $terms );
if ( $has_podcast ) {
update_option( 'simple_podcasting_onboarding', 'completed' );
}
if ( '' === get_option( 'simple_podcasting_onboarding', '' ) ) {
update_option( 'simple_podcasting_onboarding', 'no' );
}
}
register_activation_hook( __FILE__, __NAMESPACE__ . '\activate_plugin' );
// Block editor support.
if ( function_exists( 'register_block_type' ) ) {
require_once PODCASTING_PATH . 'includes/blocks.php';
}
if ( function_exists( 'register_block_pattern' ) ) {
require_once PODCASTING_PATH . 'includes/block-patterns.php';
}
/**
* Is podcasting enabled?
*
* If there are any podcast terms set up, podcasting is enabled.
*
* @return bool
*/
function podcasting_is_enabled() {
$podcasting_terms = get_terms(
array(
'taxonomy' => PODCASTING_TAXONOMY_NAME,
'hide_empty' => false,
'fields' => 'ids',
'no_found_rows' => true,
)
);
return ! empty( $podcasting_terms );
}
/**
* Enqueue admin scripts and styles on the term and term edit screens.
*
* @param string $hook_suffix The $hook_suffix for the current admin page.
*/
function podcasting_edit_term_enqueues( $hook_suffix ) {
$screens = array(
'edit-tags.php',
'term.php',
'admin_page_simple-podcasting-onboarding',
);
if ( in_array( $hook_suffix, $screens, true ) ) {
wp_enqueue_style(
'podcasting_edit_term_screen',
PODCASTING_URL . 'dist/podcasting-edit-term.css',
array(),
PODCASTING_VERSION
);
wp_enqueue_script(
'podcasting_edit_term_screen',
PODCASTING_URL . 'dist/podcasting-edit-term.js',
array( 'jquery' ),
PODCASTING_VERSION,
true
);
}
if ( in_array( $hook_suffix, $screens, true ) ) {
wp_enqueue_media();
wp_enqueue_script(
'podcasting_onboarding_screen_script',
PODCASTING_URL . 'dist/podcasting-onboarding.js',
array( 'jquery' ),
PODCASTING_VERSION,
true
);
wp_enqueue_script(
'podcasting_edit_term_screen',
PODCASTING_URL . 'dist/podcasting-edit-term.js',
array( 'jquery' ),
PODCASTING_VERSION,
true
);
wp_localize_script(
'podcasting_edit_term_screen',
'podcastingEditPostVars',
array(
'iconUrl' => PODCASTING_URL . 'dist/images/icons',
)
);
wp_enqueue_style(
'podcasting_onboarding_screen_style',
PODCASTING_URL . 'dist/podcasting-onboarding.css',
array(),
PODCASTING_VERSION
);
wp_enqueue_style( 'podcasting_onboarding_fonts', 'https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap' ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
}
}
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\podcasting_edit_term_enqueues' );
/**
* Load the file containing iTunes specific feed hooks.
*
* @param \WP_Query $query The query being parsed.
*
* @uses includes/customize-feed.php
*/
function custom_feed( \WP_Query $query ) {
if ( is_admin() || ! podcasting_is_enabled() ) {
return;
}
// Is this a feed for a term in the podcasting taxonomy?
if ( $query->is_feed() && $query->is_tax( PODCASTING_TAXONOMY_NAME ) ) {
remove_action( 'rss2_head', 'rss2_blavatar' );
remove_action( 'rss2_head', 'rss2_site_icon' );
remove_filter( 'the_excerpt_rss', 'add_bug_to_feed', 100 );
remove_action( 'rss2_head', 'rsscloud_add_rss_cloud_element' );
add_filter(
'wp_feed_cache_transient_lifetime',
function () {
return HOUR_IN_SECONDS;
}
);
require_once PODCASTING_PATH . 'includes/customize-feed.php';
}
}
add_action( 'parse_query', __NAMESPACE__ . '\custom_feed', 10, 1 );
/**
* Initialize the edit screen if podcasting is enabled.
*
* @uses includes/post-meta-box.php
*/
function setup_edit_screen() {
if ( podcasting_is_enabled() ) {
require_once PODCASTING_PATH . 'includes/post-meta-box.php';
}
}
add_action( 'admin_init', __NAMESPACE__ . '\setup_edit_screen' );
/**
* Registers block assets for Podcast block.
*/
function register_podcast_block_assets() {
$block_asset = [
'version' => PODCASTING_VERSION,
'dependencies' => [],
];
if ( file_exists( PODCASTING_PATH . 'dist/podcast.asset.php' ) ) {
$block_asset = require PODCASTING_PATH . 'dist/podcast.asset.php';
}
wp_register_style(
'podcast-block',
PODCASTING_URL . 'dist/podcast.css',
array(),
$block_asset['version'],
'all'
);
wp_enqueue_style( 'podcast-block' );
}
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\register_podcast_block_assets' );
/**
* Registers block assets for Podcast block in admin.
*/
function register_podcast_block_assets_admin() {
$block_asset = [
'version' => PODCASTING_VERSION,
'dependencies' => [],
];
if ( file_exists( PODCASTING_PATH . 'dist/podcast.asset.php' ) ) {
$block_asset = require PODCASTING_PATH . 'dist/podcast.asset.php';
}
wp_register_style(
'podcast-block',
PODCASTING_URL . 'dist/podcast.css',
array(),
$block_asset['version'],
'all'
);
wp_enqueue_style( 'podcast-block' );
}
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\register_podcast_block_assets_admin' );
/**
* Registers block assets for Latest Episode.
*/
function register_latest_episode_assets() {
if ( ! file_exists( PODCASTING_PATH . 'dist/latest-episode.asset.php' ) ) {
return;
}
$block_asset = require PODCASTING_PATH . 'dist/latest-episode.asset.php';
wp_register_style(
'latest-episode-block',
PODCASTING_URL . 'dist/latest-episode.css',
array(),
$block_asset['version'],
'all'
);
wp_enqueue_style( 'latest-episode-block' );
}
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\register_latest_episode_assets' );
/**
* Registers block assets for Latest Episode in admin.
*/
function register_latest_episode_assets_admin() {
if ( ! file_exists( PODCASTING_PATH . 'dist/latest-episode.asset.php' ) ) {
return;
}
$block_asset = require PODCASTING_PATH . 'dist/latest-episode.asset.php';
wp_register_style(
'latest-episode-block',
PODCASTING_URL . 'dist/latest-episode.css',
array(),
$block_asset['version'],
'all'
);
wp_enqueue_style( 'latest-episode-block' );
}
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\register_latest_episode_assets_admin' );