is_active_widget()
最后更新于:2021-11-27 07:58:06
is_active_widget( callable|false$callback=false, string|false$widget_id=false, string|false$id_base=false, bool$skip_inactive=true)Determines whether a given widget is displayed on the front end.
参数
- $callback
-
(callable|false) (Optional) Widget callback to check.
Default value: false
- $widget_id
-
(string|false) (Optional) Widget ID. Optional, but needed for checking.
Default value: false
- $id_base
-
(string|false) (Optional) The base ID of a widget created by extending GC_Widget.
Default value: false
- $skip_inactive
-
(bool) (Optional) Whether to check in ‘gc_inactive_widgets’.
Default value: true
响应
(string|false) ID of the sidebar in which the widget is active, false if the widget is not active.
源文件
文件: gc-includes/widgets.php
function is_active_widget( $callback = false, $widget_id = false, $id_base = false, $skip_inactive = true ) {
global $gc_registered_widgets;
$sidebars_widgets = gc_get_sidebars_widgets();
if ( is_array( $sidebars_widgets ) ) {
foreach ( $sidebars_widgets as $sidebar => $widgets ) {
if ( $skip_inactive && ( 'gc_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) ) {
continue;
}
if ( is_array( $widgets ) ) {
foreach ( $widgets as $widget ) {
if ( ( $callback && isset( $gc_registered_widgets[ $widget ]['callback'] ) && $gc_registered_widgets[ $widget ]['callback'] === $callback ) || ( $id_base && _get_widget_id_base( $widget ) === $id_base ) ) {
if ( ! $widget_id || $widget_id === $gc_registered_widgets[ $widget ]['id'] ) {
return $sidebar;
}
}
}
}
}
}
return false;
}