Description

Le hook 'doing_it_wrong_run' qui sera appelé peut être utilisé pour garder la trace d'un fichier ou d'une fonction dépréciée.

Le comportement actuel est de cibler une erreur utilisateur si la constante 'WP_DEBUG' est à true.

Paramètres

$function

(string) (Requis) La fonction qui a été appelé.

$message

(string) (Requis) Un message expliquant ce qui a été fait incorrectement.

$version

(string) (Requis) La version de WordPress où le message a été ajouté.

Structure de la fonction _doing_it_wrong()

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

function _doing_it_wrong( $function, $message, $version ) {

    /**
     * Fires when the given function is being used incorrectly.
     *
     * @since 3.1.0
     *
     * @param string $function The function that was called.
     * @param string $message  A message explaining what has been done incorrectly.
     * @param string $version  The version of WordPress where the message was added.
     */
    do_action( 'doing_it_wrong_run', $function, $message, $version );

    /**
     * Filters whether to trigger an error for _doing_it_wrong() calls.
     *
     * @since 3.1.0
     * @since 5.1.0 Added the $function, $message and $version parameters.
     *
     * @param bool   $trigger  Whether to trigger the error for _doing_it_wrong() calls. Default true.
     * @param string $function The function that was called.
     * @param string $message  A message explaining what has been done incorrectly.
     * @param string $version  The version of WordPress where the message was added.
     */
    if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true, $function, $message, $version ) ) {
        if ( function_exists( '__' ) ) {
            if ( $version ) {
                /* translators: %s: Version number. */
                $version = sprintf( __( '(This message was added in version %s.)' ), $version );
            }

            $message .= ' ' . sprintf(
                /* translators: %s: Documentation URL. */
                __( 'Please see <a href="%s">Debugging in WordPress</a> for more information.' ),
                __( 'https://wordpress.org/support/article/debugging-in-wordpress/' )
            );

            trigger_error(
                sprintf(
                    /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: WordPress version number. */
                    __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ),
                    $function,
                    $message,
                    $version
                ),
                E_USER_NOTICE
            );
        } else {
            if ( $version ) {
                $version = sprintf( '(This message was added in version %s.)', $version );
            }

            $message .= sprintf(
                ' Please see <a href="%s">Debugging in WordPress</a> for more information.',
                'https://wordpress.org/support/article/debugging-in-wordpress/'
            );

            trigger_error(
                sprintf(
                    '%1$s was called <strong>incorrectly</strong>. %2$s %3$s',
                    $function,
                    $message,
                    $version
                ),
                E_USER_NOTICE
            );
        }
    }
}

Fonctions et Hooks utilisés par _doing_it_wrong()

__()

Retourne la traduction d'un texte.

doing_it_wrong_run

Se lance quand la fonction donnée est utilisée incorrectement.

doing_it_wrong_trigger_error

Se lance quand une erreur est ciblée.

do_action()

Exécute des fonctions attachées à un hook spécifique.

apply_filters()

Appel les fonctions qui ont été attaché à un filtre (hook).

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

Sources

Codex Wordpress : _doing_it_wrong()

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

Retour