admin管理员组文章数量:1193739
To clarify -- these files in the error were NOT edited at the time of the error, I checked twice. And I checked again by doing a diff with a fresh WordPress install. I had to remove the broken line -- shown below -- because it crashes WordPress. This line does not crash all WordPress blogs, obviously, and I have another blog on the same LEMP stack without the fatal error. How is "kses" activated in this case? Is it the content of the blog? I don't know, but I don't see any plugin or theme in the stack trace.
Here's the error:
[error] FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /home/www-data/example/wp-includes/kses.php:1871
#0 /home/www-data/example/wp-includes/kses.php(1871): in_array()
#1 [internal function]: wp_kses_named_entities()
#2 /home/www-data/example/wp-includes/kses.php(1842): preg_replace_callback()
#3 /home/www-data/example/wp-includes/formatting.php(981): wp_kses_normalize_entities()
This line does not work in PHP8:
return ( ! in_array( $i, $allowedentitynames, true ) ) ? "&$i;" : "&$i;";
There's no plugin or theme referring to "allowedentitynames" as per grep.
To clarify -- these files in the error were NOT edited at the time of the error, I checked twice. And I checked again by doing a diff with a fresh WordPress install. I had to remove the broken line -- shown below -- because it crashes WordPress. This line does not crash all WordPress blogs, obviously, and I have another blog on the same LEMP stack without the fatal error. How is "kses" activated in this case? Is it the content of the blog? I don't know, but I don't see any plugin or theme in the stack trace.
Here's the error:
[error] FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /home/www-data/example.com/wp-includes/kses.php:1871
#0 /home/www-data/example.com/wp-includes/kses.php(1871): in_array()
#1 [internal function]: wp_kses_named_entities()
#2 /home/www-data/example.com/wp-includes/kses.php(1842): preg_replace_callback()
#3 /home/www-data/example.com/wp-includes/formatting.php(981): wp_kses_normalize_entities()
This line does not work in PHP8:
return ( ! in_array( $i, $allowedentitynames, true ) ) ? "&$i;" : "&$i;";
There's no plugin or theme referring to "allowedentitynames" as per grep.
Share Improve this question edited Jul 30, 2022 at 23:34 Jay Brunet asked Jul 29, 2022 at 9:10 Jay BrunetJay Brunet 5702 gold badges8 silver badges15 bronze badges 6 | Show 1 more comment2 Answers
Reset to default 5When you use the deprecated CUSTOM_TAGS
constant, you have to define the variables WordPress would normally create in kses.php
at the top. If you do not then you will encounter this issue.
/**
* Specifies the default allowable HTML tags.
*
* Using `CUSTOM_TAGS` is not recommended and should be considered deprecated. The
* {@see 'wp_kses_allowed_html'} filter is more powerful and supplies context.
*
* @see wp_kses_allowed_html()
* @since 1.2.0
*
* @var array[]|false Array of default allowable HTML tags, or false to use the defaults.
*/
if ( ! defined( 'CUSTOM_TAGS' ) ) {
define( 'CUSTOM_TAGS', false );
}
Instead, you should use the wp_kses_allowed_html
filter to modify which tags are allowed, using the context
parameter to control when and where the adjusted tags are usable:
https://developer.wordpress.org/reference/hooks/wp_kses_allowed_html/
Just keep in mind that the list of tags is chosen to avoid allowing dangerous things into posts and comments. E.g. iframes or script tags. Changing these will have significant security consequences.
How is "kses" activated in this case? Is it the content of the blog?
kses
functions are used everywhere in WordPress and play a pivotal role in security. E.g. wp_kses_post
is used to strip out dangerous tags when saving a post, and wp_kses
can strip out tags and attributes that don't fit a whitelist. wp_kses
and it's wrapper functions act as both pseudo-escaping and as sanitisation functions.
Never edit core files, and definitely do not make this change.
Looking at the source the problem doesn't seem related to PHP 8.1 at all. Something in a theme or plugin is causing $allowedentitynames
to be null
, which it should not be. See this trac ticket for a previous discussion with somebody who encountered this issue.
本文标签: Broken ksesphp function quotwpksesnamedentitiesquot crashes WordPress
版权声明:本文标题:Broken kses.php function "wp_kses_named_entities" crashes WordPress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738481977a2089196.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
CUSTOM_TAGS
constant? – bosco Commented Jul 30, 2022 at 22:37array_map
with_wp_add_global_attributes
, and if you defineCUSTOM_TAGS
it prevents WordPress from defining that variable. – Tom J Nowell ♦ Commented Jul 30, 2022 at 23:23