Fixing Your Deprecated Widget Constructors in WordPress 4.3

This is a really old version of WordPress, you should seriously consider updating the latest version.

As of WordPress 4.3 older versions of constructor functions are deprecated. Typically these are common in widgets, where you’re extending the parent WP_Widget class. I’ve recently updated a few of my older versions in my plugins and on client site’s, here’s the basics.

Older, depreciated code can be found here.

This is the new way:

It breaks down to being an older PHP method – naming the constructor function the same as the class and/or calling the parent constructor via the class name. Newer versions of PHP allow us to call parent classes via parent:: and utilize the __construct() function, which is now the preferred method for WordPress.

For more information, check out the WP Core Blog post on the subject and the Widgets API Documentation.


2 responses to “Fixing Your Deprecated Widget Constructors in WordPress 4.3”

  1. Fyi, typo in your first sentence. Should be “constructor functions are deprecated” 🙂

    1. Ah, nice find, thanks for the heads up – I’ve updated it accordingly.