WP_Widget_PostViews has a deprecated constructor 报错解决

今天在调试 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);
	}

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

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇