wp_spam_comment

Marks a comment as Spam.

Description

wp_spam_comment( (int|WP_Comment) $comment_id ); 

Parameters (1)

0. $comment_id (int|WP_Comment)
Comment ID or WP_Comment object.

Usage

  1. if ( !function_exists( 'wp_spam_comment' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // Comment ID or WP_Comment object. 
  5. $comment_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_spam_comment($comment_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment.php  
  1. function wp_spam_comment( $comment_id ) { 
  2. $comment = get_comment( $comment_id ); 
  3. if ( ! $comment ) { 
  4. return false; 
  5.  
  6. /** 
  7. * Fires immediately before a comment is marked as Spam. 
  8. * @since 2.9.0 
  9. * @param int $comment_id The comment ID. 
  10. */ 
  11. do_action( 'spam_comment', $comment->comment_ID ); 
  12.  
  13. if ( wp_set_comment_status( $comment, 'spam' ) ) { 
  14. delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); 
  15. delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); 
  16. add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved ); 
  17. add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() ); 
  18. /** 
  19. * Fires immediately after a comment is marked as Spam. 
  20. * @since 2.9.0 
  21. * @param int $comment_id The comment ID. 
  22. */ 
  23. do_action( 'spammed_comment', $comment->comment_ID ); 
  24. return true; 
  25.  
  26. return false;