Wordpress 插件 'WP_widget' 已弃用,如何修复?
Wordpress plugin 'WP_widget' deprecated, how to fix it?
我下载了一个我非常想使用的 Wordpress 插件。唯一的问题是它在使用 WP_widget.
进行调试时会抛出一个已弃用的错误
Notice: The called constructor method for WP_Widget in SteamApiWidget is deprecated since version 4.3.0! Use
__construct()
instead. in functions.php on line 3770
所以我做了一些搜索,但不幸的是,简单地将 'WP_widget' 替换为“__construct()”只会破坏插件。这就是我的编码知识。我发现 'WP_widget' 的两个实例在下方。我需要更改什么才能使其符合当前 PHP 标准?
/**
* Class SteamApiWidget
*/
class SteamApiWidget extends WP_Widget
和
/**
* @constructor
*/
public function __construct()
{
$this->initPluginConstants();
$widget_option = array(
'classname' => PLUGIN_SLUG,
'description' => __('A simple WordPress widget for your steam profile.', PLUGIN_LOCALE)
);
$this->WP_Widget(PLUGIN_SLUG, __(PLUGIN_NAME, PLUGIN_LOCALE), $widget_option);
$this->registerScriptsAndStyles();
}
替换为:
$this->WP_Widget(PLUGIN_SLUG, __(PLUGIN_NAME, PLUGIN_LOCALE), $widget_option);
和
parent::__construct(PLUGIN_SLUG, __(PLUGIN_NAME, PLUGIN_LOCALE), $widget_option);
您可能必须首先将它放在包含该行的 __construct 函数中。
我下载了一个我非常想使用的 Wordpress 插件。唯一的问题是它在使用 WP_widget.
进行调试时会抛出一个已弃用的错误Notice: The called constructor method for WP_Widget in SteamApiWidget is deprecated since version 4.3.0! Use __construct() instead. in functions.php on line 3770
所以我做了一些搜索,但不幸的是,简单地将 'WP_widget' 替换为“__construct()”只会破坏插件。这就是我的编码知识。我发现 'WP_widget' 的两个实例在下方。我需要更改什么才能使其符合当前 PHP 标准?
/**
* Class SteamApiWidget
*/
class SteamApiWidget extends WP_Widget
和
/**
* @constructor
*/
public function __construct()
{
$this->initPluginConstants();
$widget_option = array(
'classname' => PLUGIN_SLUG,
'description' => __('A simple WordPress widget for your steam profile.', PLUGIN_LOCALE)
);
$this->WP_Widget(PLUGIN_SLUG, __(PLUGIN_NAME, PLUGIN_LOCALE), $widget_option);
$this->registerScriptsAndStyles();
}
替换为:
$this->WP_Widget(PLUGIN_SLUG, __(PLUGIN_NAME, PLUGIN_LOCALE), $widget_option);
和
parent::__construct(PLUGIN_SLUG, __(PLUGIN_NAME, PLUGIN_LOCALE), $widget_option);
您可能必须首先将它放在包含该行的 __construct 函数中。