PluginProbe
Gutenberg / 19.6.1
Gutenberg v19.6.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
← All changes | lib/blocks.php +162 -39 23.5.119.6.1 View file →
@@ -9,32 +9,168 @@
9 9 * Substitutes the implementation of a core-registered block type, if exists,
10 10 * with the built result from the plugin.
11 11 */
12 12 function gutenberg_reregister_core_block_types() {
13 + // Blocks directory may not exist if working from a fresh clone.
13 14 $blocks_dirs = array(
14 - __DIR__ . '/../build/scripts/block-library/',
15 - __DIR__ . '/../build/scripts/edit-widgets/blocks/',
16 - __DIR__ . '/../build/scripts/widgets/blocks/',
15 + __DIR__ . '/../build/block-library/blocks/' => array(
16 + 'block_folders' => array(
17 + 'audio',
18 + 'button',
19 + 'buttons',
20 + 'freeform',
21 + 'code',
22 + 'column',
23 + 'columns',
24 + 'details',
25 + 'form-input',
26 + 'form-submit-button',
27 + 'group',
28 + 'html',
29 + 'list-item',
30 + 'missing',
31 + 'more',
32 + 'nextpage',
33 + 'paragraph',
34 + 'preformatted',
35 + 'pullquote',
36 + 'quote',
37 + 'separator',
38 + 'social-links',
39 + 'spacer',
40 + 'table',
41 + 'table-of-contents',
42 + 'text-columns',
43 + 'verse',
44 + 'video',
45 + 'embed',
46 + ),
47 + 'block_names' => array(
48 + 'archives.php' => 'core/archives',
49 + 'avatar.php' => 'core/avatar',
50 + 'block.php' => 'core/block',
51 + 'button.php' => 'core/button',
52 + 'calendar.php' => 'core/calendar',
53 + 'categories.php' => 'core/categories',
54 + 'cover.php' => 'core/cover',
55 + 'comment-author-avatar.php' => 'core/comment-author-avatar',
56 + 'comment-author-name.php' => 'core/comment-author-name',
57 + 'comment-content.php' => 'core/comment-content',
58 + 'comment-date.php' => 'core/comment-date',
59 + 'comment-edit-link.php' => 'core/comment-edit-link',
60 + 'comment-reply-link.php' => 'core/comment-reply-link',
61 + 'comment-template.php' => 'core/comment-template',
62 + 'comments-pagination.php' => 'core/comments-pagination',
63 + 'comments-pagination-next.php' => 'core/comments-pagination-next',
64 + 'comments-pagination-numbers.php' => 'core/comments-pagination-numbers',
65 + 'comments-pagination-previous.php' => 'core/comments-pagination-previous',
66 + 'comments-title.php' => 'core/comments-title',
67 + 'comments.php' => 'core/comments',
68 + 'footnotes.php' => 'core/footnotes',
69 + 'file.php' => 'core/file',
70 + 'form.php' => 'core/form',
71 + 'form-input.php' => 'core/form-input',
72 + 'form-submission-notification.php' => 'core/form-submission-notification',
73 + 'home-link.php' => 'core/home-link',
74 + 'image.php' => 'core/image',
75 + 'gallery.php' => 'core/gallery',
76 + 'heading.php' => 'core/heading',
77 + 'latest-comments.php' => 'core/latest-comments',
78 + 'latest-posts.php' => 'core/latest-posts',
79 + 'list.php' => 'core/list',
80 + 'loginout.php' => 'core/loginout',
81 + 'media-text.php' => 'core/media-text',
82 + 'navigation.php' => 'core/navigation',
83 + 'navigation-link.php' => 'core/navigation-link',
84 + 'navigation-submenu.php' => 'core/navigation-submenu',
85 + 'page-list.php' => 'core/page-list',
86 + 'page-list-item.php' => 'core/page-list-item',
87 + 'pattern.php' => 'core/pattern',
88 + 'post-author.php' => 'core/post-author',
89 + 'post-author-name.php' => 'core/post-author-name',
90 + 'post-author-biography.php' => 'core/post-author-biography',
91 + 'post-comment.php' => 'core/post-comment',
92 + 'post-comments-count.php' => 'core/post-comments-count',
93 + 'post-comments-form.php' => 'core/post-comments-form',
94 + 'post-comments-link.php' => 'core/post-comments-link',
95 + 'post-content.php' => 'core/post-content',
96 + 'post-date.php' => 'core/post-date',
97 + 'post-excerpt.php' => 'core/post-excerpt',
98 + 'post-featured-image.php' => 'core/post-featured-image',
99 + 'post-navigation-link.php' => 'core/post-navigation-link',
100 + 'post-terms.php' => 'core/post-terms',
101 + 'post-time-to-read.php' => 'core/post-time-to-read',
102 + 'post-title.php' => 'core/post-title',
103 + 'query.php' => 'core/query',
104 + 'post-template.php' => 'core/post-template',
105 + 'query-no-results.php' => 'core/query-no-results',
106 + 'query-pagination.php' => 'core/query-pagination',
107 + 'query-pagination-next.php' => 'core/query-pagination-next',
108 + 'query-pagination-numbers.php' => 'core/query-pagination-numbers',
109 + 'query-pagination-previous.php' => 'core/query-pagination-previous',
110 + 'query-title.php' => 'core/query-title',
111 + 'read-more.php' => 'core/read-more',
112 + 'rss.php' => 'core/rss',
113 + 'search.php' => 'core/search',
114 + 'shortcode.php' => 'core/shortcode',
115 + 'social-link.php' => 'core/social-link',
116 + 'site-logo.php' => 'core/site-logo',
117 + 'site-tagline.php' => 'core/site-tagline',
118 + 'site-title.php' => 'core/site-title',
119 + 'tag-cloud.php' => 'core/tag-cloud',
120 + 'template-part.php' => 'core/template-part',
121 + 'term-description.php' => 'core/term-description',
122 + ),
123 + ),
124 + __DIR__ . '/../build/edit-widgets/blocks/' => array(
125 + 'block_folders' => array(
126 + 'widget-area',
127 + ),
128 + 'block_names' => array(),
129 + ),
130 + __DIR__ . '/../build/widgets/blocks/' => array(
131 + 'block_folders' => array(
132 + 'legacy-widget',
133 + 'widget-group',
134 + ),
135 + 'block_names' => array(
136 + 'legacy-widget.php' => 'core/legacy-widget',
137 + 'widget-group.php' => 'core/widget-group',
138 + ),
139 + ),
17 140 );
141 + foreach ( $blocks_dirs as $blocks_dir => $details ) {
142 + $block_folders = $details['block_folders'];
143 + $block_names = $details['block_names'];
18 144
19 - foreach ( $blocks_dirs as $blocks_dir ) {
20 - $manifest_path = $blocks_dir . 'blocks-manifest.php';
21 - $blocks = require $manifest_path;
145 + foreach ( $block_folders as $folder_name ) {
146 + $block_json_file = $blocks_dir . $folder_name . '/block.json';
22 147
23 - foreach ( $blocks as $block_name_folder => $metadata ) {
24 - if ( ! is_array( $metadata ) || ! isset( $metadata['name'] ) ) {
148 + // Ideally, all paths to block metadata files should be listed in
149 + // WordPress core. In this place we should rather use filter
150 + // to replace paths with overrides defined by the plugin.
151 + $metadata = json_decode( file_get_contents( $block_json_file ), true );
152 + if ( ! is_array( $metadata ) || ! $metadata['name'] ) {
25 153 continue;
26 154 }
27 155
28 156 gutenberg_deregister_core_block_and_assets( $metadata['name'] );
29 - gutenberg_register_core_block_assets( $block_name_folder );
157 + gutenberg_register_core_block_assets( $folder_name );
158 + register_block_type_from_metadata( $block_json_file );
159 + }
30 160
31 - $php_file = $blocks_dir . $block_name_folder . '.php';
32 - if ( file_exists( $php_file ) ) {
33 - require_once $php_file;
34 - } else {
35 - register_block_type_from_metadata( $blocks_dir . $block_name_folder );
161 + foreach ( $block_names as $file => $sub_block_names ) {
162 + if ( ! file_exists( $blocks_dir . $file ) ) {
163 + continue;
36 164 }
165 +
166 + $sub_block_names_normalized = is_string( $sub_block_names ) ? array( $sub_block_names ) : $sub_block_names;
167 + foreach ( $sub_block_names_normalized as $block_name ) {
168 + gutenberg_deregister_core_block_and_assets( $block_name );
169 + gutenberg_register_core_block_assets( $block_name );
170 + }
171 +
172 + require_once $blocks_dir . $file;
37 173 }
38 174 }
39 175 }
40 176
@@ -52,10 +188,10 @@
52 188 * @ @ -153,7 +153,8 @ @ function register_block_script_handle( $metadata, $field_name, $index = 0 ) {
53 189 * $script_handle,
54 190 * $script_uri,
55 191 * $script_dependencies,
56 - * - $script_asset['version'] ?? false
57 - * + $script_asset['version'] ?? false,
192 + * - isset( $script_asset['version'] ) ? $script_asset['version'] : false
193 + * + isset( $script_asset['version'] ) ? $script_asset['version'] : false,
58 194 * + array( 'strategy' => 'defer' )
59 195 * );
60 196 * if ( ! $result ) {
61 197 * return false;
@@ -103,17 +239,8 @@
103 239 *
104 240 * @return void
105 241 */
106 242 function gutenberg_register_core_block_assets( $block_name ) {
107 - static $gutenberg_url_root = null;
108 - // Running `gutenberg_url` inside of a loop can be expensive in systems with
109 - // many callbacks attached to the `plugins_url` hook.
110 - // Since all of the paths have the same root, we can instead retrieve the
111 - // corresponding URL root once, and manually concatenate the URL below.
112 - if ( is_null( $gutenberg_url_root ) ) {
113 - $gutenberg_url_root = gutenberg_url( '/' );
114 - }
115 -
116 243 if ( ! wp_should_load_separate_core_block_assets() ) {
117 244 return;
118 245 }
119 246
@@ -121,16 +248,14 @@
121 248
122 249 // When in production, use the plugin's version as the default asset version;
123 250 // else (for development or test) default to use the current time.
124 251 $default_version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time();
125 - $suffix = SCRIPT_DEBUG ? '' : '.min';
126 252
127 - $style_path = "build/styles/block-library/$block_name/";
128 - $stylesheet_url = $gutenberg_url_root . $style_path . 'style' . $suffix . '.css';
129 - $stylesheet_path = gutenberg_dir_path() . $style_path . ( is_rtl() ? 'style-rtl' . $suffix . '.css' : 'style' . $suffix . '.css' );
253 + $style_path = "build/block-library/blocks/$block_name/";
254 + $stylesheet_url = gutenberg_url( $style_path . 'style.css' );
255 + $stylesheet_path = gutenberg_dir_path() . $style_path . ( is_rtl() ? 'style-rtl.css' : 'style.css' );
130 256
131 257 if ( file_exists( $stylesheet_path ) ) {
132 -
133 258 wp_deregister_style( "wp-block-{$block_name}" );
134 259 wp_register_style(
135 260 "wp-block-{$block_name}",
136 261 $stylesheet_url,
@@ -137,9 +262,9 @@
137 262 array(),
138 263 $default_version
139 264 );
140 265 wp_style_add_data( "wp-block-{$block_name}", 'rtl', 'replace' );
141 - wp_style_add_data( "wp-block-{$block_name}", 'suffix', $suffix );
266 +
142 267 // Add a reference to the stylesheet's path to allow calculations for inlining styles in `wp_head`.
143 268 wp_style_add_data( "wp-block-{$block_name}", 'path', $stylesheet_path );
144 269 } else {
145 270 wp_register_style( "wp-block-{$block_name}", false, array() );
@@ -152,10 +277,10 @@
152 277 if ( current_theme_supports( 'wp-block-styles' ) ) {
153 278
154 279 // Get the path to the block's stylesheet.
155 280 $theme_style_path = is_rtl()
156 - ? "build/styles/block-library/$block_name/theme-rtl{$suffix}.css"
157 - : "build/styles/block-library/$block_name/theme{$suffix}.css";
281 + ? "build/block-library/blocks/$block_name/theme-rtl.css"
282 + : "build/block-library/blocks/$block_name/theme.css";
158 283
159 284 // If the file exists, enqueue it.
160 285 if ( file_exists( gutenberg_dir_path() . $theme_style_path ) ) {
161 286 wp_deregister_style( "wp-block-{$block_name}-theme" );
@@ -160,28 +285,26 @@
160 285 if ( file_exists( gutenberg_dir_path() . $theme_style_path ) ) {
161 286 wp_deregister_style( "wp-block-{$block_name}-theme" );
162 287 wp_register_style(
163 288 "wp-block-{$block_name}-theme",
164 - $gutenberg_url_root . $theme_style_path,
289 + gutenberg_url( $theme_style_path ),
165 290 array(),
166 291 $default_version
167 292 );
168 293 wp_style_add_data( "wp-block-{$block_name}-theme", 'path', gutenberg_dir_path() . $theme_style_path );
169 - wp_style_add_data( "wp-block-{$block_name}-theme", 'suffix', $suffix );
170 294 }
171 295 }
172 296
173 - $editor_style_path = "build/styles/block-library/$block_name/style-editor{$suffix}.css";
297 + $editor_style_path = "build/block-library/blocks/$block_name/style-editor.css";
174 298 if ( file_exists( gutenberg_dir_path() . $editor_style_path ) ) {
175 299 wp_deregister_style( "wp-block-{$block_name}-editor" );
176 300 wp_register_style(
177 301 "wp-block-{$block_name}-editor",
178 - $gutenberg_url_root . $editor_style_path,
302 + gutenberg_url( $editor_style_path ),
179 303 array(),
180 304 $default_version
181 305 );
182 306 wp_style_add_data( "wp-block-{$block_name}-editor", 'rtl', 'replace' );
183 - wp_style_add_data( "wp-block-{$block_name}-editor", 'suffix', $suffix );
184 307 } else {
185 308 wp_register_style( "wp-block-{$block_name}-editor", false );
186 309 }
187 310 }
@@ -197,9 +320,9 @@
197 320 *
198 321 * This shim is INTENTIONALLY left out of core, as Social Links have never
199 322 * landed there.
200 323 *
201 - * @link https://github.com/WordPress/gutenberg/pull/19887
324 + * @see https://github.com/WordPress/gutenberg/pull/19887
202 325 */
203 326 function gutenberg_register_legacy_social_link_blocks() {
204 327 $services = array(
205 328 'amazon',