PHP7.4升级8.3后wordpress博客遇到的问题

博主的wordpress一直都跟随官方推送的更新,一般只要提示了就会点更新,这么多年也从来没有出现更挂了的情况,但是最近更新后,管理后台赫然弹出了PHP7.4已过期的,最低满足要求版本为PHP8.3的警告提示,于是强迫症发作,升级了一波,果然升级后访问页面直接出现了PHP崩溃的情况,特此记录下一些处理方法。

首先,既然官方提示了升级警告,那自然表明wordpress本身代码是都可以兼容8.3版本的PHP的,问题基本都出在各种常年没人维护的插件上,首先第一个:

[Fri Jul 11 16:20:57.973316 2025] [proxy_fcgi:error] [pid 19955:tid 20046] [client 85.208.96.204:23228] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function create_function() in /var/www/vhosts/blog.k-res.net/wp-content/plugins/custom-iframe-widget/custom-iframe-widget.php:189\nStack trace:\n#0 /var/www/vhosts/blog.k-res.net/wp-settings.php(545): include_once()\n#1 /var/www/vhosts/blog.k-res.net/wp-config.php(73): require_once('...')\n#2 /var/www/vhosts/blog.k-res.net/wp-load.php(50): require_once('...')\n#3 /var/www/vhosts/blog.k-res.net/wp-blog-header.php(13): require_once('...')\n#4 /var/www/vhosts/blog.k-res.net/index.php(17): require('...')\n#5 {main}\n  thrown in /var/www/vhosts/blog.k-res.net/wp-content/plugins/custom-iframe-widget/custom-iframe-widget.php on line 189'
[Fri Jul 11 16:21:22.922529 2025] [proxy_fcgi:error] [pid 19956:tid 20045] [client 66.249.68.38:61524] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function create_function() in /var/www/vhosts/blog.k-res.net/wp-content/plugins/custom-iframe-widget/custom-iframe-widget.php:189\nStack trace:\n#0 /var/www/vhosts/blog.k-res.net/wp-settings.php(545): include_once()\n#1 /var/www/vhosts/blog.k-res.net/wp-config.php(73): require_once('...')\n#2 /var/www/vhosts/blog.k-res.net/wp-load.php(50): require_once('...')\n#3 /var/www/vhosts/blog.k-res.net/wp-blog-header.php(13): require_once('...')\n#4 /var/www/vhosts/blog.k-res.net/index.php(17): require('...')\n#5 {main}\n  thrown in /var/www/vhosts/blog.k-res.net/wp-content/plugins/custom-iframe-widget/custom-iframe-widget.php on line 189'
[Fri Jul 11 16:21:52.750113 2025] [proxy_fcgi:error] [pid 19955:tid 20013] [client 49.232.55.15:43176] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function create_function() in /var/www/vhosts/blog.k-res.net/wp-content/plugins/custom-iframe-widget/custom-iframe-widget.php:189\nStack trace:\n#0 /var/www/vhosts/blog.k-res.net/wp-settings.php(545): include_once()\n#1 /var/www/vhosts/blog.k-res.net/wp-config.php(73): require_once('...')\n#2 /var/www/vhosts/blog.k-res.net/wp-load.php(50): require_once('...')\n#3 /var/www/vhosts/blog.k-res.net/wp-blog-header.php(13): require_once('...')\n#4 /var/www/vhosts/blog.k-res.net/index.php(17): require('...')\n#5 {main}\n  thrown in /var/www/vhosts/blog.k-res.net/wp-content/plugins/custom-iframe-widget/custom-iframe-widget.php on line 189'
[Fri Jul 11 16:21:52.750983 2025] [proxy_fcgi:error] [pid 19956:tid 20010] [client 49.232.55.15:43192] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function create_function() in /var/www/vhosts/blog.k-res.net/wp-content/plugins/custom-iframe-widget/custom-iframe-widget.php:189\nStack trace:\n#0 /var/www/vhosts/blog.k-res.net/wp-settings.php(545): include_once()\n#1 /var/www/vhosts/blog.k-res.net/wp-config.php(73): require_once('...')\n#2 /var/www/vhosts/blog.k-res.net/wp-load.php(50): require_once('...')\n#3 /var/www/vhosts/blog.k-res.net/wp-blog-header.php(13): require_once('...')\n#4 /var/www/vhosts/blog.k-res.net/index.php(17): require('...')\n#5 {main}\n  thrown in /var/www/vhosts/blog.k-res.net/wp-content/plugins/custom-iframe-widget/custom-iframe-widget.php on line 189'

简单看了下调用栈,发现果然是某个“古早”插件:“custom-iframe-widget”的问题,查了下报错异常“Call to undefined function create_function()”,就是8.3中废弃的函数,要换成匿名函数实现,于是小改了一下:

181 function custom_parse_iframe_widget($text)
182 {
183         return preg_replace_callback("@(?:<p>\s*)?\[ShaktiIFrame\s*(.*?)\](?:\s*</p>)?@", 'shakti_iframe_replace', $text);
184 }
185 
186 add_filter('the_content', 'custom_parse_iframe_widget');
187 add_filter('the_excerpt', 'custom_parse_iframe_widget');
188  $new_func = function() {register_widget("Custom_IFrame_Widget");};
189 //add_action( 'widgets_init', create_function( '', 'register_widget("Custom_IFrame_Widget");' ) );
190 add_action( 'widgets_init', $new_func );
191 ?>

结果,又报了新的错误:

[Fri Jul 11 16:28:48.619300 2025] [proxy_fcgi:error] [pid 19956:tid 19995] [remote 218.69.109.82:3061] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct(), 0 passed in /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-widget-factory.php on line 62 and at least 2 expected in /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-widget.php:163\nStack trace:\n#0 /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-widget-factory.php(62): WP_Widget->__construct()\n#1 /var/www/vhosts/blog.k-res.net/wp-includes/widgets.php(123): WP_Widget_Factory->register()\n#2 /var/www/vhosts/blog.k-res.net/wp-content/plugins/custom-iframe-widget/custom-iframe-widget.php(189): register_widget()\n#3 /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php(324): {closure}()\n#4 /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()\n#5 /var/www/vhosts/blog.k-res.net/wp-includes/plugin.php(517): WP_Hook->do_action()\n#6 /var/www/vhosts/blog.k-res.net/wp-includes/widgets.php(1870): do_action()\n#7 /var/www/vhosts/blog.k-res.net/wp...'
[Fri Jul 11 16:28:50.837111 2025] [proxy_fcgi:error] [pid 19956:tid 19959] [remote 218.69.109.82:3061] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct(), 0 passed in /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-widget-factory.php on line 62 and at least 2 expected in /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-widget.php:163\nStack trace:\n#0 /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-widget-factory.php(62): WP_Widget->__construct()\n#1 /var/www/vhosts/blog.k-res.net/wp-includes/widgets.php(123): WP_Widget_Factory->register()\n#2 /var/www/vhosts/blog.k-res.net/wp-content/plugins/custom-iframe-widget/custom-iframe-widget.php(189): register_widget()\n#3 /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php(324): {closure}()\n#4 /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()\n#5 /var/www/vhosts/blog.k-res.net/wp-includes/plugin.php(517): WP_Hook->do_action()\n#6 /var/www/vhosts/blog.k-res.net/wp-includes/widgets.php(1870): do_action()\n#7 /var/www/vhosts/blog.k-res.net/wp...'
[Fri Jul 11 16:28:52.378850 2025] [proxy_fcgi:error] [pid 19956:tid 19961] [remote 218.69.109.82:3061] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct(), 0 passed in /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-widget-factory.php on line 62 and at least 2 expected in /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-widget.php:163\nStack trace:\n#0 /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-widget-factory.php(62): WP_Widget->__construct()\n#1 /var/www/vhosts/blog.k-res.net/wp-includes/widgets.php(123): WP_Widget_Factory->register()\n#2 /var/www/vhosts/blog.k-res.net/wp-content/plugins/custom-iframe-widget/custom-iframe-widget.php(189): register_widget()\n#3 /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php(324): {closure}()\n#4 /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()\n#5 /var/www/vhosts/blog.k-res.net/wp-includes/plugin.php(517): WP_Hook->do_action()\n#6 /var/www/vhosts/blog.k-res.net/wp-includes/widgets.php(1870): do_action()\n#7 /var/www/vhosts/blog.k-res.net/wp...'

“Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct”,这个简单查了下,发现是构造时参数数量不匹配,PHP8.3对这方面的要求更加严格了,简单读了下代码,发现有点复杂,又看了下这个插件的信息:

Custom IFrame Widget

启用 | 删除

A Custom IFrame Widget, Short Code for Page,Post: [ShaktiIFrame url 650px 200px]

1.1 版本 | 作者:Shakti Kumar | 查看详情

已经14年没有更新了,印象中也没有用这个小工具的地方,于是最终放弃修改代码,直接删除了这个widget。

处理好后,再次刷新页面,还是crash,查看log:

[Fri Jul 11 16:25:42.886121 2025] [proxy_fcgi:error] [pid 19956:tid 19984] [remote 218.69.109.82:2980] AH01071: Got error 'PHP message: PHP Fatal error:  Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /var/www/vhosts/blog.k-res.net/wp-content/plugins/wp-category-tag-could/classes/wpctc-widget.php on line 224'
[Fri Jul 11 16:25:44.268693 2025] [proxy_fcgi:error] [pid 19956:tid 19985] [remote 103.107.219.218:39763] AH01071: Got error 'PHP message: PHP Fatal error:  Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /var/www/vhosts/blog.k-res.net/wp-content/plugins/wp-category-tag-could/classes/wpctc-widget.php on line 224'
[Fri Jul 11 16:25:44.518528 2025] [proxy_fcgi:error] [pid 19956:tid 20045] [client 103.107.219.235:14593] AH01071: Got error 'PHP message: PHP Fatal error:  Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /var/www/vhosts/blog.k-res.net/wp-content/plugins/wp-category-tag-could/classes/wpctc-widget.php on line 224'
[Fri Jul 11 16:25:45.319044 2025] [proxy_fcgi:error] [pid 19956:tid 19987] [remote 218.69.109.82:2980] AH01071: Got error 'PHP message: PHP Fatal error:  Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /var/www/vhosts/blog.k-res.net/wp-content/plugins/wp-category-tag-could/classes/wpctc-widget.php on line 224'
[Fri Jul 11 16:25:47.982762 2025] [proxy_fcgi:error] [pid 19956:tid 19992] [remote 103.167.26.12:21088] AH01071: Got error 'PHP message: PHP Fatal error:  Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /var/www/vhosts/blog.k-res.net/wp-content/plugins/wp-category-tag-could/classes/wpctc-widget.php on line 224'
[Fri Jul 11 16:25:52.036035 2025] [proxy_fcgi:error] [pid 19955:tid 19981] [remote 218.69.109.82:2984] AH01071: Got error 'PHP message: PHP Fatal error:  Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /var/www/vhosts/blog.k-res.net/wp-content/plugins/wp-category-tag-could/classes/wpctc-widget.php on line 224'
[Fri Jul 11 16:26:04.887852 2025] [proxy_fcgi:error] [pid 19956:tid 19994] [remote 218.69.109.82:2987] AH01071: Got error 'PHP message: PHP Fatal error:  Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /var/www/vhosts/blog.k-res.net/wp-content/plugins/wp-category-tag-could/classes/wpctc-widget.php on line 224'

发现是wp-category-tag-could这个小工具的错,报错代码是一个多级嵌套的问号表达式,显然8.3对这种骚代码的歧义性要求更严格了,按直接右边优先,修改一下:

201         $includeTags = '';
202         if (count($tags) > 0) {
203             foreach ($tags as $tag) {
204                 if ($instance['taxonomy'] == 'post_tag' && count($instance['tag_id']) > 0 && !in_array($tag->tag_id, $instance['tag_id'])) {
205                     continue;
206                 }
207                 if (isset($instance[$instance['taxonomy'] . '_id'])
208                     && count($instance[$instance['taxonomy'] . '_id']) > 0
209                     && !in_array($tag->tag_id, $instance[$instance['taxonomy'] . '_id'])
210                 ) {
211                     continue;
212                 }
213                 if (!in_array($tag->tag_id, $exclude)) {
214                     $includeTags = $tag->tag_id . ',' . $includeTags;
215                 }
216             }
217         }
218 
219         $cloud_args = array(
220             'smallest' => $instance['format'] == 'price' ? '100' : $instance['smallest'],
221             'largest' => $instance['format'] == 'price' ? '100' : $instance['largest'],
222             'unit' => '%',
223             'number' => $instance['number'],
224             //'format' => $instance['format'] == 'price' ? 'flat' : $instance['format'] == 'bars' ? 'list' : $instance['format'] == 'rounded' ? 'list' : $instance['format'],
224             'format' => $instance['format'] == 'price' ? 'flat' : ($instance['format'] == 'bars' ? 'list' : ($instance['format'] == 'rounded' ? 'list' : $instance['format'])),
225             'orderby' => $instance['order_by'],
226             'order' => $instance['order'],
227             'include' => null,
228             'link' => 'view',
229             'taxonomy' => $instance['taxonomy'],
230             'echo' => $instance['format'] != 'array',
231         );
232         if (strlen($includeTags > 0)) {
233             $cloud_args['include'] = $includeTags;
234         }
235         ?>

刷新请求,迎来下一个异常:

[Fri Jul 11 16:41:18.850168 2025] [proxy_fcgi:error] [pid 19956:tid 19992] [remote 218.69.109.82:3731] AH01071: Got error 'PHP message: PHP Warning:  Undefined variable $content in /var/www/vhosts/blog.k-res.net/wp-content/plugins/rejected-wp-keyword-link-rejected/wp_keywordlink.php on line 321; PHP message: PHP Fatal error:  Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, non-static method CustomPostOrder::CustomPostOrder_options() cannot be called statically in /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php:324\nStack trace:\n#0 /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()\n#1 /var/www/vhosts/blog.k-res.net/wp-includes/plugin.php(517): WP_Hook->do_action()\n#2 /var/www/vhosts/blog.k-res.net/wp-admin/includes/menu.php(161): do_action()\n#3 /var/www/vhosts/blog.k-res.net/wp-admin/menu.php(423): require_once('...')\n#4 /var/www/vhosts/blog.k-res.net/wp-admin/admin.php(159): require('...')\n#5 /var/www/vhosts/blog.k-res.net/wp-admin/index.php(10): require_once('...')\n#6 {main}\n  thrown in /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php on line 324'
[Fri Jul 11 16:41:45.121753 2025] [proxy_fcgi:error] [pid 19956:tid 19994] [remote 218.69.109.82:3748] AH01071: Got error 'PHP message: PHP Warning:  Undefined variable $content in /var/www/vhosts/blog.k-res.net/wp-content/plugins/rejected-wp-keyword-link-rejected/wp_keywordlink.php on line 321; PHP message: PHP Fatal error:  Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, non-static method CustomPostOrder::CustomPostOrder_options() cannot be called statically in /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php:324\nStack trace:\n#0 /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()\n#1 /var/www/vhosts/blog.k-res.net/wp-includes/plugin.php(517): WP_Hook->do_action()\n#2 /var/www/vhosts/blog.k-res.net/wp-admin/includes/menu.php(161): do_action()\n#3 /var/www/vhosts/blog.k-res.net/wp-admin/menu.php(423): require_once('...')\n#4 /var/www/vhosts/blog.k-res.net/wp-admin/admin.php(159): require('...')\n#5 /var/www/vhosts/blog.k-res.net/wp-admin/index.php(10): require_once('...')\n#6 {main}\n  thrown in /var/www/vhosts/blog.k-res.net/wp-includes/class-wp-hook.php on line 324'

这个异常都直接写明是哪个插件了:CustomPostOrder,哈哈。看了下代码,原来是8.3对回调函数的要求也更加严格了,CustomPostOrder::CustomPostOrder_options是个实例函数,所以不能作为回调函数使用,随后看了下CustomPostOrder的这个实例函数,发现里面根本没有访问成员的处理,于是直接加了个static:

 48 /**
 49  * Creation of the Custom Post Order
 50  * This class should host all the functionality that the plugin requires.
 51  */
 52 /*
 53  * first get the options necessary to properly display the plugin
 54  */
 55 
 56 
 57 
 58 if ( !class_exists( "CustomPostOrder" ) ) {
 59     add_action ( 'admin_menu', array ( 'CustomPostOrder', 'CustomPostOrder_options' ) );
 60     global $post;
 61 
 62     class CustomPostOrder {
 63 
 64         /**
 65          * Global Class Variables
 66          */
 67 
 68 
 69         var $optionsName = "CustomPostOrderOptions";
 70         var $version = "1.1";
 71 
 72 
 73 
 74      /**
 75          * CustomPostOrder plugin options page
 76          */
 77         static function CustomPostOrder_options ( ) {
 78                 if ( function_exists ( 'add_management_page' ) )
 79                 {
 80                     add_options_page( 'Custom Post Order', 'Custom Post Order', 9,
 81                             dirname ( __FILE__ ) .'/custom-post-order-adminfunctions.php' );
 82                 }
 83         }
 84 
 85         function custom_posts_order( $orderby )
 86         {
 87             $category_checked = false;
 88             $settings = get_option ( "CustomPostOrder-settings" );
 89             $cats = $settings['applyArray'];
 90             if ( $settings['applyTo'] == 'all')
 91                 return $settings['orderElement']." ".$settings['orderType'];
 92             else {
 93                 foreach ( $cats as $cat ):
 94                     if ( is_category ( $cat ) ) {
 95                         $category_checked = true;
 96                         break;
 97                     }
 98                 endforeach;
 99                 if ( $category_checked ) {
100                     return $settings['orderElement']." ".$settings['orderType'];
101                 }
102                 else

77行,修改后再次刷新,熟悉的wp页面终于又回来了。

博主友情提示:

如您在评论中需要提及如QQ号、电子邮件地址或其他隐私敏感信息,欢迎使用>>博主专用加密工具v3<<处理后发布,原文只有博主可以看到。