PluginProbe
Gutenberg / 10.1.0
Gutenberg v10.1.0
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 +239 -256 24.0.0 → 10.1.0 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Block functions specific for the Gutenberg editor plugin.
3 + * Block and style registration functions.
4 4 *
5 5 * @package gutenberg
6 6 */
7 7
@@ -9,101 +9,153 @@
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 + '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 + 'page-list.php' => 'core/page-list',
67 + 'post-author.php' => 'core/post-author',
68 + 'post-comment.php' => 'core/post-comment',
69 + 'post-comment-author.php' => 'core/post-comment-author',
70 + 'post-comment-content.php' => 'core/post-comment-content',
71 + 'post-comment-date.php' => 'core/post-comment-date',
72 + 'post-comments.php' => 'core/post-comments',
73 + 'post-comments-count.php' => 'core/post-comments-count',
74 + 'post-comments-form.php' => 'core/post-comments-form',
75 + 'post-content.php' => 'core/post-content',
76 + 'post-date.php' => 'core/post-date',
77 + 'post-excerpt.php' => 'core/post-excerpt',
78 + 'post-featured-image.php' => 'core/post-featured-image',
79 + 'post-hierarchical-terms.php' => 'core/post-hierarchical-terms',
80 + 'post-navigation-link.php' => 'core/post-navigation-link',
81 + 'post-tags.php' => 'core/post-tags',
82 + 'post-title.php' => 'core/post-title',
83 + 'query.php' => 'core/query',
84 + 'query-loop.php' => 'core/query-loop',
85 + 'query-pagination.php' => 'core/query-pagination',
86 + 'query-pagination-next.php' => 'core/query-pagination-next',
87 + 'query-pagination-numbers.php' => 'core/query-pagination-numbers',
88 + 'query-pagination-previous.php' => 'core/query-pagination-previous',
89 + 'site-logo.php' => 'core/site-logo',
90 + 'site-tagline.php' => 'core/site-tagline',
91 + 'site-title.php' => 'core/site-title',
92 + 'template-part.php' => 'core/template-part',
93 + )
94 + ),
95 + ),
96 + __DIR__ . '/../build/edit-widgets/blocks/' => array(
97 + 'block_folders' => array(
98 + 'legacy-widget',
99 + 'widget-area',
100 + ),
101 + 'block_names' => array(
102 + 'legacy-widget.php' => 'core/legacy-widget',
103 + 'widget-area.php' => 'core/widget-area',
104 + ),
105 + ),
17 106 );
107 + foreach ( $blocks_dirs as $blocks_dir => $details ) {
108 + $block_folders = $details['block_folders'];
109 + $block_names = $details['block_names'];
18 110
19 - foreach ( $blocks_dirs as $blocks_dir ) {
20 - $manifest_path = $blocks_dir . 'blocks-manifest.php';
21 - $blocks = require $manifest_path;
111 + $registry = WP_Block_Type_Registry::get_instance();
22 112
23 - foreach ( $blocks as $block_name_folder => $metadata ) {
24 - if ( ! is_array( $metadata ) || ! isset( $metadata['name'] ) ) {
25 - continue;
113 + foreach ( $block_folders as $folder_name ) {
114 + $block_json_file = $blocks_dir . $folder_name . '/block.json';
115 +
116 + // Ideally, all paths to block metadata files should be listed in
117 + // WordPress core. In this place we should rather use filter
118 + // to replace paths with overrides defined by the plugin.
119 + $metadata = json_decode( file_get_contents( $block_json_file ), true );
120 + if ( ! is_array( $metadata ) || ! $metadata['name'] ) {
121 + return false;
26 122 }
27 123
28 - gutenberg_deregister_core_block_and_assets( $metadata['name'] );
29 - gutenberg_register_core_block_assets( $block_name_folder );
30 -
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 );
124 + if ( $registry->is_registered( $metadata['name'] ) ) {
125 + $registry->unregister( $metadata['name'] );
36 126 }
37 - }
38 - }
39 -}
40 127
41 -add_action( 'init', 'gutenberg_reregister_core_block_types' );
42 -
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 -/**
51 - * Adds the defer loading strategy to all registered blocks.
52 - *
53 - * This function would not be part of core merge. Instead, the register_block_script_handle() function would be patched
54 - * as follows.
55 - *
56 - * ```
57 - * --- a/wp-includes/blocks.php
58 - * +++ b/wp-includes/blocks.php
59 - * @ @ -153,7 +153,8 @ @ function register_block_script_handle( $metadata, $field_name, $index = 0 ) {
60 - * $script_handle,
61 - * $script_uri,
62 - * $script_dependencies,
63 - * - $script_asset['version'] ?? false
64 - * + $script_asset['version'] ?? false,
65 - * + array( 'strategy' => 'defer' )
66 - * );
67 - * if ( ! $result ) {
68 - * return false;
69 - * ```
70 - *
71 - * @see register_block_script_handle()
72 - */
73 -function gutenberg_defer_block_view_scripts() {
74 - $block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();
75 - foreach ( $block_types as $block_type ) {
76 - foreach ( $block_type->view_script_handles as $view_script_handle ) {
77 - wp_script_add_data( $view_script_handle, 'strategy', 'defer' );
128 + gutenberg_register_core_block_styles( $folder_name );
129 + register_block_type_from_metadata( $block_json_file );
78 130 }
79 - }
80 -}
81 131
82 -add_action( 'init', 'gutenberg_defer_block_view_scripts', 100 );
132 + foreach ( $block_names as $file => $block_names ) {
133 + if ( ! file_exists( $blocks_dir . $file ) ) {
134 + return;
135 + }
83 136
84 -/**
85 - * Deregisters the existing core block type and its assets.
86 - *
87 - * @param string $block_name The name of the block.
88 - *
89 - * @return void
90 - */
91 -function gutenberg_deregister_core_block_and_assets( $block_name ) {
92 - $registry = WP_Block_Type_Registry::get_instance();
93 - if ( $registry->is_registered( $block_name ) ) {
94 - $block_type = $registry->get_registered( $block_name );
95 - if ( ! empty( $block_type->view_script_handles ) ) {
96 - foreach ( $block_type->view_script_handles as $view_script_handle ) {
97 - if ( str_starts_with( $view_script_handle, 'wp-block-' ) ) {
98 - wp_deregister_script( $view_script_handle );
137 + if ( is_string( $block_names ) ) {
138 + if ( $registry->is_registered( $block_names ) ) {
139 + $registry->unregister( $block_names );
99 140 }
141 + gutenberg_register_core_block_styles( $block_names );
142 + } elseif ( is_array( $block_names ) ) {
143 + foreach ( $block_names as $block_name ) {
144 + if ( $registry->is_registered( $block_name ) ) {
145 + $registry->unregister( $block_name );
146 + }
147 + gutenberg_register_core_block_styles( $block_name );
148 + }
100 149 }
150 +
151 + require $blocks_dir . $file;
101 152 }
102 - $registry->unregister( $block_name );
103 153 }
104 154 }
105 155
156 +add_action( 'init', 'gutenberg_reregister_core_block_types' );
157 +
106 158 /**
107 159 * Registers block styles for a core block.
108 160 *
109 161 * @param string $block_name The block-name.
@@ -109,92 +161,142 @@
109 161 * @param string $block_name The block-name.
110 162 *
111 163 * @return void
112 164 */
113 -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 - if ( ! wp_should_load_separate_core_block_assets() ) {
165 +function gutenberg_register_core_block_styles( $block_name ) {
166 + if ( ! gutenberg_should_load_separate_block_styles() ) {
124 167 return;
125 168 }
126 169
127 170 $block_name = str_replace( 'core/', '', $block_name );
128 171
129 - // When in production, use the plugin's version as the default asset version;
130 - // else (for development or test) default to use the current time.
131 - $default_version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time();
132 - $suffix = SCRIPT_DEBUG ? '' : '.min';
172 + $style_path = "build/block-library/blocks/$block_name/style.css";
173 + $editor_style_path = "build/block-library/blocks/$block_name/style-editor.css";
133 174
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' );
137 -
138 - if ( file_exists( $stylesheet_path ) ) {
139 -
140 - wp_deregister_style( "wp-block-{$block_name}" );
175 + if ( file_exists( gutenberg_dir_path() . $style_path ) ) {
141 176 wp_register_style(
142 177 "wp-block-{$block_name}",
143 - $stylesheet_url,
178 + gutenberg_url( $style_path ),
144 179 array(),
145 - $default_version
180 + filemtime( gutenberg_dir_path() . $style_path )
146 181 );
147 182 wp_style_add_data( "wp-block-{$block_name}", 'rtl', 'replace' );
148 - wp_style_add_data( "wp-block-{$block_name}", 'suffix', $suffix );
183 +
149 184 // Add a reference to the stylesheet's path to allow calculations for inlining styles in `wp_head`.
150 - wp_style_add_data( "wp-block-{$block_name}", 'path', $stylesheet_path );
151 - } else {
152 - wp_register_style( "wp-block-{$block_name}", false, array() );
185 + wp_style_add_data( "wp-block-{$block_name}", 'path', gutenberg_dir_path() . $style_path );
153 186 }
154 187
155 - /*
156 - * If the current theme supports wp-block-styles, dequeue the core styles
157 - * and enqueue the plugin ones instead.
188 + if ( file_exists( gutenberg_dir_path() . $editor_style_path ) ) {
189 + wp_register_style(
190 + "wp-block-{$block_name}-editor",
191 + gutenberg_url( $editor_style_path ),
192 + array(),
193 + filemtime( gutenberg_dir_path() . $editor_style_path )
194 + );
195 + wp_style_add_data( "wp-block-{$block_name}-editor", 'rtl', 'replace' );
196 + }
197 +}
198 +
199 +/**
200 + * Change the way styles get loaded depending on their size.
201 + *
202 + * Optimizes performance and sustainability of styles by inlining smaller stylesheets.
203 + *
204 + * @return void
205 + */
206 +function gutenberg_maybe_inline_styles() {
207 +
208 + $total_inline_limit = 20000;
209 + /**
210 + * The maximum size of inlined styles in bytes.
211 + *
212 + * @param int $total_inline_limit The file-size threshold, in bytes. Defaults to 20000.
213 + * @return int The file-size threshold, in bytes.
158 214 */
159 - if ( current_theme_supports( 'wp-block-styles' ) ) {
215 + $total_inline_limit = apply_filters( 'styles_inline_size_limit', $total_inline_limit );
160 216
161 - // Get the path to the block's stylesheet.
162 - $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";
217 + global $wp_styles;
218 + $styles = array();
165 219
166 - // If the file exists, enqueue it.
167 - if ( file_exists( gutenberg_dir_path() . $theme_style_path ) ) {
168 - wp_deregister_style( "wp-block-{$block_name}-theme" );
169 - wp_register_style(
170 - "wp-block-{$block_name}-theme",
171 - $gutenberg_url_root . $theme_style_path,
172 - array(),
173 - $default_version
220 + // Build an array of styles that have a path defined.
221 + foreach ( $wp_styles->queue as $handle ) {
222 + if ( wp_styles()->get_data( $handle, 'path' ) && file_exists( $wp_styles->registered[ $handle ]->extra['path'] ) ) {
223 + $block_styles = false;
224 + $styles_size = filesize( $wp_styles->registered[ $handle ]->extra['path'] );
225 +
226 + // Minify styles and get their minified size if SCRIPT_DEBUG is not enabled.
227 + if ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) {
228 + // Get the styles and minify them by removing comments & whitespace.
229 + $block_styles = gutenberg_get_minified_styles( file_get_contents( $wp_styles->registered[ $handle ]->extra['path'] ) );
230 + // Get the styles size.
231 + $styles_size = strlen( $block_styles );
232 + }
233 +
234 + $styles[] = array(
235 + 'handle' => $handle,
236 + 'path' => $wp_styles->registered[ $handle ]->extra['path'],
237 + 'size' => $styles_size,
238 + 'css' => $block_styles,
174 239 );
175 - 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 240 }
178 241 }
179 242
180 - $editor_style_path = "build/styles/block-library/$block_name/style-editor{$suffix}.css";
181 - if ( file_exists( gutenberg_dir_path() . $editor_style_path ) ) {
182 - wp_deregister_style( "wp-block-{$block_name}-editor" );
183 - wp_register_style(
184 - "wp-block-{$block_name}-editor",
185 - $gutenberg_url_root . $editor_style_path,
186 - array(),
187 - $default_version
243 + if ( ! empty( $styles ) ) {
244 + // Reorder styles array based on size.
245 + usort(
246 + $styles,
247 + function( $a, $b ) {
248 + return ( $a['size'] <= $b['size'] ) ? -1 : 1;
249 + }
188 250 );
189 - wp_style_add_data( "wp-block-{$block_name}-editor", 'rtl', 'replace' );
190 - wp_style_add_data( "wp-block-{$block_name}-editor", 'suffix', $suffix );
191 - } else {
192 - wp_register_style( "wp-block-{$block_name}-editor", false );
251 +
252 + /**
253 + * The total inlined size.
254 + *
255 + * On each iteration of the loop, if a style gets added inline the value of this var increases
256 + * to reflect the total size of inlined styles.
257 + */
258 + $total_inline_size = 0;
259 +
260 + // Loop styles.
261 + foreach ( $styles as $style ) {
262 +
263 + // Size check. Since styles are ordered by size, we can break the loop.
264 + if ( $total_inline_size + $style['size'] > $total_inline_limit ) {
265 + break;
266 + }
267 +
268 + // Get the styles if we don't already have them.
269 + $style['css'] = $style['css'] ? $style['css'] : file_get_contents( $style['path'] );
270 +
271 + // Set `src` to `false` and add styles inline.
272 + $wp_styles->registered[ $style['handle'] ]->src = false;
273 + $wp_styles->registered[ $style['handle'] ]->extra['after'][] = $style['css'];
274 +
275 + // Add the styles size to the $total_inline_size var.
276 + $total_inline_size += (int) $style['size'];
277 + }
193 278 }
194 279 }
280 +add_action( 'wp_head', 'gutenberg_maybe_inline_styles', 1 );
195 281
196 282 /**
283 + * Minify styles.
284 + *
285 + * Removes inline comments and whitespace.
286 + *
287 + * @param string $styles The styles to be minified.
288 + * @return string
289 + */
290 +function gutenberg_get_minified_styles( $styles ) {
291 + $re1 = '(?sx)("(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')|/\\* (?> .*? \\*/ )';
292 + $re2 = '(?six)("(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')|\\s*+ ; \\s*+ ( } ) \\s*+|\\s*+ ( [*$~^|]?+= | [{};,>~+-] | !important\\b ) \\s*+|( [[(:] ) \\s++|\\s++ ( [])] )|\\s++ ( : ) \\s*+(?!(?>[^{}"\']++|"(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')*+{)|^ \\s++ | \\s++ \\z|(\\s)\\s+';
293 +
294 + $styles = preg_replace( "%$re1%", '$1', $styles );
295 + return preg_replace( "%$re2%", '$1$2$3$4$5$6$7', $styles );
296 +}
297 +
298 +/**
197 299 * Complements the implementation of block type `core/social-icon`, whether it
198 300 * be provided by core or the plugin, with derived block types for each
199 301 * "service" (WordPress, Twitter, etc.) supported by Social Links.
200 302 *
@@ -201,12 +303,12 @@
201 303 * This ensures backwards compatibility for any users running the Gutenberg
202 304 * plugin who have used Social Links prior to their conversion to block
203 305 * variations.
204 306 *
205 - * This shim is INTENTIONALLY left out of core, as Social Links have never
307 + * This shim is INTENTIONALLY left out of core, as Social Links haven't yet
206 308 * landed there.
207 309 *
208 - * @link https://github.com/WordPress/gutenberg/pull/19887
310 + * @see https://github.com/WordPress/gutenberg/pull/19887
209 311 */
210 312 function gutenberg_register_legacy_social_link_blocks() {
211 313 $services = array(
212 314 'amazon',
@@ -273,123 +375,4 @@
273 375 }
274 376 }
275 377
276 378 add_action( 'init', 'gutenberg_register_legacy_social_link_blocks' );
277 -
278 -/**
279 - * Migrate the legacy `sync_status` meta key (added 16.1) to the new `wp_pattern_sync_status` meta key (16.1.1).
280 - *
281 - * This filter is INTENTIONALLY left out of core as the meta key was fist introduced to core in 6.3 as `wp_pattern_sync_status`.
282 - * see https://github.com/WordPress/gutenberg/pull/52232
283 - *
284 - * @param mixed $value The value to return, either a single metadata value or an array of values depending on the value of $single.
285 - * @param int $object_id ID of the object metadata is for.
286 - * @param string $meta_key Metadata key.
287 - * @param bool $single Whether to return only the first value of the specified $meta_key.
288 - */
289 -function gutenberg_legacy_wp_block_post_meta( $value, $object_id, $meta_key, $single ) {
290 - if ( 'wp_pattern_sync_status' !== $meta_key ) {
291 - return $value;
292 - }
293 -
294 - $sync_status = get_post_meta( $object_id, 'sync_status', $single );
295 -
296 - if ( $single && 'unsynced' === $sync_status ) {
297 - return $sync_status;
298 - } elseif ( isset( $sync_status[0] ) && 'unsynced' === $sync_status[0] ) {
299 - return $sync_status;
300 - }
301 -
302 - return $value;
303 -}
304 -
305 -add_filter( 'default_post_metadata', 'gutenberg_legacy_wp_block_post_meta', 10, 4 );
306 -
307 -
308 -
309 -/**
310 - * Strips all HTML from the content of footnotes, and sanitizes the ID.
311 - *
312 - * This function expects slashed data on the footnotes content.
313 - *
314 - * @access private
315 - *
316 - * @param string $footnotes JSON encoded string of an array containing the content and ID of each footnote.
317 - * @return string Filtered content without any HTML on the footnote content and with the sanitized id.
318 - */
319 -function _gutenberg_filter_post_meta_footnotes( $footnotes ) {
320 - $footnotes_decoded = json_decode( $footnotes, true );
321 - if ( ! is_array( $footnotes_decoded ) ) {
322 - return '';
323 - }
324 - $footnotes_sanitized = array();
325 - foreach ( $footnotes_decoded as $footnote ) {
326 - if ( ! empty( $footnote['content'] ) && ! empty( $footnote['id'] ) ) {
327 - $footnotes_sanitized[] = array(
328 - 'id' => sanitize_key( $footnote['id'] ),
329 - 'content' => wp_unslash( wp_filter_post_kses( wp_slash( $footnote['content'] ) ) ),
330 - );
331 - }
332 - }
333 - return wp_json_encode( $footnotes_sanitized );
334 -}
335 -
336 -/**
337 - * Adds the filters to filter footnotes meta field.
338 - *
339 - * @access private
340 - */
341 -function _gutenberg_footnotes_kses_init_filters() {
342 - add_filter( 'sanitize_post_meta_footnotes', '_gutenberg_filter_post_meta_footnotes' );
343 -}
344 -
345 -/**
346 - * Removes the filters that filter footnotes meta field.
347 - *
348 - * @access private
349 - */
350 -function _gutenberg_footnotes_remove_filters() {
351 - remove_filter( 'sanitize_post_meta_footnotes', '_gutenberg_filter_post_meta_footnotes' );
352 -}
353 -
354 -/**
355 - * Registers the filter of footnotes meta field if the user does not have unfiltered_html capability.
356 - *
357 - * @access private
358 - */
359 -function _gutenberg_footnotes_kses_init() {
360 - if ( function_exists( '_wp_filter_post_meta_footnotes' ) ) {
361 - return;
362 - }
363 - _gutenberg_footnotes_remove_filters();
364 - if ( ! current_user_can( 'unfiltered_html' ) ) {
365 - _gutenberg_footnotes_kses_init_filters();
366 - }
367 -}
368 -
369 -/**
370 - * Initializes footnotes meta field filters when imported data should be filtered.
371 - *
372 - * This filter is the last being executed on force_filtered_html_on_import.
373 - * If the input of the filter is true it means we are in an import situation and should
374 - * enable kses, independently of the user capabilities.
375 - * So in that case we call _gutenberg_footnotes_kses_init_filters;
376 - *
377 - * @access private
378 - *
379 - * @param string $arg Input argument of the filter.
380 - * @return string Input argument of the filter.
381 - */
382 -function _gutenberg_footnotes_force_filtered_html_on_import_filter( $arg ) {
383 - if ( function_exists( '_wp_filter_post_meta_footnotes' ) ) {
384 - return $arg;
385 - }
386 - // force_filtered_html_on_import is true we need to init the global styles kses filters.
387 - if ( $arg ) {
388 - _gutenberg_footnotes_kses_init_filters();
389 - }
390 - return $arg;
391 -}
392 -
393 -add_action( 'init', '_gutenberg_footnotes_kses_init' );
394 -add_action( 'set_current_user', '_gutenberg_footnotes_kses_init' );
395 -add_filter( 'force_filtered_html_on_import', '_gutenberg_footnotes_force_filtered_html_on_import_filter', 999 );