I wrote WordPress plugin and want to include 2 extra Widgets with it...
if( !class_exists('plugin_name') ) {
class plugin_name {
// plugin code
}
}
// include widgets code
require_once( 'include/custom_functions.php' );
...and Widgets (according to WP codex) should be created like this within "custom_functions.php":
class My_Widget extends WP_Widget {
// widget code
}
function sfp_register_widgets() {
register_widget( 'My_Widget' );
}
add_action( 'widgets_init', 'sfp_register_widgets' );
I can't put "class SFP_Search extends WP_Widget" inside my plugin's class and if I place it outside, I get an error:
Class 'WP_Widget' not found in /Applications/XAMPP/...etc
Is there any other solution? Thanks!
WP_Widget
is loaded earlier than any plugin. Does your widget file run in a WordPress context, or do you call it directly?plugins_loaded
. maybe you create a new instance vianew Your_Class
and this is to early for the classWP_Widget
.