Commit 4571c1b 1 parent 66d46b3 commit 4571c1b Copy full SHA for 4571c1b
File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Block Pattern functionality.
4
+ *
5
+ * @package gutenberg
6
+ */
7
+
8
+ /**
9
+ * Register "core" patterns from the WordPress.org pattern directory.
10
+ */
11
+ function gutenberg_register_remote_block_patterns () {
12
+ $ should_register_core_patterns = get_theme_support ( 'core-block-patterns ' );
13
+
14
+ // Unregister the bundled core patterns.
15
+ $ patterns = WP_Block_Patterns_Registry::get_instance ()->get_all_registered ();
16
+ foreach ( $ patterns as $ pattern ) {
17
+ if ( 'core/ ' === substr ( $ pattern ['name ' ], 0 , 5 ) ) {
18
+ unregister_block_pattern ( $ pattern ['name ' ] );
19
+ }
20
+ }
21
+
22
+ if ( $ should_register_core_patterns ) {
23
+ $ request = new WP_REST_Request ( 'GET ' , '/__experimental/pattern-directory/patterns ' );
24
+ $ request ->set_param ( 'keyword ' , 11 ); // 11 is the ID for "core".
25
+ $ response = rest_do_request ( $ request );
26
+ if ( $ response ->is_error () ) {
27
+ return ;
28
+ }
29
+ $ patterns = $ response ->get_data ();
30
+ foreach ( $ patterns as $ settings ) {
31
+ $ pattern_name = 'core/ ' . sanitize_title ( $ settings ['title ' ] );
32
+ register_block_pattern ( $ pattern_name , (array ) $ settings );
33
+ }
34
+ }
35
+ }
36
+ add_action ( 'init ' , 'gutenberg_register_remote_block_patterns ' , 11 );
Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ function gutenberg_is_experiment_enabled( $name ) {
108
108
require __DIR__ . '/full-site-editing/edit-site-page.php ' ;
109
109
require __DIR__ . '/full-site-editing/edit-site-export.php ' ;
110
110
111
+ require __DIR__ . '/block-patterns.php ' ;
111
112
require __DIR__ . '/blocks.php ' ;
112
113
require __DIR__ . '/client-assets.php ' ;
113
114
require __DIR__ . '/demo.php ' ;
You can’t perform that action at this time.
0 commit comments