[wp-hackers] Programmatic Widget Handling

Jeremy Clarke jer at simianuprising.com
Wed Oct 20 19:06:00 UTC 2010

On Wed, Oct 20, 2010 at 2:33 PM, Moya, Eddie <emoya at tribune.com> wrote:

>  1.  Activate/Deactivate, similar to the way you can with plugins

I might have been confused because that is something that is easy to do with
the existing api:

function custom_widgets_init() {

    // Uncomment these two lines for output of default widgets
    //global $wp_widget_factory;

    // Unregister the default recent comments widget

    // Register our better version
add_action('widgets_init', 'custom_widgets_init');

I'm pretty sure that unregister_widget() will even fail gracefully if the
widget in question wasn't registered, meaning you can unregister plugin
widgets without worrying about whether the plugin is installed on the
current site.

 3.  Role/Capability-based access using/modifying widgets. (Possibly equally
> as needed, but probably more difficult to implement)

For number 3, obviously widget developers can create there widgets with
> capability-based conditions in place - but whats really needed is for the
> users of any widget to be able to say certain widgets are off-limits to
> certain users.
If someone can edit a sidebar then having widgets that they can't edit will
mean there are parts of the sidebar that they can't change. This seems
pretty user-unfriendly to me, and I don't even want to start thinking
through all the logic you'd need to handle to make it work well. I'd tend to
think that you should instead limit Widgets/Sidebars access to those you can
trust with the content of the sidebar.

Jeremy Clarke
Code and Design | globalvoicesonline.org

More information about the wp-hackers mailing list