Full Site Editing - Version 3.6725

Version Description

Download this release

Release Info

Developer ramonopoly
Plugin Icon wp plugin Full Site Editing
Version 3.6725
Comparing to
See all releases

Code changes from version 3.6678 to 3.6725

block-patterns/class-block-patterns-from-api.php CHANGED
@@ -44,6 +44,15 @@ class Block_Patterns_From_API {
44
  */
45
  private $utils;
46
 
 
 
 
 
 
 
 
 
 
47
  /**
48
  * Block_Patterns constructor.
49
  *
@@ -54,6 +63,13 @@ class Block_Patterns_From_API {
54
  $patterns_sources = empty( $patterns_sources ) ? array( 'block_patterns' ) : $patterns_sources;
55
  $this->patterns_sources = empty( array_diff( $patterns_sources, $this->valid_patterns_sources ) ) ? $patterns_sources : array( 'block_patterns' );
56
  $this->utils = empty( $utils ) ? new \A8C\FSE\Block_Patterns_Utils() : $utils;
 
 
 
 
 
 
 
57
  }
58
 
59
  /**
@@ -62,14 +78,7 @@ class Block_Patterns_From_API {
62
  * @return array Results of pattern registration.
63
  */
64
  public function register_patterns() {
65
- if ( class_exists( 'WP_Block_Patterns_Registry' ) ) {
66
- // Remove core patterns.
67
- foreach ( \WP_Block_Patterns_Registry::get_instance()->get_all_registered() as $pattern ) {
68
- if ( 'core/' === substr( $pattern['name'], 0, 5 ) ) {
69
- unregister_block_pattern( $pattern['name'] );
70
- }
71
- }
72
- }
73
 
74
  // Used to track which patterns we successfully register.
75
  $results = array();
@@ -141,6 +150,9 @@ class Block_Patterns_From_API {
141
  }
142
  }
143
  }
 
 
 
144
  return $results;
145
  }
146
 
@@ -188,21 +200,13 @@ class Block_Patterns_From_API {
188
  );
189
 
190
  $block_patterns = $this->utils->remote_get( $request_url );
 
191
  $this->utils->cache_add( $patterns_cache_key, $block_patterns, 'ptk_patterns', DAY_IN_SECONDS );
192
  }
193
 
194
  return $block_patterns;
195
  }
196
 
197
- /**
198
- * Get the locale to be used for fetching block patterns
199
- */
200
- private function get_block_patterns_locale() {
201
- // Make sure to get blog locale, not user locale.
202
- $language = function_exists( 'get_blog_lang_code' ) ? get_blog_lang_code() : get_locale();
203
- return \A8C\FSE\Common\get_iso_639_locale( $language );
204
- }
205
-
206
  /**
207
  * Check that the pattern is allowed to be registered.
208
  *
@@ -236,5 +240,56 @@ class Block_Patterns_From_API {
236
 
237
  return true;
238
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  }
240
 
44
  */
45
  private $utils;
46
 
47
+ /**
48
+ * A dictionary to map existing WPCOM pattern categories to core patterns.
49
+ * These should match the categories in $patterns_sources,
50
+ * which are registered in $this->register_patterns()
51
+ *
52
+ * @var array
53
+ */
54
+ private $core_to_wpcom_categories_dictionary;
55
+
56
  /**
57
  * Block_Patterns constructor.
58
  *
63
  $patterns_sources = empty( $patterns_sources ) ? array( 'block_patterns' ) : $patterns_sources;
64
  $this->patterns_sources = empty( array_diff( $patterns_sources, $this->valid_patterns_sources ) ) ? $patterns_sources : array( 'block_patterns' );
65
  $this->utils = empty( $utils ) ? new \A8C\FSE\Block_Patterns_Utils() : $utils;
66
+ // Add categories to this array using the core pattern name as the key for core patterns we wish to "recategorize".
67
+ $this->core_to_wpcom_categories_dictionary = array(
68
+ 'core/quote' => array(
69
+ 'quotes' => __( 'Quotes', 'full-site-editing' ),
70
+ 'text' => __( 'Text', 'full-site-editing' ),
71
+ ),
72
+ );
73
  }
74
 
75
  /**
78
  * @return array Results of pattern registration.
79
  */
80
  public function register_patterns() {
81
+ $this->reregister_core_patterns();
 
 
 
 
 
 
 
82
 
83
  // Used to track which patterns we successfully register.
84
  $results = array();
150
  }
151
  }
152
  }
153
+
154
+ $this->update_core_patterns_with_wpcom_categories();
155
+
156
  return $results;
157
  }
158
 
200
  );
201
 
202
  $block_patterns = $this->utils->remote_get( $request_url );
203
+
204
  $this->utils->cache_add( $patterns_cache_key, $block_patterns, 'ptk_patterns', DAY_IN_SECONDS );
205
  }
206
 
207
  return $block_patterns;
208
  }
209
 
 
 
 
 
 
 
 
 
 
210
  /**
211
  * Check that the pattern is allowed to be registered.
212
  *
240
 
241
  return true;
242
  }
243
+
244
+ /**
245
+ * Unregister all core patterns, then reregister core patterns in core WordPress only,
246
+ * that is those in wp-includes/block-patterns.php
247
+ * Gutenberg adds new and overrides existing core patterns. We don't want these for now.
248
+ */
249
+ private function reregister_core_patterns() {
250
+ if ( class_exists( 'WP_Block_Patterns_Registry' ) ) {
251
+ foreach ( \WP_Block_Patterns_Registry::get_instance()->get_all_registered() as $pattern ) {
252
+ // Gutenberg registers patterns with varying prefixes, but categorizes them using `core/*` in a blockTypes array.
253
+ // This will ensure we remove `query/*` blocks for example.
254
+ // TODO: We need to revisit our usage or $pattern['blockTypes']: they are currently an experimental feature and not guaranteed to reference `core/*` blocks.
255
+ $pattern_block_type_or_name = ! empty( $pattern['blockTypes'][0] ) ? $pattern['blockTypes'][0] : $pattern['name'];
256
+ if ( 'core/' === substr( $pattern_block_type_or_name, 0, 5 ) ) {
257
+ unregister_block_pattern( $pattern['name'] );
258
+ }
259
+ }
260
+ if ( function_exists( '_register_core_block_patterns_and_categories' ) ) {
261
+ $did_switch_locale = switch_to_locale( $this->utils->get_block_patterns_locale() );
262
+ _register_core_block_patterns_and_categories();
263
+ // The site locale might be the same as the current locale so switching could have failed in such instances.
264
+ if ( false !== $did_switch_locale ) {
265
+ restore_previous_locale();
266
+ }
267
+ }
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Update categories for core patterns if a records exists in $this->core_to_wpcom_categories_dictionary
273
+ * and reregister them.
274
+ */
275
+ private function update_core_patterns_with_wpcom_categories() {
276
+ if ( class_exists( 'WP_Block_Patterns_Registry' ) ) {
277
+ foreach ( \WP_Block_Patterns_Registry::get_instance()->get_all_registered() as $pattern ) {
278
+ $wpcom_categories = $this->core_to_wpcom_categories_dictionary[ $pattern['name'] ];
279
+ if ( isset( $wpcom_categories ) ) {
280
+ unregister_block_pattern( $pattern['name'] );
281
+ $pattern_properties = array_merge(
282
+ $pattern,
283
+ array( 'categories' => array_keys( $wpcom_categories ) )
284
+ );
285
+ unset( $pattern_properties['name'] );
286
+ register_block_pattern(
287
+ $pattern['name'],
288
+ $pattern_properties
289
+ );
290
+ }
291
+ }
292
+ }
293
+ }
294
  }
295
 
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.6678
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.6678' );
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.6725
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.6725' );
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.6678
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.6725
7
  Requires PHP: 5.6.20
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html