Jump to content
xisto Community
Sign in to follow this  
k_nitin_r

The Wp_Widget Constructor Parameters

Recommended Posts

While building WordPress widgets, I use the widget API that was introduced in WordPress 2.8. I have always wondered, however, what the parameters passed to the WP_Widget constructor are and have only been passing in a false followed by the name of the widget. My curiosity got the better of me today and I finally decided to go figure out what the other parameters to the WP_Widget constructor were.I looked up Google, the all-knowing search engine that documents almost all of the knowledge known to man, but all I could find were tutorial sites that explained how to build a widget and all they would say is along the lines of "pass in the name of the widget as the second parameter". As my search went on, I reached the definition of the WP_Widget class and I noticed that the WP_Widget class does indeed take four parameters, which are the Base ID, the widget name, options for the widget, and other control options. The default value for the Base ID is taken as false, which is the argument being passed to the $id_base parameter by most tutorials and widgets out there. The name is something for the plugin developer to specify and is self-explanatory. The widget options are values that are passed on to the wp_register_sidebar_widget function (I hope you still remember that function from the pre-WordPress 2.8 days) and can take a class name and a description through an associative array. The control options, which are the last parameter to the WP_Widget constructor, can take parameters to pass to the wp_register_widget_control function that can specify the width and height for the widget. The width parameter can be specified but the height parameter has been document as not currently used. Both the width and the height control options are passed in through an associative array.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.