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 +163 -47 24.0.019.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
@@ -39,15 +175,8 @@
39 175 }
40 176
41 177 add_action( 'init', 'gutenberg_reregister_core_block_types' );
42 178
43 -/*
44 - * Remove the WordPress core filter to avoid generating a second tabs ID for
45 - * every tabs block: `wp_unique_prefixed_id()` advances a counter, so running
46 - * both copies makes the numbering skip.
47 - */
48 -remove_filter( 'render_block_context', 'block_core_tabs_provide_context', 10 );
49 -
50 179 /**
51 180 * Adds the defer loading strategy to all registered blocks.
52 181 *
53 182 * This function would not be part of core merge. Instead, the register_block_script_handle() function would be patched
@@ -59,10 +188,10 @@
59 188 * @ @ -153,7 +153,8 @ @ function register_block_script_handle( $metadata, $field_name, $index = 0 ) {
60 189 * $script_handle,
61 190 * $script_uri,
62 191 * $script_dependencies,
63 - * - $script_asset['version'] ?? false
64 - * + $script_asset['version'] ?? false,
192 + * - isset( $script_asset['version'] ) ? $script_asset['version'] : false
193 + * + isset( $script_asset['version'] ) ? $script_asset['version'] : false,
65 194 * + array( 'strategy' => 'defer' )
66 195 * );
67 196 * if ( ! $result ) {
68 197 * return false;
@@ -110,17 +239,8 @@
110 239 *
111 240 * @return void
112 241 */
113 242 function gutenberg_register_core_block_assets( $block_name ) {
114 - static $gutenberg_url_root = null;
115 - // Running `gutenberg_url` inside of a loop can be expensive in systems with
116 - // many callbacks attached to the `plugins_url` hook.
117 - // Since all of the paths have the same root, we can instead retrieve the
118 - // corresponding URL root once, and manually concatenate the URL below.
119 - if ( is_null( $gutenberg_url_root ) ) {
120 - $gutenberg_url_root = gutenberg_url( '/' );
121 - }
122 -
123 243 if ( ! wp_should_load_separate_core_block_assets() ) {
124 244 return;
125 245 }
126 246
@@ -128,16 +248,14 @@
128 248
129 249 // When in production, use the plugin's version as the default asset version;
130 250 // else (for development or test) default to use the current time.
131 251 $default_version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time();
132 - $suffix = SCRIPT_DEBUG ? '' : '.min';
133 252
134 - $style_path = "build/styles/block-library/$block_name/";
135 - $stylesheet_url = $gutenberg_url_root . $style_path . 'style' . $suffix . '.css';
136 - $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' );
137 256
138 257 if ( file_exists( $stylesheet_path ) ) {
139 -
140 258 wp_deregister_style( "wp-block-{$block_name}" );
141 259 wp_register_style(
142 260 "wp-block-{$block_name}",
143 261 $stylesheet_url,
@@ -144,9 +262,9 @@
144 262 array(),
145 263 $default_version
146 264 );
147 265 wp_style_add_data( "wp-block-{$block_name}", 'rtl', 'replace' );
148 - wp_style_add_data( "wp-block-{$block_name}", 'suffix', $suffix );
266 +
149 267 // Add a reference to the stylesheet's path to allow calculations for inlining styles in `wp_head`.
150 268 wp_style_add_data( "wp-block-{$block_name}", 'path', $stylesheet_path );
151 269 } else {
152 270 wp_register_style( "wp-block-{$block_name}", false, array() );
@@ -159,10 +277,10 @@
159 277 if ( current_theme_supports( 'wp-block-styles' ) ) {
160 278
161 279 // Get the path to the block's stylesheet.
162 280 $theme_style_path = is_rtl()
163 - ? "build/styles/block-library/$block_name/theme-rtl{$suffix}.css"
164 - : "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";
165 283
166 284 // If the file exists, enqueue it.
167 285 if ( file_exists( gutenberg_dir_path() . $theme_style_path ) ) {
168 286 wp_deregister_style( "wp-block-{$block_name}-theme" );
@@ -167,28 +285,26 @@
167 285 if ( file_exists( gutenberg_dir_path() . $theme_style_path ) ) {
168 286 wp_deregister_style( "wp-block-{$block_name}-theme" );
169 287 wp_register_style(
170 288 "wp-block-{$block_name}-theme",
171 - $gutenberg_url_root . $theme_style_path,
289 + gutenberg_url( $theme_style_path ),
172 290 array(),
173 291 $default_version
174 292 );
175 293 wp_style_add_data( "wp-block-{$block_name}-theme", 'path', gutenberg_dir_path() . $theme_style_path );
176 - wp_style_add_data( "wp-block-{$block_name}-theme", 'suffix', $suffix );
177 294 }
178 295 }
179 296
180 - $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";
181 298 if ( file_exists( gutenberg_dir_path() . $editor_style_path ) ) {
182 299 wp_deregister_style( "wp-block-{$block_name}-editor" );
183 300 wp_register_style(
184 301 "wp-block-{$block_name}-editor",
185 - $gutenberg_url_root . $editor_style_path,
302 + gutenberg_url( $editor_style_path ),
186 303 array(),
187 304 $default_version
188 305 );
189 306 wp_style_add_data( "wp-block-{$block_name}-editor", 'rtl', 'replace' );
190 - wp_style_add_data( "wp-block-{$block_name}-editor", 'suffix', $suffix );
191 307 } else {
192 308 wp_register_style( "wp-block-{$block_name}-editor", false );
193 309 }
194 310 }
@@ -204,9 +320,9 @@
204 320 *
205 321 * This shim is INTENTIONALLY left out of core, as Social Links have never
206 322 * landed there.
207 323 *
208 - * @link https://github.com/WordPress/gutenberg/pull/19887
324 + * @see https://github.com/WordPress/gutenberg/pull/19887
209 325 */
210 326 function gutenberg_register_legacy_social_link_blocks() {
211 327 $services = array(
212 328 'amazon',
@@ -380,9 +496,9 @@
380 496 * @return string Input argument of the filter.
381 497 */
382 498 function _gutenberg_footnotes_force_filtered_html_on_import_filter( $arg ) {
383 499 if ( function_exists( '_wp_filter_post_meta_footnotes' ) ) {
384 - return $arg;
500 + return;
385 501 }
386 502 // force_filtered_html_on_import is true we need to init the global styles kses filters.
387 503 if ( $arg ) {
388 504 _gutenberg_footnotes_kses_init_filters();