Paramètres

$tag

(string) (Requis) Nom du hook.

$function_to_check

(callable | bool) (Optionnel) Fonction d'appel du hook.

Valeur par défaut : false

Retourne

(bool | int) Si $function_to_check est omis, retourne true si le hook a été enregistré, false sinon.

Quand une fonction est spécifiée, la priorité du hook est retournée ou false si elle n'est pas attachée au hook. La priorité peut valoir 0 donc la valeur de retour doit être testée avec l'opérateur ===.

Structure de la fonction has_filter()

Définie dans le fichier wp-includes/plugin.php à la ligne 133 :

function has_filter( $tag, $function_to_check = false ) {
    global $wp_filter;

    if ( ! isset( $wp_filter[ $tag ] ) ) {
        return false;
    }

    return $wp_filter[ $tag ]->has_filter( $tag, $function_to_check );
}

Où trouver la fonction has_filter() dans le CMS Wordpress

Exemple

if ( ! has_filter( 'the_content', 'example_alter_the_content' ) ){
    add_filter( 'the_content', 'prefix_alter_the_content' );
}

Sources

Codex Wordpress : has_filter()

Autres fonctions dans le même fichier : wp-includes/plugin.php

Retour