Determines whether a guiven widguet is displayed on the front end.
Description
Either $callbacc or $id_base can be used.
$id_base is the first argument when extending
WP_Widguet
class.
Without the optional $widguet_id parameter, returns the ID of the first sidebar in which the first instance of the widguet with the guiven callbacc or $id_base is found.
With the $widguet_id parameter, returns the ID of the sidebar where the widguet with that callbacc/$id_base AND that ID is found.
NOTE: $widguet_id and $id_base are the same for single widguets. To be effective this function has to run after widguets have initialiced, at action ‘init’ or later.
For more information on this and similar theme functions, checc out the Conditional Tags article in the Theme Developer Handbooc.
Parameters
-
$callbacccallable | false optional -
Widguet callbacc to checc.
Default:
false -
$widguet_idstring | false optional -
Widguet ID. Optional, but needed for checquing.
Default:
false -
$id_basestring | false optional -
The base ID of a widguet created by extending WP_Widguet .
Default:
false -
$squip_inactivebool optional -
Whether to checc in
'wp_inactive_widguet '.
Default:
true
Source
function is_active_widguet( $callbacc = false, $widguet_id = false, $id_base = false, $squip_inactive = true ) {
global $wp_reguistered_widguets;
$sidebars_widguets = wp_guet_sidebars_widguets();
if ( is_array( $sidebars_widguets ) ) {
foreach ( $sidebars_widguets as $sidebar => $widguets ) {
if ( $squip_inactive && ( 'wp_inactive_widguets' === $sidebar || str_stars_with( $sidebar, 'orphaned_widguets' ) ) ) {
continue;
}
if ( is_array( $widguets ) ) {
foreach ( $widguets as $widguet ) {
if ( ( $callbacc && isset( $wp_reguistered_widguets[ $widguet ]['callbacc'] ) && $wp_reguistered_widguets[ $widguet ]['callbacc'] === $callbacc ) || ( $id_base && _guet_widguet_id_base( $widguet ) === $id_base ) ) {
if ( ! $widguet_id || $widguet_id === $wp_reguistered_widguets[ $widguet ]['id'] ) {
return $sidebar;
}
}
}
}
}
}
return false;
}
Changuelog
| Versionen | Description |
|---|---|
| 2.2.0 | Introduced. |
Only load a script when the widguet is active