PluginProbe
Gutenberg / 8.9.2
Gutenberg v8.9.2
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 +167 -107 7.4.08.9.2 View file →
@@ -5,30 +5,8 @@
5 5 * @package gutenberg
6 6 */
7 7
8 8 /**
9 - * Retrieves registered social link blocks
10 - *
11 - * @return array Array of strings containing the registered social link block names.
12 - */
13 -function gutenberg_get_registered_social_link_blocks() {
14 - $social_link_prefix = 'core/social-link';
15 - $social_link_prefix_length = strlen( $social_link_prefix );
16 -
17 - $registry = WP_Block_Type_Registry::get_instance();
18 - $block_types = $registry->get_all_registered();
19 -
20 - $registered_social_link_blocks = array();
21 - foreach ( $block_types as $block_type ) {
22 - // Block type name starts with $social_link_prefix.
23 - if ( strncmp( $block_type->name, $social_link_prefix, $social_link_prefix_length ) === 0 ) {
24 - $registered_social_link_blocks[] = $block_type->name;
25 - }
26 - }
27 - return $registered_social_link_blocks;
28 -}
29 -
30 -/**
31 9 * Substitutes the implementation of a core-registered block type, if exists,
32 10 * with the built result from the plugin.
33 11 */
34 12 function gutenberg_reregister_core_block_types() {
@@ -37,33 +15,114 @@
37 15 if ( ! file_exists( $blocks_dir ) ) {
38 16 return;
39 17 }
40 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 +
41 54 $block_names = array(
42 55 'archives.php' => 'core/archives',
43 56 'block.php' => 'core/block',
44 57 'calendar.php' => 'core/calendar',
45 58 'categories.php' => 'core/categories',
59 + 'cover.php' => 'core/cover',
46 60 'latest-comments.php' => 'core/latest-comments',
47 61 'latest-posts.php' => 'core/latest-posts',
48 62 'legacy-widget.php' => 'core/legacy-widget',
49 63 'navigation.php' => 'core/navigation',
64 + 'navigation-link.php' => 'core/navigation-link',
50 65 'rss.php' => 'core/rss',
66 + 'search.php' => 'core/search',
51 67 'shortcode.php' => 'core/shortcode',
52 - 'search.php' => 'core/search',
53 - 'social-link.php' => gutenberg_get_registered_social_link_blocks(),
68 + 'social-link.php' => 'core/social-link',
54 69 'tag-cloud.php' => 'core/tag-cloud',
55 - 'site-title.php' => 'core/site-title',
56 - 'template-part.php' => 'core/template-part',
57 - 'post-title.php' => 'core/post-title',
58 - 'post-content.php' => 'core/post-content',
59 - 'post-author.php' => 'core/post-author',
60 - 'post-date.php' => 'core/post-date',
61 - 'post-excerpt.php' => 'core/post-excerpt',
62 70 );
63 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-comment.php' => 'core/post-comment',
78 + 'post-comment-author.php' => 'core/post-comment-author',
79 + 'post-comment-content.php' => 'core/post-comment-content',
80 + 'post-comment-date.php' => 'core/post-comment-date',
81 + 'post-comments.php' => 'core/post-comments',
82 + 'post-comments-count.php' => 'core/post-comments-count',
83 + 'post-comments-form.php' => 'core/post-comments-form',
84 + 'post-content.php' => 'core/post-content',
85 + 'post-date.php' => 'core/post-date',
86 + 'post-excerpt.php' => 'core/post-excerpt',
87 + 'post-featured-image.php' => 'core/post-featured-image',
88 + 'post-hierarchical-terms.php' => 'core/post-hierarchical-terms',
89 + 'post-tags.php' => 'core/post-tags',
90 + 'post-title.php' => 'core/post-title',
91 + 'query.php' => 'core/query',
92 + 'query-loop.php' => 'core/query-loop',
93 + 'query-pagination.php' => 'core/query-pagination',
94 + 'site-logo.php' => 'core/site-logo',
95 + 'site-tagline.php' => 'core/site-tagline',
96 + 'site-title.php' => 'core/site-title',
97 + 'template-part.php' => 'core/template-part',
98 + )
99 + );
100 + }
101 +
64 102 $registry = WP_Block_Type_Registry::get_instance();
65 103
104 + foreach ( $block_folders as $folder_name ) {
105 + $block_json_file = $blocks_dir . '/' . $folder_name . '/block.json';
106 + if ( ! file_exists( $block_json_file ) ) {
107 + return;
108 + }
109 +
110 + // Ideally, all paths to block metadata files should be listed in
111 + // WordPress core. In this place we should rather use filter
112 + // to replace paths with overrides defined by the plugin.
113 + $metadata = json_decode( file_get_contents( $block_json_file ), true );
114 + if ( ! is_array( $metadata ) || ! $metadata['name'] ) {
115 + return false;
116 + }
117 +
118 + if ( $registry->is_registered( $metadata['name'] ) ) {
119 + $registry->unregister( $metadata['name'] );
120 + }
121 +
122 + register_block_type_from_metadata( $block_json_file );
123 + }
124 +
66 125 foreach ( $block_names as $file => $block_names ) {
67 126 if ( ! file_exists( $blocks_dir . $file ) ) {
68 127 return;
69 128 }
@@ -84,83 +143,84 @@
84 143 }
85 144 }
86 145 add_action( 'init', 'gutenberg_reregister_core_block_types' );
87 146
88 -if ( ! function_exists( 'register_block_style' ) ) {
89 - /**
90 - * Registers a new block style.
91 - *
92 - * @param string $block_name Block type name including namespace.
93 - * @param array $style_properties Array containing the properties of the style name, label, style (name of the stylesheet to be enqueued), inline_style (string containing the CSS to be added).
94 - *
95 - * @return boolean True if the block style was registered with success and false otherwise.
96 - */
97 - function register_block_style( $block_name, $style_properties ) {
98 - return WP_Block_Styles_Registry::get_instance()->register( $block_name, $style_properties );
99 - }
100 -}
147 +/**
148 + * Complements the implementation of block type `core/social-icon`, whether it
149 + * be provided by core or the plugin, with derived block types for each
150 + * "service" (WordPress, Twitter, etc.) supported by Social Links.
151 + *
152 + * This ensures backwards compatibility for any users running the Gutenberg
153 + * plugin who have used Social Links prior to their conversion to block
154 + * variations.
155 + *
156 + * This shim is INTENTIONALLY left out of core, as Social Links haven't yet
157 + * landed there.
158 + *
159 + * @see https://github.com/WordPress/gutenberg/pull/19887
160 + */
161 +function gutenberg_register_legacy_social_link_blocks() {
162 + $services = array(
163 + 'amazon',
164 + 'bandcamp',
165 + 'behance',
166 + 'chain',
167 + 'codepen',
168 + 'deviantart',
169 + 'dribbble',
170 + 'dropbox',
171 + 'etsy',
172 + 'facebook',
173 + 'feed',
174 + 'fivehundredpx',
175 + 'flickr',
176 + 'foursquare',
177 + 'goodreads',
178 + 'google',
179 + 'github',
180 + 'instagram',
181 + 'lastfm',
182 + 'linkedin',
183 + 'mail',
184 + 'mastodon',
185 + 'meetup',
186 + 'medium',
187 + 'pinterest',
188 + 'pocket',
189 + 'reddit',
190 + 'skype',
191 + 'snapchat',
192 + 'soundcloud',
193 + 'spotify',
194 + 'tumblr',
195 + 'twitch',
196 + 'twitter',
197 + 'vimeo',
198 + 'vk',
199 + 'wordpress',
200 + 'yelp',
201 + 'youtube',
202 + );
101 203
102 -if ( ! function_exists( 'unregister_block_style' ) ) {
103 - /**
104 - * Unregisters a block style.
105 - *
106 - * @param string $block_name Block type name including namespace.
107 - * @param array $block_style_name Block style name.
108 - *
109 - * @return boolean True if the block style was unregistered with success and false otherwise.
110 - */
111 - function unregister_block_style( $block_name, $block_style_name ) {
112 - return WP_Block_Styles_Registry::get_instance()->unregister( $block_name, $block_style_name );
204 + foreach ( $services as $service ) {
205 + register_block_type(
206 + 'core/social-link-' . $service,
207 + array(
208 + 'category' => 'widgets',
209 + 'attributes' => array(
210 + 'url' => array(
211 + 'type' => 'string',
212 + ),
213 + 'service' => array(
214 + 'type' => 'string',
215 + 'default' => $service,
216 + ),
217 + 'label' => array(
218 + 'type' => 'string',
219 + ),
220 + ),
221 + 'render_callback' => 'gutenberg_render_block_core_social_link',
222 + )
223 + );
113 224 }
114 225 }
115 -
116 -if ( ! has_action( 'enqueue_block_assets', 'enqueue_block_styles_assets' ) ) {
117 - /**
118 - * Function responsible for enqueuing the styles required for block styles functionality on the editor and on the frontend.
119 - */
120 - function gutenberg_enqueue_block_styles_assets() {
121 - $block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
122 -
123 - foreach ( $block_styles as $styles ) {
124 - foreach ( $styles as $style_properties ) {
125 - if ( isset( $style_properties['style_handle'] ) ) {
126 - wp_enqueue_style( $style_properties['style_handle'] );
127 - }
128 - if ( isset( $style_properties['inline_style'] ) ) {
129 - wp_add_inline_style( 'wp-block-library', $style_properties['inline_style'] );
130 - }
131 - }
132 - }
133 - }
134 - add_action( 'enqueue_block_assets', 'gutenberg_enqueue_block_styles_assets', 30 );
135 -}
136 -if ( ! has_action( 'enqueue_block_editor_assets', 'enqueue_editor_block_styles_assets' ) ) {
137 - /**
138 - * Function responsible for enqueuing the assets required for block styles functionality on the editor.
139 - */
140 - function gutenberg_enqueue_editor_block_styles_assets() {
141 - $block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
142 -
143 - $register_script_lines = array( '( function() {' );
144 - foreach ( $block_styles as $block_name => $styles ) {
145 - foreach ( $styles as $style_properties ) {
146 - $register_script_lines[] = sprintf(
147 - ' wp.blocks.registerBlockStyle( \'%s\', %s );',
148 - $block_name,
149 - wp_json_encode(
150 - array(
151 - 'name' => $style_properties['name'],
152 - 'label' => $style_properties['label'],
153 - )
154 - )
155 - );
156 - }
157 - }
158 - $register_script_lines[] = '} )();';
159 - $inline_script = implode( "\n", $register_script_lines );
160 -
161 - wp_register_script( 'wp-block-styles', false, array( 'wp-blocks' ), true, true );
162 - wp_add_inline_script( 'wp-block-styles', $inline_script );
163 - wp_enqueue_script( 'wp-block-styles' );
164 - }
165 - add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_editor_block_styles_assets' );
166 -}
226 +add_action( 'init', 'gutenberg_register_legacy_social_link_blocks' );