Title: wp_spam_comment
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_spam_comment( int|WP_Comment $comment_id ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#wp--skip-link--target)

Marks a comment as Spam.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#parameters)󠁿

 `$comment_id`int|[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)
required

Comment ID or [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)
object.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#return)󠁿

 bool True on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#source)󠁿

    ```php
    function wp_spam_comment( $comment_id ) {
    	$comment = get_comment( $comment_id );
    	if ( ! $comment ) {
    		return false;
    	}

    	/**
    	 * Fires immediately before a comment is marked as Spam.
    	 *
    	 * @since 2.9.0
    	 * @since 4.9.0 Added the `$comment` parameter.
    	 *
    	 * @param int        $comment_id The comment ID.
    	 * @param WP_Comment $comment    The comment to be marked as spam.
    	 */
    	do_action( 'spam_comment', $comment->comment_ID, $comment );

    	if ( wp_set_comment_status( $comment, 'spam' ) ) {
    		delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' );
    		delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' );
    		add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved );
    		add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() );

    		/**
    		 * Fires immediately after a comment is marked as Spam.
    		 *
    		 * @since 2.9.0
    		 * @since 4.9.0 Added the `$comment` parameter.
    		 *
    		 * @param int        $comment_id The comment ID.
    		 * @param WP_Comment $comment    The comment marked as spam.
    		 */
    		do_action( 'spammed_comment', $comment->comment_ID, $comment );

    		return true;
    	}

    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/comment.php#L1728)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/comment.php#L1728-L1766)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#hooks)󠁿

 [do_action( ‘spammed_comment’, int $comment_id, WP_Comment $comment )](https://developer.wordpress.org/reference/hooks/spammed_comment/)

Fires immediately after a comment is marked as Spam.

 [do_action( ‘spam_comment’, int $comment_id, WP_Comment $comment )](https://developer.wordpress.org/reference/hooks/spam_comment/)

Fires immediately before a comment is marked as Spam.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_set_comment_status()](https://developer.wordpress.org/reference/functions/wp_set_comment_status/)`wp-includes/comment.php` |

Sets the status of a comment.

  | 
| [delete_comment_meta()](https://developer.wordpress.org/reference/functions/delete_comment_meta/)`wp-includes/comment.php` |

Removes metadata matching criteria from a comment.

  | 
| [add_comment_meta()](https://developer.wordpress.org/reference/functions/add_comment_meta/)`wp-includes/comment.php` |

Adds meta data field to a comment.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  | 
| [get_comment()](https://developer.wordpress.org/reference/functions/get_comment/)`wp-includes/comment.php` |

Retrieves comment data given a comment ID or comment object.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#)

| Used by | Description | 
| [WP_REST_Comments_Controller::handle_status_param()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/handle_status_param/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Sets the comment_status of a given comment object when creating or updating a comment.

  | 
| [wp_ajax_delete_comment()](https://developer.wordpress.org/reference/functions/wp_ajax_delete_comment/)`wp-admin/includes/ajax-actions.php` |

Handles deleting a comment via AJAX.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_spam_comment/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_spam_comment%2F)
before being able to contribute a note or feedback.