2

This error only happened this morning as I updated my wordpress site to version 4.3. Two other sites on the same hosting ( and all using CPanel as an admin portal for the hosting) are not having any problem. On this one problematic site company.com though on the wordpress admin portal and the live site there is an error repeating several times at the top of the page, that is:

The error continues down the page like this 9 times.

The error page is then finished off with this error/line.

I have read up today on this and it is perhaps to do with upgrading from PHP4 to PHP5, although there is no problem with the other WP sites on the same server. I also disabled all the plugins on the site to test and the problem was still there. Short of restoring from a backup (which is not easy to do and can cause errors of its own) is there anyone else having this issue today/recently?

It does not help that the error message appears to suggest a solution itself before it is cut off at the end with

Use...". The error message begins "company/public_html/wp-includes/ ...". The second line is "constructor method for WP_Widget is deprecated since version 4.3.0.

Version 4.3 is the version that WP was updated to today. It seemingly has caused this error but I do not know how to fix it.

Any other information needed to answer this I'll be more than happy to provide.

  • 2
    Have you seen this? make.wordpress.org/core/2015/07/02/… – kraftner Aug 19 '15 at 15:14
  • 1
    It does not help that the error message appears to suggest a solution itself before it is cut off at the end -- If you View Source of the page, can you read the full error message? – Pat J Aug 19 '15 at 15:20
  • The error doesn't actually cut off it appears, post updated with more accurate error image. I've seen that article. Is there a way in CPanel/WP/Hosting to see what PHP version is being used because 'PHP Configuration' in CPanel doesn't seem to show it. – MuccyCork Aug 20 '15 at 9:43
4

The error isn't actually caused by your PHP version (PHP 4 constructors won't be removed until PHP 7) - it's a warning produced by WordPress in preparation for this. Each repetition of the error represents a plugin using the outdated code.

Until your plugins' authors update them, you can run the following shell command on a Linux system to find the old constructor calls:

grep -R "WP_Widget\(" /path/to/your/wp/install

This will give you a list of files that you can either modify on the command line, or use WP's plugin editor. Matched strings - mostly parent::WP_Widget(args) should be changed to parent::__construct(args).

  • Is this not negated by the fact that I deactivated all the plugins and still got the same errors? – MuccyCork Aug 20 '15 at 9:34
  • @MuccyCork the deprecated code could be part of your theme - the grep command will find it wherever it is. Bear in mind that it will match plugins and themes that aren't active, in which case you can ignore those files. – tjbp Aug 20 '15 at 10:00
3

It seems that it's not WP_Widget that's being updated, but the way it is referenced.

I believe what we want is to go from this:

class mZ_Mindbody_day_schedule extends WP_Widget {

        function mZ_Mindbody_day_schedule() {
                $widget_ops = array(
                        'classname' => 'mZ_Mindbody_day_schedule_class',
                        'description' => __('Display class schedule for current day.', 'mz-mindbody-api')
                        );
                $this->WP_Widget('mZ_Mindbody_day_schedule', __('Today\'s MindBody Schedule', 'mz-mindbody-api'),
                                                        $widget_ops );
        } 

To this:

class mZ_Mindbody_day_schedule extends WP_Widget {

        function mZ_Mindbody_day_schedule() {
                $widget_ops = array(
                        'classname' => 'mZ_Mindbody_day_schedule_class',
                        'description' => __('Display class schedule for current day.', 'mz-mindbody-api')
                        );
                parent::__construct('mZ_Mindbody_day_schedule', __('Today\'s MindBody Schedule', 'mz-mindbody-api'),
                                                        $widget_ops );
        } 

Where it's only line six of the above code that gets updated.

2

WordPress is giving you a notice that this construct is deprecated, because it is preparing for PHP7. You should check your custom code and any plug-ins for the use of the WP_Widget construct. There are (still) a lot of plug-ins that need to update their code.

Here is a list of plug-ins that use the deprecated WP_Widget construct: https://gist.github.com/chriscct7/d7d077afb01011b1839d

You can either wait for the plug-in authors to update their code or you can change the code of plug-ins (temporarily) yourself. There is a good summary about changing your code (by Chris Christoff)

Basically instead of doing these:

  • {classname}::{classname}() as in WP_Widget::WP_Widget() or
  • parent::{classname}() as in parent::WP_Widget() or
  • {object}->{classname}() as in {object}->WP_Widget() (a more specific example: $this->WP_Widget())

Do:

  • parent::__construct() to call the parent class constructor from a child class
  • $var = new {class name}() as in $var = new My_Widget_Class() to hold an instance of a widget (don't use My_Widget_Class as the name of your widget class though, use something more unique and applicable to avoid class name conflicts with other plugins.
1

If you want to keep WP_DEBUG on and do you want to hide this specific type of error, put in your theme functions.php this line:

add_filter('deprecated_constructor_trigger_error', '__return_false');

This will prevent this kind of error to be displayed.

I hope it helps :)

  • Is this still avoiding fixing the problem? – MuccyCork Aug 31 '15 at 16:41
  • I prefer to let the plugin developers to fix the real problem: it's not an error, only a notice to remind THEM to fix it :) – Lorenzo Zottar Sep 1 '15 at 0:23
0

I was in a similar boat (first had to fix some custom widgets in a theme), but had the message even after fixing them.

Switched to a default theme: still had the same error.

TL;DR: Started deactivating plugins one-by-one... found https://wordpress.org/plugins/list-category-posts/ was the culprit.

  • Good method but I deactivated all the plugins and still got the same error. If there was a way to deactivate widgets and activate them as easily as you can do with plugins then this would make troubleshooting a lot easier. – MuccyCork Aug 20 '15 at 9:31
-1

Wordpress Debug mode can produce these kinds of messages.

I had the same problem on one of my sites.

Maybe you have this line of code on your wp-config.php file:

define('WP_DEBUG', true);

Try changing it to:

define('WP_DEBUG', false);

Hope it helps.

  • 1
    That will only hide the bug. Debug is there for a reason. You should always correct a bug and not simply hide it, a bug stays a bug, hidden or not – Pieter Goosen Aug 27 '15 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.