PluginProbe
Gutenberg / 9.1.1
Gutenberg v9.1.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.1.1, at lib/blocks.php

240 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 'widget-area',
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 ),
100 'block_names' => array(
101 'legacy-widget.php' => 'core/legacy-widget',
102 ),
103 ),
104 );
105 foreach ( $blocks_dirs as $blocks_dir => $details ) {
106 if ( ! file_exists( $blocks_dir ) ) {
107 return;
108 }
109 $block_folders = $details['block_folders'];
110 $block_names = $details['block_names'];
111
112 $registry = WP_Block_Type_Registry::get_instance();
113
114 foreach ( $block_folders as $folder_name ) {
115 $block_json_file = $blocks_dir . $folder_name . '/block.json';
116 if ( ! file_exists( $block_json_file ) ) {
117 return;
118 }
119
120 // Ideally, all paths to block metadata files should be listed in
121 // WordPress core. In this place we should rather use filter
122 // to replace paths with overrides defined by the plugin.
123 $metadata = json_decode( file_get_contents( $block_json_file ), true );
124 if ( ! is_array( $metadata ) || ! $metadata['name'] ) {
125 return false;
126 }
127
128 if ( $registry->is_registered( $metadata['name'] ) ) {
129 $registry->unregister( $metadata['name'] );
130 }
131
132 register_block_type_from_metadata( $block_json_file );
133 }
134
135 foreach ( $block_names as $file => $block_names ) {
136 if ( ! file_exists( $blocks_dir . $file ) ) {
137 return;
138 }
139
140 if ( is_string( $block_names ) ) {
141 if ( $registry->is_registered( $block_names ) ) {
142 $registry->unregister( $block_names );
143 }
144 } elseif ( is_array( $block_names ) ) {
145 foreach ( $block_names as $block_name ) {
146 if ( $registry->is_registered( $block_name ) ) {
147 $registry->unregister( $block_name );
148 }
149 }
150 }
151
152 require $blocks_dir . $file;
153 }
154 }
155 }
156
157 add_action( 'init', 'gutenberg_reregister_core_block_types' );
158
159 /**
160 * Complements the implementation of block type `core/social-icon`, whether it
161 * be provided by core or the plugin, with derived block types for each
162 * "service" (WordPress, Twitter, etc.) supported by Social Links.
163 *
164 * This ensures backwards compatibility for any users running the Gutenberg
165 * plugin who have used Social Links prior to their conversion to block
166 * variations.
167 *
168 * This shim is INTENTIONALLY left out of core, as Social Links haven't yet
169 * landed there.
170 *
171 * @see https://github.com/WordPress/gutenberg/pull/19887
172 */
173 function gutenberg_register_legacy_social_link_blocks() {
174 $services = array(
175 'amazon',
176 'bandcamp',
177 'behance',
178 'chain',
179 'codepen',
180 'deviantart',
181 'dribbble',
182 'dropbox',
183 'etsy',
184 'facebook',
185 'feed',
186 'fivehundredpx',
187 'flickr',
188 'foursquare',
189 'goodreads',
190 'google',
191 'github',
192 'instagram',
193 'lastfm',
194 'linkedin',
195 'mail',
196 'mastodon',
197 'meetup',
198 'medium',
199 'pinterest',
200 'pocket',
201 'reddit',
202 'skype',
203 'snapchat',
204 'soundcloud',
205 'spotify',
206 'tumblr',
207 'twitch',
208 'twitter',
209 'vimeo',
210 'vk',
211 'wordpress',
212 'yelp',
213 'youtube',
214 );
215
216 foreach ( $services as $service ) {
217 register_block_type(
218 'core/social-link-' . $service,
219 array(
220 'category' => 'widgets',
221 'attributes' => array(
222 'url' => array(
223 'type' => 'string',
224 ),
225 'service' => array(
226 'type' => 'string',
227 'default' => $service,
228 ),
229 'label' => array(
230 'type' => 'string',
231 ),
232 ),
233 'render_callback' => 'gutenberg_render_block_core_social_link',
234 )
235 );
236 }
237 }
238
239 add_action( 'init', 'gutenberg_register_legacy_social_link_blocks' );
240