php WP_Widget 的被调用构造函数方法自 4.3.0 版起已弃用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32860218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:14:57  来源:igfitidea点击:

The called constructor method for WP_Widget is deprecated since version 4.3.0

phpwordpress

提问by aniruddh

I just updated to WordPress 4.3 and it seems that something is broken.

我刚刚更新到 WordPress 4.3,似乎有些东西坏了。

I get this error that shows up on my page:

我收到显示在我的页面上的错误:

Notice: The called constructor method for WP_Widget is deprecated since version 4.3.0! Use __construct()instead. in /mnt/stor13-wc1-ord1/754452/www.eden-festival.com/web/content/securewp/wp-includes/functions.php on line 3457

注意:WP_Widget 被调用的构造函数方法从 4.3.0 版本开始被弃用!使用__construct()来代替。在 /mnt/stor13-wc1-ord1/754452/www.eden-festival.com/web/content/securewp/wp-includes/functions.php 第 3457 行

Is there something that needs to be fixed?

有什么需要修复的吗?

回答by Gal

Since php 7 isn't supported anymore, the old php 4 object construct was replaced with __construct(). Wordpress developers created a notice message so the plugin developers would change the way their plugins work (and also so it could run on next php versions). Since php 4 has long been dead, there's no reason to use this style of object construct.

由于不再支持 php 7,旧的 php 4 对象构造被替换为__construct(). Wordpress 开发人员创建了一条通知消息,以便插件开发人员更改其插件的工作方式(并且还可以在下一个 php 版本上运行)。由于 php 4 早已死了,没有理由使用这种风格的对象构造。

How to fix?

怎么修?

Option 1 - not going to upgrade to newer php versions

选项 1 - 不打算升级到较新的 php 版本

just add add_filter('deprecated_constructor_trigger_error', '__return_false');

只需添加 add_filter('deprecated_constructor_trigger_error', '__return_false');

to your functions.php file it will ignore those notices.

到您的functions.php 文件,它会忽略这些通知。

Option 2 - might upgrade to php 7 / prefer dealing with the issue rather than silencing it

选项 2 - 可能会升级到 php 7 / 更喜欢处理问题而不是使其沉默

If this is a third party plugin, beware that if you make the change yourself and the plugin developer releases an update then it will override your changes. Contacting the plugin developer to fix this issue will be the best option

如果这是第三方插件,请注意,如果您自己进行更改并且插件开发人员发布更新,那么它将覆盖您的更改。联系插件开发者解决这个问题将是最好的选择

Find the problematic plugin and change:

找到有问题的插件并更改:

parent::WP_Widget

parent::WP_Widget

To

parent::__construct

parent::__construct

回答by Ganesh

I am also getting the same error And I fixed it in such a way

我也遇到了同样的错误 我以这种方式修复了它

class Dokan_Category_Widget extends WP_Widget {

    /**
     * Constructor
     *
     * @return void
     **/
    public function __construct() {
        $widget_ops = array( 'classname' => 'dokan-category-menu', 'description' => __( 'Dokan product category menu', 'dokan' ) );
        $this->WP_Widget( 'dokan-category-menu', 'Dokan: Product Category', $widget_ops );
    }
}

As way of calling constructor in such way is deprecated in php 7, so I replaced calling way as $this->WP_Widget()with parent::__construct()

由于调用这样的方式构造方法在PHP 7弃用,因此,我调用替换方式$this->WP_Widget()parent::__construct()

class Dokan_Category_Widget extends WP_Widget {

    /**
     * Constructor
     *
     * @return void
     **/
    public function __construct() {
        $widget_ops = array( 'classname' => 'dokan-category-menu', 'description' => __( 'Dokan product category menu', 'dokan' ) );
        //$this->WP_Widget( 'dokan-category-menu', 'Dokan: Product Category', $widget_ops );
        parent::__construct('dokan-category-menu', 'Dokan: Product Category', $widget_ops  );
    }
}

回答by Prafulla Kumar Sahu

I guess you are using some plugin that is not updated after wordpress updates and having some code like class ***_Widget extends WP_Widget {.you should update that plugin or deactivate it until It is updated.

我猜你正在使用一些在 wordpress 更新后没有更新的插件,并且有一些像class ***_Widget extends WP_Widget {.you 应该更新该插件或停用它的代码,直到它更新。

回答by coletrain

Declaring a function then calling the parent constructor resolved this issue for me.

声明一个函数然后调用父构造函数为我解决了这个问题。

class myClass extends WP_Widget {
  function __construct(){
     parent::__construct(...) // calls constructor from WP_Widget class
  }
}

回答by Hoque MD Zahidul

Its kind of warning you can hide the error using add a line in your wp-config.phpfile in your site root directory

它的警告类型,您可以使用wp-config.php在站点根目录中的文件中添加一行来隐藏错误

define('WP_DEBUG', false);

定义('WP_DEBUG',假);

回答by Robbie

I experienced this issue and I found by changing the 'true' statement to 'false' in /wp-includes/functions.php it disabled the errors.

我遇到了这个问题,我发现通过将 /wp-includes/functions.php 中的“true”语句更改为“false”,它禁用了错误。

if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {

if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {