From 19ee1343254a4c3477ad3255564a5b6c11c162d6 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 17 Apr 2009 05:54:07 +0000 Subject: [PATCH] unregister_widget(). see #8441 git-svn-id: https://develop.svn.wordpress.org/trunk@10979 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/widgets.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index 5cc93474f3..ab6e24ac40 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -293,6 +293,14 @@ class WP_Widget_Factory { $this->widgets[] = new $widget_class(); } + function unregister($widget_class) { + $offset = array_search($widget_class, $this->widgets); + if ( false === $offset ) + return; + + array_splice($this->widgets, $offset, 1); + } + function _register_widgets() { foreach ( $this->widgets as $widget ) $widget->_register(); @@ -350,6 +358,26 @@ function register_widget($widget_class) { $wp_widget_factory->register($widget_class); } +/** + * Unregister a widget + * + * Unregisters a WP_Widget widget. Useful for unregistering default widgets. + * Run within a function hooked to the widgets_init action. + * + * @since 2.8.0 + * + * @see WP_Widget + * @see WP_Widget_Factory + * @uses WP_Widget_Factory + * + * @param string $widget_class The name of a class that extends WP_Widget + */ +function unregister_widget($widget_class) { + global $wp_widget_factory; + + $wp_widget_factory->unregister($widget_class); +} + /** * Creates multiple sidebars. *