Full Site Editing - Version 3.27073

Version Description

Download this release

Release Info

Developer addiestavlo
Plugin Icon wp plugin Full Site Editing
Version 3.27073
Comparing to
See all releases

Code changes from version 3.26914 to 3.27073

full-site-editing-plugin.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: WordPress.com Editing Toolkit
4
  * Description: Enhances your page creation workflow within the Block Editor.
5
- * Version: 3.26914
6
  * Author: Automattic
7
  * Author URI: https://automattic.com/wordpress-plugins/
8
  * License: GPLv2 or later
@@ -42,7 +42,7 @@ namespace A8C\FSE;
42
  *
43
  * @var string
44
  */
45
- define( 'A8C_ETK_PLUGIN_VERSION', '3.26914' );
46
 
47
  // Always include these helper files for dotcom FSE.
48
  require_once __DIR__ . '/dotcom-fse/helpers.php';
2
  /**
3
  * Plugin Name: WordPress.com Editing Toolkit
4
  * Description: Enhances your page creation workflow within the Block Editor.
5
+ * Version: 3.27073
6
  * Author: Automattic
7
  * Author URI: https://automattic.com/wordpress-plugins/
8
  * License: GPLv2 or later
42
  *
43
  * @var string
44
  */
45
+ define( 'A8C_ETK_PLUGIN_VERSION', '3.27073' );
46
 
47
  // Always include these helper files for dotcom FSE.
48
  require_once __DIR__ . '/dotcom-fse/helpers.php';
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: automattic
3
  Tags: block, blocks, editor, gutenberg, page
4
  Requires at least: 5.5
5
  Tested up to: 5.6
6
- Stable tag: 3.26914
7
  Requires PHP: 5.6.20
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
3
  Tags: block, blocks, editor, gutenberg, page
4
  Requires at least: 5.5
5
  Tested up to: 5.6
6
+ Stable tag: 3.27073
7
  Requires PHP: 5.6.20
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
wpcom-universal-themes/index.php CHANGED
@@ -15,26 +15,18 @@ namespace A8C\FSE;
15
  define( 'ACTIVATE_FSE_OPTION_NAME', 'wpcom_is_fse_activated' );
16
 
17
  /**
18
- * Checks if Core's FSE is active via this plugin,
19
- * always returning false when `gutenberg_is_fse_theme` is false.
 
 
 
 
20
  *
21
  * @return boolean Core FSE is active.
22
  */
23
  function is_core_fse_active() {
24
- // If `gutenberg_is_fse_theme` is false, this is a non-starter.
25
- if ( ! is_fse_theme() ) {
26
- return false;
27
- }
28
-
29
- if ( is_universal_theme() ) {
30
- return (bool) get_option( ACTIVATE_FSE_OPTION_NAME );
31
- }
32
-
33
- // Universal themes can use the customizer to customize the site, regardless of whether or
34
- // not the full site editor is activated. Block themes, however, don't have access to the
35
- // customizer. If the site editor is disabled for them, it will severely limit site
36
- // customizability. Because of this we always activate FSE for block themes.
37
- return true;
38
  }
39
 
40
  /**
@@ -71,8 +63,11 @@ function is_universal_theme() {
71
  }
72
 
73
  /**
74
- * Activates Core FSE by setting our option.
75
- * Note that even setting this option to true will make no difference on a classic theme.
 
 
 
76
  *
77
  * @return void
78
  */
@@ -81,6 +76,9 @@ function activate_core_fse() {
81
  }
82
 
83
  /**
 
 
 
84
  * Deactivates Core FSE by setting the option to NULL (matches the Options API).
85
  *
86
  * @return void
@@ -96,40 +94,17 @@ function deactivate_core_fse() {
96
  */
97
  function load_core_fse() {
98
  // perfect parity would put the admin notices back but we don't want that.
99
- add_action( 'admin_menu', 'gutenberg_site_editor_menu', 9 );
100
- add_action( 'admin_menu', 'gutenberg_remove_legacy_pages' );
101
- add_action( 'admin_bar_menu', 'gutenberg_adminbar_items', 50 );
102
  add_action( 'admin_menu', __NAMESPACE__ . '\hide_nav_menus_submenu' );
103
- remove_action( 'init', __NAMESPACE__ . '\hide_template_cpts', 11 );
104
- remove_action( 'restapi_theme_init', __NAMESPACE__ . '\hide_template_cpts', 11 );
105
- remove_filter( 'block_editor_settings_all', __NAMESPACE__ . '\hide_fse_blocks' );
106
- remove_filter( 'block_editor_settings_all', __NAMESPACE__ . '\hide_template_editing', 11 );
107
- remove_action( 'admin_menu', __NAMESPACE__ . '\hide_core_site_editor' );
108
  }
109
 
110
  /**
111
- * Unhooks anything that Gutenberg uses for Full Site Editing
112
  *
113
  * @return void
114
  */
115
  function unload_core_fse() {
116
- remove_action( 'admin_notices', 'gutenberg_full_site_editing_notice' );
117
- remove_action( 'admin_menu', 'gutenberg_site_editor_menu', 9 );
118
- remove_action( 'admin_menu', 'gutenberg_remove_legacy_pages' );
119
- remove_action( 'admin_bar_menu', 'gutenberg_adminbar_items', 50 );
120
  remove_action( 'admin_menu', __NAMESPACE__ . '\hide_nav_menus_submenu' );
121
-
122
- if ( defined( 'REST_API_REQUEST' ) && true === REST_API_REQUEST ) {
123
- // Do not hook to init during the REST API requests, as it causes PHP warnings
124
- // while loading the alloptions (unable to access wp_0_ prefixed tables).
125
- // Use the restapi_theme_init hook instead.
126
- add_action( 'restapi_theme_init', __NAMESPACE__ . '\hide_template_cpts', 11 );
127
- } else {
128
- add_action( 'init', __NAMESPACE__ . '\hide_template_cpts', 11 );
129
- }
130
- add_filter( 'block_editor_settings_all', __NAMESPACE__ . '\hide_fse_blocks' );
131
- add_filter( 'block_editor_settings_all', __NAMESPACE__ . '\hide_template_editing', 11 );
132
- add_action( 'admin_menu', __NAMESPACE__ . '\hide_core_site_editor' );
133
  }
134
 
135
  /**
@@ -152,10 +127,6 @@ function load_helpers() {
152
  // This menu toggles site editor visibility for universal themes.
153
  // It's unnecessary for block themes because the site editor
154
  // will always be visible.
155
- if ( is_universal_theme() ) {
156
- add_action( 'admin_menu', __NAMESPACE__ . '\add_submenu' );
157
- }
158
- add_action( 'admin_notices', __NAMESPACE__ . '\theme_nag' );
159
  add_action( 'admin_init', __NAMESPACE__ . '\init_settings' );
160
  }
161
 
@@ -165,8 +136,6 @@ function load_helpers() {
165
  * @return void
166
  */
167
  function unload_helpers() {
168
- remove_action( 'admin_notices', __NAMESPACE__ . '\theme_nag' );
169
- remove_action( 'admin_menu', __NAMESPACE__ . '\add_submenu' );
170
  remove_action( 'admin_init', __NAMESPACE__ . '\init_settings' );
171
  remove_action( 'admin_menu', __NAMESPACE__ . '\maybe_juggle_amp_priority', 0 );
172
  }
@@ -188,203 +157,20 @@ function maybe_juggle_amp_priority() {
188
  add_action( 'admin_menu', 'amp_add_customizer_link', 11 );
189
  }
190
 
191
- /**
192
- * Adds our submenu
193
- *
194
- * @return void
195
- */
196
- function add_submenu() {
197
- add_options_page(
198
- __( 'Full Site Editing (beta)', 'full-site-editing' ),
199
- sprintf(
200
- /* translators: %s: "beta" label. */
201
- __( 'Full Site Editing %s', 'full-site-editing' ),
202
- '<span class="awaiting-mod">' . esc_html__( 'beta', 'full-site-editing' ) . '</span>'
203
- ),
204
- 'manage_options',
205
- 'site-editor-toggle',
206
- __NAMESPACE__ . '\menu_page'
207
- );
208
- }
209
-
210
- /**
211
- * Prints an admin notice on the themes screen when an FSE theme is active and
212
- * this plugin's toggle is inactive. Links to our submenu for activation.
213
- *
214
- * @return void
215
- */
216
- function theme_nag() {
217
- $is_active = is_core_fse_active();
218
- $is_themes_screen = 'themes' === get_current_screen()->id;
219
- $is_fse_theme = is_fse_theme();
220
- if ( $is_active || ! $is_themes_screen || ! $is_fse_theme ) {
221
- return;
222
- }
223
- $message = sprintf(
224
- /* translators: %s: URL for linking to activation subpage */
225
- __( 'You are running a theme capable of Full Site Editing! <a href="%s" class="button">Try the Site Editor</a>', 'full-site-editing' ),
226
- admin_url( 'themes.php?page=site-editor-toggle' )
227
- );
228
- printf(
229
- '<div class="notice is-dismissible"><p>%s</p></div>',
230
- wp_kses(
231
- $message,
232
- array(
233
- 'a' => array(
234
- 'href' => array(),
235
- 'class' => array(),
236
- ),
237
- )
238
- )
239
- );
240
-
241
- }
242
-
243
- /**
244
- * Filter for `block_editor_settings_all` in order to prevent expermiental
245
- * blocks from showing up in the post editor when FSE is inactive.
246
- *
247
- * @param [array] $editor_settings Editor settings.
248
- * @return array Possibly modified editor settings.
249
- */
250
- function hide_fse_blocks( $editor_settings ) {
251
- // this shouldn't even be hooked under this condition, but let's be sure.
252
- if ( is_core_fse_active() ) {
253
- return $editor_settings;
254
- }
255
- $editor_settings['__unstableEnableFullSiteEditingBlocks'] = false;
256
- return $editor_settings;
257
- }
258
-
259
- /**
260
- * Filter for `block_editor_settings_all` in order to prevent template
261
- * editing from showing up in the post editor when FSE is inactive.
262
- *
263
- * @param [array] $editor_settings Editor settings.
264
- * @return array Possibly modified editor settings.
265
- */
266
- function hide_template_editing( $editor_settings ) {
267
- // this shouldn't even be hooked under this condition, but let's be sure.
268
- if ( is_core_fse_active() ) {
269
- return $editor_settings;
270
- }
271
- $editor_settings['supportsTemplateMode'] = false;
272
- return $editor_settings;
273
- }
274
-
275
- /**
276
- * Hides the Template and Template Part Custom Post Types' UI
277
- *
278
- * @return void
279
- */
280
- function hide_template_cpts() {
281
- // This can interfere with Legacy FSE, bail if it's active.
282
- if ( is_full_site_editing_active() ) {
283
- return;
284
- }
285
- global $wp_post_types;
286
- if ( isset( $wp_post_types['wp_template'] ) ) {
287
- $wp_post_types['wp_template']->show_ui = false;
288
- }
289
- if ( isset( $wp_post_types['wp_template_part'] ) ) {
290
- $wp_post_types['wp_template_part']->show_ui = false;
291
- }
292
- }
293
-
294
- /**
295
- * Prints the screen for our toggle page
296
- *
297
- * @return void
298
- */
299
- function menu_page() {
300
- ?>
301
- <div
302
- id="site-editor-toggle"
303
- class="wrap"
304
- >
305
- <h1><?php esc_html_e( 'Full Site Editing (beta)', 'full-site-editing' ); ?></h1>
306
- <?php settings_errors(); ?>
307
- <form method="post" action="options.php">
308
- <?php settings_fields( 'site-editor-toggle' ); ?>
309
- <?php do_settings_sections( 'site-editor-toggle' ); ?>
310
- <?php submit_button(); ?>
311
- </form>
312
- </div>
313
- <?php
314
- }
315
-
316
  /**
317
  * Adds our settings sections and fields
318
  *
319
  * @return void
320
  */
321
  function init_settings() {
322
- add_settings_section(
323
- 'fse_toggle_section',
324
- // The empty string ensures the render function won't output a h2.
325
- '',
326
- __NAMESPACE__ . '\display_fse_section',
327
- 'site-editor-toggle'
328
- );
329
- add_settings_field(
330
- 'fse-universal-theme-toggle',
331
- __( 'Site Editor', 'full-site-editing' ),
332
- __NAMESPACE__ . '\do_field',
333
- 'site-editor-toggle',
334
- 'fse_toggle_section'
335
- );
336
  register_setting(
337
  'site-editor-toggle',
338
  ACTIVATE_FSE_OPTION_NAME
339
  );
340
  }
341
 
342
- /**
343
- * Prints our setting field
344
- *
345
- * @return void
346
- */
347
- function do_field() {
348
- $value = (bool) get_option( ACTIVATE_FSE_OPTION_NAME ) ? 1 : 0;
349
- $for_sprintf = <<<HTML
350
- <label for="%s">
351
- <input type="checkbox" name="%s" id="%s" value="1" %s />
352
- %s
353
- </label>
354
- HTML;
355
- // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
356
- printf(
357
- $for_sprintf,
358
- ACTIVATE_FSE_OPTION_NAME,
359
- ACTIVATE_FSE_OPTION_NAME,
360
- ACTIVATE_FSE_OPTION_NAME,
361
- checked( 1, $value, false ),
362
- esc_html__( 'Enable Site Editor', 'full-site-editing' )
363
- );
364
- // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
365
- }
366
-
367
- /**
368
- * Prints our settings section
369
- *
370
- * @return void
371
- */
372
- function display_fse_section() {
373
- printf(
374
- '<p>%s</p>',
375
- esc_html__( 'The Site Editor is an exciting new direction for WordPress themes! Blocks are now the foundation of your whole site and everything is editable.', 'full-site-editing' )
376
- );
377
- }
378
-
379
- /**
380
- * Hide the Core Site Editor (in addition to the Gutenberg one) when unloading Core FSE.
381
- *
382
- * @return void
383
- */
384
- function hide_core_site_editor() {
385
- remove_submenu_page( 'themes.php', 'site-editor.php' );
386
- }
387
-
388
  /**
389
  * Hide the (Nav) Menus submenu when site editing is enabled
390
  *
15
  define( 'ACTIVATE_FSE_OPTION_NAME', 'wpcom_is_fse_activated' );
16
 
17
  /**
18
+ * TODO - NOTE - This function becomes unnecessary when we enable all universal themes to run in FSE
19
+ * mode as it can be replaced by `is_fse_theme`. We can clean this up after removing backend
20
+ * references.
21
+ *
22
+ * Checks if Core's FSE is active via this plugin, always returning false when
23
+ * `gutenberg_is_fse_theme` is false.
24
  *
25
  * @return boolean Core FSE is active.
26
  */
27
  function is_core_fse_active() {
28
+ // Always run FSE for eligible themes, including universal.
29
+ return is_fse_theme();
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
 
32
  /**
63
  }
64
 
65
  /**
66
+ * TODO - Cleanup once backend references are removed, this option is no longer required to run FSE
67
+ * for universal themes.
68
+ *
69
+ * Activates Core FSE by setting our option. Note that even setting this
70
+ * option to true will make no difference on a classic theme.
71
  *
72
  * @return void
73
  */
76
  }
77
 
78
  /**
79
+ * TODO - Cleanup once backend references are removed, this option is no longer required to run FSE
80
+ * for universal themes.
81
+ *
82
  * Deactivates Core FSE by setting the option to NULL (matches the Options API).
83
  *
84
  * @return void
94
  */
95
  function load_core_fse() {
96
  // perfect parity would put the admin notices back but we don't want that.
 
 
 
97
  add_action( 'admin_menu', __NAMESPACE__ . '\hide_nav_menus_submenu' );
 
 
 
 
 
98
  }
99
 
100
  /**
101
+ * Unhooks the Gutenberg notice for Full Site Editing.
102
  *
103
  * @return void
104
  */
105
  function unload_core_fse() {
 
 
 
 
106
  remove_action( 'admin_menu', __NAMESPACE__ . '\hide_nav_menus_submenu' );
107
+ remove_action( 'admin_notices', 'gutenberg_full_site_editing_notice' );
 
 
 
 
 
 
 
 
 
 
 
108
  }
109
 
110
  /**
127
  // This menu toggles site editor visibility for universal themes.
128
  // It's unnecessary for block themes because the site editor
129
  // will always be visible.
 
 
 
 
130
  add_action( 'admin_init', __NAMESPACE__ . '\init_settings' );
131
  }
132
 
136
  * @return void
137
  */
138
  function unload_helpers() {
 
 
139
  remove_action( 'admin_init', __NAMESPACE__ . '\init_settings' );
140
  remove_action( 'admin_menu', __NAMESPACE__ . '\maybe_juggle_amp_priority', 0 );
141
  }
157
  add_action( 'admin_menu', 'amp_add_customizer_link', 11 );
158
  }
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  /**
161
  * Adds our settings sections and fields
162
  *
163
  * @return void
164
  */
165
  function init_settings() {
166
+ // TODO - Clean up this setting registration once we clean up adding this setting on site
167
+ // creation.
 
 
 
 
 
 
 
 
 
 
 
 
168
  register_setting(
169
  'site-editor-toggle',
170
  ACTIVATE_FSE_OPTION_NAME
171
  );
172
  }
173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  /**
175
  * Hide the (Nav) Menus submenu when site editing is enabled
176
  *