From b66bda65e4d1cc2d926b319d9046c539ee35a478 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 17 Apr 2009 05:54:07 +0000 Subject: [PATCH] unregister_widget(). see #8441 git-svn-id: http://svn.automattic.com/wordpress/trunk@10979 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/widgets.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index 5cc93474f..ab6e24ac4 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. *