PluginProbe
Gutenberg / 9.2.1
Gutenberg v9.2.1
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / blocks.php

blocks.php in Gutenberg 9.2.1, at lib/blocks.php

242 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Block and style registration functions.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Substitutes the implementation of a core-registered block type, if exists,
10 * with the built result from the plugin.
11 */
12 function gutenberg_reregister_core_block_types() {
13 // Blocks directory may not exist if working from a fresh clone.
14 $blocks_dirs = array(
15 dirname( __FILE__ ) . '/../build/block-library/blocks/' => array(
16 'block_folders' => array(
17 'audio',
18 'button',
19 'buttons',
20 'classic',
21 'code',
22 'column',
23 'columns',
24 'file',
25 'gallery',
26 'group',
27 'heading',
28 'html',
29 'image',
30 'list',
31 'media-text',
32 'missing',
33 'more',
34 'navigation-link',
35 'nextpage',
36 'paragraph',
37 'preformatted',
38 'pullquote',
39 'quote',
40 'separator',
41 'social-links',
42 'spacer',
43 'subhead',
44 'table',
45 'text-columns',
46 'verse',
47 'video',
48 'embed',
49 ),
50 'block_names' => array_merge(
51 array(
52 'archives.php' => 'core/archives',
53 'block.php' => 'core/block',
54 'calendar.php' => 'core/calendar',
55 'categories.php' => 'core/categories',
56 'cover.php' => 'core/cover',
57 'latest-comments.php' => 'core/latest-comments',
58 'latest-posts.php' => 'core/latest-posts',
59 'navigation.php' => 'core/navigation',
60 'navigation-link.php' => 'core/navigation-link',
61 'rss.php' => 'core/rss',
62 'search.php' => 'core/search',
63 'shortcode.php' => 'core/shortcode',
64 'social-link.php' => 'core/social-link',
65 'tag-cloud.php' => 'core/tag-cloud',
66 ),
67 ! gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing' )
68 ? array()
69 :
70 array(
71 'post-author.php' => 'core/post-author',
72 'post-comment.php' => 'core/post-comment',
73 'post-comment-author.php' => 'core/post-comment-author',
74 'post-comment-content.php' => 'core/post-comment-content',
75 'post-comment-date.php' => 'core/post-comment-date',
76 'post-comments.php' => 'core/post-comments',
77 'post-comments-count.php' => 'core/post-comments-count',
78 'post-comments-form.php' => 'core/post-comments-form',
79 'post-content.php' => 'core/post-content',
80 'post-date.php' => 'core/post-date',
81 'post-excerpt.php' => 'core/post-excerpt',
82 'post-featured-image.php' => 'core/post-featured-image',
83 'post-hierarchical-terms.php' => 'core/post-hierarchical-terms',
84 'post-tags.php' => 'core/post-tags',
85 'post-title.php' => 'core/post-title',
86 'query.php' => 'core/query',
87 'query-loop.php' => 'core/query-loop',
88 'query-pagination.php' => 'core/query-pagination',
89 'site-logo.php' => 'core/site-logo',
90 'site-tagline.php' => 'core/site-tagline',
91 'site-title.php' => 'core/site-title',
92 'template-part.php' => 'core/template-part',
93 )
94 ),
95 ),
96 dirname( __FILE__ ) . '/../build/edit-widgets/blocks/' => array(
97 'block_folders' => array(
98 'legacy-widget',
99 'widget-area',
100 ),
101 'block_names' => array(
102 'legacy-widget.php' => 'core/legacy-widget',
103 'widget-area.php' => 'core/widget-area',
104 ),
105 ),
106 );
107 foreach ( $blocks_dirs as $blocks_dir => $details ) {
108 if ( ! file_exists( $blocks_dir ) ) {
109 return;
110 }
111 $block_folders = $details['block_folders'];
112 $block_names = $details['block_names'];
113
114 $registry = WP_Block_Type_Registry::get_instance();
115
116 foreach ( $block_folders as $folder_name ) {
117 $block_json_file = $blocks_dir . $folder_name . '/block.json';
118 if ( ! file_exists( $block_json_file ) ) {
119 return;
120 }
121
122 // Ideally, all paths to block metadata files should be listed in
123 // WordPress core. In this place we should rather use filter
124 // to replace paths with overrides defined by the plugin.
125 $metadata = json_decode( file_get_contents( $block_json_file ), true );
126 if ( ! is_array( $metadata ) || ! $metadata['name'] ) {
127 return false;
128 }
129
130 if ( $registry->is_registered( $metadata['name'] ) ) {
131 $registry->unregister( $metadata['name'] );
132 }
133
134 register_block_type_from_metadata( $block_json_file );
135 }
136
137 foreach ( $block_names as $file => $block_names ) {
138 if ( ! file_exists( $blocks_dir . $file ) ) {
139 return;
140 }
141
142 if ( is_string( $block_names ) ) {
143 if ( $registry->is_registered( $block_names ) ) {
144 $registry->unregister( $block_names );
145 }
146 } elseif ( is_array( $block_names ) ) {
147 foreach ( $block_names as $block_name ) {
148 if ( $registry->is_registered( $block_name ) ) {
149 $registry->unregister( $block_name );
150 }
151 }
152 }
153
154 require $blocks_dir . $file;
155 }
156 }
157 }
158
159 add_action( 'init', 'gutenberg_reregister_core_block_types' );
160
161 /**
162 * Complements the implementation of block type `core/social-icon`, whether it
163 * be provided by core or the plugin, with derived block types for each
164 * "service" (WordPress, Twitter, etc.) supported by Social Links.
165 *
166 * This ensures backwards compatibility for any users running the Gutenberg
167 * plugin who have used Social Links prior to their conversion to block
168 * variations.
169 *
170 * This shim is INTENTIONALLY left out of core, as Social Links haven't yet
171 * landed there.
172 *
173 * @see https://github.com/WordPress/gutenberg/pull/19887
174 */
175 function gutenberg_register_legacy_social_link_blocks() {
176 $services = array(
177 'amazon',
178 'bandcamp',
179 'behance',
180 'chain',
181 'codepen',
182 'deviantart',
183 'dribbble',
184 'dropbox',
185 'etsy',
186 'facebook',
187 'feed',
188 'fivehundredpx',
189 'flickr',
190 'foursquare',
191 'goodreads',
192 'google',
193 'github',
194 'instagram',
195 'lastfm',
196 'linkedin',
197 'mail',
198 'mastodon',
199 'meetup',
200 'medium',
201 'pinterest',
202 'pocket',
203 'reddit',
204 'skype',
205 'snapchat',
206 'soundcloud',
207 'spotify',
208 'tumblr',
209 'twitch',
210 'twitter',
211 'vimeo',
212 'vk',
213 'wordpress',
214 'yelp',
215 'youtube',
216 );
217
218 foreach ( $services as $service ) {
219 register_block_type(
220 'core/social-link-' . $service,
221 array(
222 'category' => 'widgets',
223 'attributes' => array(
224 'url' => array(
225 'type' => 'string',
226 ),
227 'service' => array(
228 'type' => 'string',
229 'default' => $service,
230 ),
231 'label' => array(
232 'type' => 'string',
233 ),
234 ),
235 'render_callback' => 'gutenberg_render_block_core_social_link',
236 )
237 );
238 }
239 }
240
241 add_action( 'init', 'gutenberg_register_legacy_social_link_blocks' );
242