-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathfull-site-editing-plugin.php
336 lines (296 loc) · 10.4 KB
/
full-site-editing-plugin.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
<?php
/**
* Plugin Name: WordPress.com Editing Toolkit
* Description: Enhances your page creation workflow within the Block Editor.
* Version: 2.21
* Author: Automattic
* Author URI: https://automattic.com/wordpress-plugins/
* License: GPLv2 or later
* Text Domain: full-site-editing
*
* @package A8C\FSE
*/
namespace A8C\FSE;
/**
* This file should only be used to load files needed for each subfeature.
*
* For example, if you are adding a new feature to this plugin called "Foo",
* you would create a directory `./foo` to contain all code needed by your
* feature. Then, in this file, you would add a `load_foo()` function which
* includes your feature's files via the 'plugins_loaded' action.
*
* Please take care to _not_ load your feature's files if there are situations
* which could cause bugs. For example, dotcom FSE files are only loaded if dotcom
* FSE isactive on the site.
*
* Finally, don't forget to use the A8C\FSE namespace for your code. :)
*/
/**
* Plugin version.
*
* Can be used in cache keys to invalidate caches on plugin update.
*
* Note: this constant is updated via TeamCity continuous integration. That
* change is not copied back to VCS, so we use "dev" here to indicate that the
* version in wp-calypso is for development.
*
* On WordPress.com, the version here should show up in the "info" section of
* the "more options" menu in Gutenberg.
*
* @var string
*/
define( 'A8C_ETK_PLUGIN_VERSION', 'dev' );
// Always include these helper files for dotcom FSE.
require_once __DIR__ . '/dotcom-fse/helpers.php';
// Enqueues the shared JS data stores and defines shared helper functions.
require_once __DIR__ . '/common/index.php';
/**
* Load dotcom-FSE.
*/
function load_full_site_editing() {
// Bail if FSE should not be active on the site. We do not
// want to load FSE functionality on non-supported sites!
if ( ! is_full_site_editing_active() ) {
return;
}
// Not dangerous here since we have already checked for eligibility.
dangerously_load_full_site_editing_files();
Full_Site_Editing::get_instance();
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_full_site_editing' );
/**
* Load Posts List Block.
*/
function load_posts_list_block() {
if ( class_exists( 'Posts_List_Block' ) ) {
return;
}
/**
* Can be used to disable the Post List Block.
*
* @since 0.2
*
* @param bool true if Post List Block should be disabled, false otherwise.
*/
if ( apply_filters( 'a8c_disable_post_list_block', false ) ) {
return;
}
require_once __DIR__ . '/posts-list-block/utils.php';
require_once __DIR__ . '/posts-list-block/class-posts-list-block.php';
Posts_List_Block::get_instance();
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_posts_list_block' );
/**
* Load Starter_Page_Templates.
*/
function load_starter_page_templates() {
// We don't want the user to choose a template when copying a post.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['jetpack-copy'] ) ) {
return;
}
/**
* Can be used to disable the Starter Page Templates.
*
* @since 0.2
*
* @param bool true if Starter Page Templates should be disabled, false otherwise.
*/
if ( apply_filters( 'a8c_disable_starter_page_templates', false ) ) {
return;
}
require_once __DIR__ . '/starter-page-templates/class-starter-page-templates.php';
Starter_Page_Templates::get_instance();
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_starter_page_templates' );
/**
* Load Global Styles plugin.
*/
function load_global_styles() {
require_once __DIR__ . '/global-styles/class-global-styles.php';
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_global_styles' );
/**
* Load Event Countdown Block.
*/
function load_countdown_block() {
require_once __DIR__ . '/event-countdown-block/index.php';
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_countdown_block' );
/**
* Load Timeline Block.
*/
function load_timeline_block() {
require_once __DIR__ . '/jetpack-timeline/index.php';
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_timeline_block' );
/**
* Load Editor Site Launch.
*/
function load_editor_site_launch() {
require_once __DIR__ . '/editor-site-launch/index.php';
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_editor_site_launch' );
/**
* Add front-end CoBlocks gallery block scripts.
*
* This function performs the same enqueueing duties as `CoBlocks_Block_Assets::frontend_scripts`,
* but for dotcom FSE header and footer content. `frontend_scripts` uses
* `has_block` to determine if gallery blocks are present, and `has_block` is
* not aware of content sections outside of post_content yet.
*/
function enqueue_coblocks_gallery_scripts() {
if ( ! function_exists( 'CoBlocks' ) || ! is_full_site_editing_active() ) {
return;
}
// This happens in the Customizer because we try very hard not to load things and we get a fatal
// https://github.com/Automattic/wp-calypso/issues/36680.
if ( ! class_exists( '\A8C\FSE\WP_Template' ) ) {
require_once __DIR__ . '/dotcom-fse/templates/class-wp-template.php';
}
$template = new WP_Template();
$header = $template->get_template_content( 'header' );
$footer = $template->get_template_content( 'footer' );
// Define where the asset is loaded from.
$dir = CoBlocks()->asset_source( 'js' );
// Define where the vendor asset is loaded from.
$vendors_dir = CoBlocks()->asset_source( 'js', 'vendors' );
// Masonry block.
if ( has_block( 'coblocks/gallery-masonry', $header . $footer ) ) {
wp_enqueue_script(
'coblocks-masonry',
$dir . 'coblocks-masonry' . COBLOCKS_ASSET_SUFFIX . '.js',
array( 'jquery', 'masonry', 'imagesloaded' ),
COBLOCKS_VERSION,
true
);
}
// Carousel block.
if ( has_block( 'coblocks/gallery-carousel', $header . $footer ) ) {
wp_enqueue_script(
'coblocks-flickity',
$vendors_dir . '/flickity' . COBLOCKS_ASSET_SUFFIX . '.js',
array( 'jquery' ),
COBLOCKS_VERSION,
true
);
}
}
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_coblocks_gallery_scripts' );
/**
* Load Blog Posts block.
*/
function load_blog_posts_block() {
// Use regex instead of static slug in order to match plugin installation also from github, where slug may contain (HASH|branch-name).
$slug_regex = '/newspack-blocks(-[A-Za-z0-9-]+)?\/newspack-blocks\.php/';
$disable_block = (
( defined( 'WP_CLI' ) && WP_CLI ) ||
/* phpcs:ignore WordPress.Security.NonceVerification */
( isset( $_GET['action'], $_GET['plugin'] ) && 'activate' === $_GET['action'] && preg_match( $slug_regex, sanitize_text_field( wp_unslash( $_GET['plugin'] ) ) ) ) ||
preg_grep( $slug_regex, (array) get_option( 'active_plugins' ) ) ||
preg_grep( $slug_regex, (array) get_site_option( 'active_sitewide_plugins' ) )
);
/**
* Can be used to disable the Blog Posts block.
*
* @since 0.15.1
*
* @param bool $disable_block True if Blog Posts block should be enabled, false otherwise.
*/
if ( apply_filters( 'a8c_disable_blog_posts_block', $disable_block ) ) {
return;
}
require_once __DIR__ . '/newspack-blocks/index.php';
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_blog_posts_block' );
/**
* Load WPCOM Block Editor NUX.
*/
function load_wpcom_block_editor_nux() {
require_once __DIR__ . '/wpcom-block-editor-nux/class-wpcom-block-editor-nux.php';
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_wpcom_block_editor_nux' );
/**
* Load editing toolkit block patterns from the API
*
* @param obj $current_screen The current screen object.
*/
function load_block_patterns_from_api( $current_screen ) {
if ( ! apply_filters( 'a8c_enable_block_patterns_api', false ) ) {
return;
}
$is_site_editor = ( function_exists( 'gutenberg_is_edit_site_page' ) && gutenberg_is_edit_site_page( $current_screen->id ) );
if ( ! $current_screen->is_block_editor && ! $is_site_editor ) {
return;
}
$patterns_sources = array( 'block_patterns' );
// While we're still testing the FSE patterns, limit activation via a filter.
if ( $is_site_editor && apply_filters( 'a8c_enable_fse_block_patterns_api', false ) ) {
$patterns_sources[] = 'fse_block_patterns';
}
require_once __DIR__ . '/block-patterns/class-block-patterns-from-api.php';
$block_patterns_from_api = new Block_Patterns_From_API( $patterns_sources );
$block_patterns_from_api->register_patterns();
}
add_action( 'current_screen', __NAMESPACE__ . '\load_block_patterns_from_api' );
/**
* Load WPCOM Block Patterns Modifications.
*
* This is responsible for modifying how block patterns behave in the editor,
* including adding support for premium block patterns. The patterns themselves
* are loaded via load_block_patterns_from_api.
*/
function load_wpcom_block_patterns_modifications() {
// Disable the premium patterns feature temporarily due to performance issues (#50069).
// phpcs:disable
// if ( apply_filters( 'a8c_enable_block_patterns_modifications', false ) ) {
// require_once __DIR__ . '/block-patterns/class-block-patterns-modifications.php';
// }
// phpcs:enable
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_wpcom_block_patterns_modifications' );
/**
* Load Block Inserter Modifications module.
*/
function load_block_inserter_modifications() {
require_once __DIR__ . '/block-inserter-modifications/index.php';
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_block_inserter_modifications' );
/**
* Load Mailerlite module.
*/
function load_mailerlite() {
require_once __DIR__ . '/mailerlite/subscriber-popup.php';
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_mailerlite' );
/**
* Load WPCOM block editor nav sidebar.
*/
function load_wpcom_block_editor_sidebar() {
if (
( defined( 'WPCOM_BLOCK_EDITOR_SIDEBAR' ) && WPCOM_BLOCK_EDITOR_SIDEBAR ) ||
apply_filters( 'a8c_enable_nav_sidebar', false )
) {
require_once __DIR__ . '/wpcom-block-editor-nav-sidebar/class-wpcom-block-editor-nav-sidebar.php';
}
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_wpcom_block_editor_sidebar' );
/**
* Coming soon.
*/
function load_coming_soon() {
if (
( defined( 'WPCOM_PUBLIC_COMING_SOON' ) && WPCOM_PUBLIC_COMING_SOON ) ||
apply_filters( 'a8c_enable_public_coming_soon', false )
) {
require_once __DIR__ . '/coming-soon/coming-soon.php';
}
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_coming_soon' );
/**
* What's New section of the Tools menu.
*/
function load_whats_new() {
require_once __DIR__ . '/whats-new/class-whats-new.php';
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_whats_new' );