Skip to main content
added 114 characters in body
Source Link
Dameer
  • 197
  • 1
  • 10

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

Class 'WP_Widget' not found in /Applications/XAMPP/...etc

Is there any other solution? Thanks!

I wrote WordPress plugin and want to include 2 extra Widgets with it...

if( !class_exists('plugin_name') ) {
    class plugin_name {
            // plugin code
    }
}

...and Widgets (according to WP codex) should be created like this:

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!

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!

Source Link
Dameer
  • 197
  • 1
  • 10

How do I create Widget within plugin that uses its own class?

I wrote WordPress plugin and want to include 2 extra Widgets with it...

if( !class_exists('plugin_name') ) {
    class plugin_name {
            // plugin code
    }
}

...and Widgets (according to WP codex) should be created like this:

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!