Create you own widget in WordPress

I just experienced one problem when create own widget for wordpress. The problem is taht I know that I need to use register_sidebar_widget. Problem appears after installing the plugin. I’m getting error:
Call to undefined function register_sidebar_widget
I found few examples where calling to this method is in inside of statement which checks if the method exists. I thought that it will exists only on some pages and not on all where the wordpress doesn’t need it. When I click on the widgets page, my control is not there. After short looking for solution and go through another plugins I found the solution.
You need to register the widget and control in plugins_loaded action.

add_action('plugins_loaded', array(&$this, 'plugins_loaded'));

function plugins_loaded()
{
	register_sidebar_widget('Widget name', array(&$this, 'widget_function'));
	register_widget_control(array('Widget name','widgets'), array(&$this, 'widget_function_control'), 300, 210);
}

Leave a Reply

Your email address will not be published. Required fields are marked *