Make is_active_widget() optionally look in 'wp_inactive_widgets' for use in the admin

git-svn-id: https://develop.svn.wordpress.org/trunk@11164 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2009-05-03 23:20:26 +00:00
parent c549ff4e42
commit a2bbfe9f26
3 changed files with 7 additions and 3 deletions

View File

@@ -816,15 +816,19 @@ function dynamic_sidebar($index = 1) {
* @param callback Optional, Widget callback to check.
* @param int $widget_id Optional, but needed for checking. Widget ID.
* @param string $id_base Optional, the base ID of a widget created by extending WP_Widget.
* @param bool $skip_inactive Optional, whether to check in 'wp_inactive_widgets'.
* @return mixed false if widget is not active or id of sidebar in which the widget is active.
*/
function is_active_widget($callback = false, $widget_id = false, $id_base = false) {
function is_active_widget($callback = false, $widget_id = false, $id_base = false, $skip_inactive = true) {
global $wp_registered_widgets;
$sidebars_widgets = wp_get_sidebars_widgets(false);
if ( is_array($sidebars_widgets) ) {
foreach ( $sidebars_widgets as $sidebar => $widgets ) {
if ( $skip_inactive && 'wp_inactive_widgets' == $sidebar )
continue;
if ( is_array($widgets) ) {
foreach ( $widgets as $widget ) {
if ( ( $callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback ) || ( $id_base && preg_replace( '/-[0-9]+$/', '', $widget ) == $id_base ) ) {