KSES: Display a notice if any of the required globals are not set.

When using the `CUSTOM_TAGS` constant, these global variables should be set to arrays:

* `$allowedposttags`
* `$allowedtags`
* `$allowedentitynames`
* `$allowedxmlentitynames`

This commit aims to improve developer experience by displaying a more helpful message to explain a PHP fatal error further in the code if any of these globals are either not set or not an array.

Note Using `CUSTOM_TAGS` is not recommended and should be considered deprecated. The `wp_kses_allowed_html` filter is more powerful and supplies context.

Follow-up to [832], [834], [2896], [13358], [21796], [28845], [43016], [48072].

Props doctorlai, pento, KnowingArt_com, bosconiandynamics, TJNowell, ironprogrammer, audrasjb, mukesh27, SergeyBiryukov.
Fixes #47357.
Built from https://develop.svn.wordpress.org/trunk@54672


git-svn-id: http://core.svn.wordpress.org/trunk@54224 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-10-24 14:49:15 +00:00
parent ca3cfae579
commit 89e665383f
2 changed files with 35 additions and 1 deletions

View File

@ -36,6 +36,13 @@
* Using `CUSTOM_TAGS` is not recommended and should be considered deprecated. The
* {@see 'wp_kses_allowed_html'} filter is more powerful and supplies context.
*
* When using this constant, make sure to set all of these globals to arrays:
*
* - `$allowedposttags`
* - `$allowedtags`
* - `$allowedentitynames`
* - `$allowedxmlentitynames`
*
* @see wp_kses_allowed_html()
* @since 1.2.0
*
@ -685,6 +692,33 @@ if ( ! CUSTOM_TAGS ) {
$allowedposttags = array_map( '_wp_add_global_attributes', $allowedposttags );
} else {
$required_kses_globals = array(
'allowedposttags',
'allowedtags',
'allowedentitynames',
'allowedxmlentitynames',
);
$missing_kses_globals = array();
foreach ( $required_kses_globals as $global_name ) {
if ( ! isset( $GLOBALS[ $global_name ] ) || ! is_array( $GLOBALS[ $global_name ] ) ) {
$missing_kses_globals[] = '<code>$' . $global_name . '</code>';
}
}
if ( $missing_kses_globals ) {
_doing_it_wrong(
'wp_kses_allowed_html',
sprintf(
/* translators: 1: CUSTOM_TAGS, 2: Global variable names. */
__( 'When using the %1$s constant, make sure to set these globals to an array: %2$s.' ),
'<code>CUSTOM_TAGS</code>',
implode( ', ', $missing_kses_globals )
),
'6.2.0'
);
}
$allowedtags = wp_kses_array_lc( $allowedtags );
$allowedposttags = wp_kses_array_lc( $allowedposttags );
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.2-alpha-54670';
$wp_version = '6.2-alpha-54672';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.