32
votes

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

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

Is there something that needs to be fixed?

6
You have a deprecated function in your functions.php you should change that. If you want help with it, we need to see the code. - DocRattie
That's strange.. I've just looked at my functions.php file inside my wp-includes folder, at this line.. and there's no constructor method being called.. although it lands right in the function that displays the error message in the admin. That's not right is it? - Lee

6 Answers

50
votes

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.

How to fix?

Option 1 - not going to upgrade to newer php versions

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

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

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

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

To

parent::__construct

22
votes

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()

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  );
    }
}
3
votes

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.

1
votes

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
  }
}
1
votes

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

define('WP_DEBUG', false);

-3
votes

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

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