I try to create an own Widget, but i got an error: Fatal error: Class 'my_widget' not found in /wp-includes/widgets.php on line 591
Here is my code from init.php:
class my_widget extends \WP_Widget {}
function wpb_load_widget() {
register_widget( 'my_widget' );
}
add_action( 'widgets_init', __NAMESPACE__ . '\\wpb_load_widget' );
Add namespaces in the end of the function, like this: function register_foo_widget() { register_widget( __NAMESPACE__ . '\\Foo_Widget' ); } add_action('widgets_init', __NAMESPACE__ . '\\register_foo_widget');