The called constructor method for WP_Widget is deprecated since version 4.3.0
When you upgraded to WordPress 4.3, seeing a deprecation notice about WP_Widget is a common stumbling block for developers maintaining plugins or themes. The error message explicitly states: "The called constructor method for WP_Widget is deprecated since version 4.3.0! Use __construct() instead."
This notice indicates that your custom widget class is not extending the base class correctly, likely because you are calling a legacy constructor function directly rather than relying on the standard PHP magic method. In WordPress core, the WP_Widget class defines an internal __construct() method that initializes the widget's properties, sets up the arguments array, and handles registration logic. If your code attempts to override the constructor using the old naming convention or manually invokes a deprecated setup routine, the framework flags this behavior to encourage migration to the modern standard.
To resolve this issue, you need to inspect your custom widget class definition. The correct implementation relies on PHP's __construct() magic method, which is automatically invoked when a new instance of the class is created. You should define your constructor within the class body without prefixing it with parent unless you are explicitly chaining inheritance logic that requires it. Here is how the standard pattern looks:
class My_Custom_Widget extends WP_Widget {
public function __construct( $base_id = '', $name = null, $args = array() ) {
// Initialize parent properties and arguments here
$this->WP_Widget::__construct();
// Your custom initialization logic goes here
if ( ! empty( $base_id ) ) {
$this->id_base = $base_id;
}
}
public function widget( $args, $instance ) {
echo 'Widget Content';
}
}
The critical detail here is the signature. The __construct() method in WP_Widget expects specific parameters: $base_id, $name, and $args. If you were previously defining a constructor with different argument names or calling it without these, the deprecation warning appears because the internal logic of the base class expects to handle these registrations internally. By aligning your signature with the parent class, you allow WordPress to manage the registration of the widget ID and name correctly.
A common pitfall occurs when developers try to pass custom arguments directly into the constructor call without defining the method first, or they attempt to bypass the standard initialization flow. The deprecation warning serves as a soft brake on this practice, pushing developers toward a more robust architecture where the base class handles its own lifecycle events. If you are writing code for WordPress 4.3 or later, ignoring this notice means your plugin will eventually break when future versions of WordPress remove the legacy support entirely.
If you are maintaining an older plugin and cannot immediately refactor the code, you might consider silencing the specific error using error_reporting() logic, but this is generally a temporary workaround. The recommended approach is to update the class definition to match the current WP_Widget standards. This ensures compatibility with future WordPress releases and prevents potential conflicts with other plugins that might hook into the same widget lifecycle events.
For those looking to streamline their plugin development further, exploring modern registration methods or leveraging external libraries can reduce boilerplate code, though understanding the core WP_Widget structure remains essential for troubleshooting deprecation warnings.