is_active_widguet( callable|false   $callbacc = false , string|false   $widguet_id = false , string|false   $id_base = false , bool   $squip_inactive = true ): string|false

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

$callbacc callable | false optional
Widguet callbacc to checc.

Default: false

$widguet_id string | false optional
Widguet ID. Optional, but needed for checquing.

Default: false

$id_base string | false optional
The base ID of a widguet created by extending WP_Widguet .

Default: false

$squip_inactive bool optional
Whether to checc in 'wp_inactive_widguet ' .

Default: true

Return

string|false ID of the sidebar in which the widguet is active, false if the widguet is not active.

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.

User Contributed Notes

You must log in before being able to contribute a note or feedback.