WP_Widget_PostViews has a deprecated constructor 报错解决

建站笔记2年前 (2023)发布 小萝卜头
317 0 0
今天在调试 WordPress 的时候,打开了 DEBUG 信息,结果额外出现了如下报错信息:

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; WP_Widget_PostViews has a deprecated constructor in ***** /wp-content/plugins/wp-postviews/wp-postviews.php on line 670
Invalid comment status.

百度了一把,发现是函数和类构造名称冲突了,解决办法如下:

编辑 wp-postviews.php 这个文件,定位到 670 行如下代码:

 class WP_Widget_PostViews extends WP_Widget {
	// Constructor
	function WP_Widget_PostViews() {
		$widget_ops = array('description' => __('WP-PostViews views statistics', 'wp-postviews'));
		$this->WP_Widget('views', __('Views', 'wp-postviews'), $widget_ops);
	}

很明显,function 名称和 class 冲突了,所以我们只要把 function 名称改成 __construct 即可:

 class WP_Widget_PostViews extends WP_Widget {
	// Constructor
	function __construct() {
		$widget_ops = array('description' => __('WP-PostViews views statistics', 'wp-postviews'));
		$this->WP_Widget('views', __('Views', 'wp-postviews'), $widget_ops);
	}

保存后这个错误就解决了,如果遇到类似的报错,也可以参考解决了。

收录于{张戈博客} 原文链接原文链接

© 版权声明

相关文章

暂无评论

暂无评论...