PluginProbe
Gutenberg / 8.5.1
Gutenberg v8.5.1
24.0.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 All 403 releases
gutenberg / lib / blocks.php

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

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