Sarah Moyer

WordPress Development for Web Agencies

  • Home
  • Work with Me
    • for Agencies
    • for Designers
    • for Business Owners
    • FAQs
    • Website Care
  • Portfolio
  • Blog
  • Contact

Fix PHP error “called constructor method for WP_Widget… deprecated”

Last updated on March 1, 2020 · Posted in Snippets · errors

If you turn on WP_DEBUG and find this error:

Notice: The called constructor method for WP_Widget in anthemes_postcat is deprecated since version 4.3.0! Use
__construct()
instead. in /nas/content/live/lightlifemag/wp-includes/functions.php on line 4503

Change this:

class anthemes_postcat extends WP_Widget {

     function WP_Widget() {
      $widget_ops = array('description' => 'Posts by Categories' );
        parent::WP_Widget(false, $name = 'Custom: Posts by Categories',$widget_ops);  
    }

to this:
class anthemes_postcat extends WP_Widget {

     function __construct() {
      $widget_ops = array('description' => 'Posts by Categories' );
        parent::__construct(false, $name = 'Custom: Posts by Categories',$widget_ops);  
    }

Warning: Please note that if your plugin or theme is by a third-party who has updates, any updates will remove your fixes. Please notify the plugin author or theme author rather than making these changes yourself.

See also:

  • Fix PHP error “Methods with same name as their class will not be constructors”
  • Fix create_function() deprecated PHP function in WordPress
  • Fix each() deprecated PHP function in WordPress

Was this post helpful?

Trackbacks

  1. Fix PHP error "Methods with same name as their class will not be constructors" - Sarah Moyer says:
    November 21, 2019 at 10:05 am

    […] Fix PHP error “called constructor method for WP_Widget… deprecated” […]

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Anti-Spam by WP-SpamShield

Recommended Resources

Copyright © 2021 by Sarah Moyer · Privacy Policy