With the continuous evolution of PHP, the backbone language of WordPress, it’s inevitable that older coding practices will become obsolete and might even break on newer versions. WPengine, one of our most highly recommended WordPress hosting platforms, has announced its transition to PHP 8.2 and is phasing out support for PHP 7.4. This move is significant for numerous websites, especially those using older themes that haven’t updated their widget registration methods. One of our clients who came to us with a broken website that was due to this problem was running the “Apex” theme by Templatic Themes.
The Problem
The older method of registering widgets in WordPress themes used the PHP 4 style constructors, which have been deprecated since PHP 7 and are now removed in PHP 8. This means that any theme or plugin still using this old method is at risk of breaking when the hosting environment upgrades to PHP 8.2.
In this particular instance, the client was getting a critical error screen on their homepage and they couldn’t access the backend of their website (wp-admin). Here’s a screenshot from the client’s website after we enabled WP_DEBUG_DISPLAY in their wp-config.php file.

What the issue looks like
The older method looked something like this:
function My_Widget_Class() {
// Constructor content here...
$this->WP_Widget('widget-id', 'Widget Name', $widget_ops);
}
This approach involves defining a function with the same name as the class. This is the PHP 4 style of creating class constructors, which is now outdated.
The Solution
For PHP 7 and onwards, especially to be compatible with PHP 8.2, widget registration should use the __construct() method. The updated method looks like this:
function __construct() {
// Constructor content here...
parent::__construct('widget-id', 'Widget Name', $widget_ops);
}
Step-by-Step Guide to Updating Your Theme’s Widget Registration
- Backup Your Theme/Website: Before making any changes, ensure you have a complete backup of your theme and website. This is a best practice before making any changes to your live site.
- Identify Outdated Widget Constructors: Search for any function within your theme that has the same name as its class. This is a clear indication of the old PHP 4 style constructor. If you are not sure where they need to be updated, enable wp_debug_log in your wp-config.php file and check to see
- Update the Constructor: Replace the old-style function with the __construct() method.
- Before:
function Tmpl_Widget_Example() { // Constructor content... $this->WP_Widget('widget-id', 'Widget Name', $widget_ops); } - After:
function __construct() { // Constructor content... parent::__construct('widget-id', 'Widget Name', $widget_ops); } - Test Your Changes: After updating, ensure to test the widget’s functionality on a staging environment. Ensure it appears correctly, saves options as expected, and no errors are displayed.
- Deploy to Live Site: Once you’re confident with the changes, you can update the theme on your live site. Again, ensure you have backups in place.
Conclusion
With PHP continually evolving, it’s essential for website owners, developers, and theme authors to stay updated and adapt their code accordingly. The transition from PHP 7.4 to PHP 8.2 in platforms like WPengine underscores this need. By updating your widget registration methods as detailed above, you ensure that your WordPress website remains functional, efficient, and free from errors related to outdated PHP practices.
Remember, always backup your site and test changes in a safe environment before applying them to your live site. Stay updated, stay secure, and if you need help we’re here to offer both emergency WordPress debugging services as well as regularly scheduled WordPress maintenance!
