PluginProbe
Gutenberg / 9.5.0
Gutenberg v9.5.0
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.5.0, at lib/blocks.php

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