wp_insert_comment

ACTION wp-includes\comment.php (ligne 2059) github
Inserts a comment into the database.
traduction française
Insère un commentaire dans la base de données.

Paramètres

Entrée :
$commentdata
Sortie :
@param array $commentdata {
@return int|false The new comment's ID on success, false on failure.

Utilisation

Exécuter une action lors de l'ajout d'un commentaire

Action déclenchée quand un commentaire est inséré.

content
add_action('wp_insert_comment', 'on_new_comment', 10, 2);
function on_new_comment($comment_id, $comment) {
    if ($comment->comment_approved === 'spam') {
        wp_spam_comment($comment_id);
        return;
    }
    if ($comment->user_id > 0) {
        wp_set_comment_status($comment_id, 'approve');
    }
}

Actualités

Chargement des actualités...