3 WP_CLI::add_command( 'akismet', 'Akismet_CLI' );
6 * Filter spam comments.
8 class Akismet_CLI extends WP_CLI_Command {
10 * Checks one or more comments against the Akismet API.
14 * : The ID(s) of the comment(s) to check.
17 * : Don't change the status of the comment. Just report what Akismet thinks it is.
21 * wp akismet check 12345
23 * @alias comment-check
25 public function check( $args, $assoc_args ) {
26 foreach ( $args as $comment_id ) {
27 if ( isset( $assoc_args['noaction'] ) ) {
28 // Check the comment, but don't reclassify it.
29 $api_response = Akismet::check_db_comment( $comment_id, 'wp-cli' );
32 $api_response = Akismet::recheck_comment( $comment_id, 'wp-cli' );
35 if ( 'true' === $api_response ) {
36 WP_CLI::line( sprintf( __( "Comment #%d is spam.", 'akismet' ), $comment_id ) );
38 else if ( 'false' === $api_response ) {
39 WP_CLI::line( sprintf( __( "Comment #%d is not spam.", 'akismet' ), $comment_id ) );
42 if ( false === $api_response ) {
43 WP_CLI::error( __( "Failed to connect to Akismet.", 'akismet' ) );
45 else if ( is_wp_error( $api_response ) ) {
46 WP_CLI::warning( sprintf( __( "Comment #%d could not be checked.", 'akismet' ), $comment_id ) );
53 * Recheck all comments in the Pending queue.
57 * wp akismet recheck_queue
59 * @alias recheck-queue
61 public function recheck_queue() {
65 $total_counts = array();
68 $result_counts = Akismet_Admin::recheck_queue_portion( $start, $batch_size );
70 if ( $result_counts['processed'] > 0 ) {
71 foreach ( $result_counts as $key => $count ) {
72 if ( ! isset( $total_counts[ $key ] ) ) {
73 $total_counts[ $key ] = $count;
76 $total_counts[ $key ] += $count;
79 $start += $batch_size;
80 $start -= $result_counts['spam']; // These comments will have been removed from the queue.
82 } while ( $result_counts['processed'] > 0 );
84 WP_CLI::line( sprintf( _n( "Processed %d comment.", "Processed %d comments.", $total_counts['processed'], 'akismet' ), number_format( $total_counts['processed'] ) ) );
85 WP_CLI::line( sprintf( _n( "%d comment moved to Spam.", "%d comments moved to Spam.", $total_counts['spam'], 'akismet' ), number_format( $total_counts['spam'] ) ) );
87 if ( $total_counts['error'] ) {
88 WP_CLI::line( sprintf( _n( "%d comment could not be checked.", "%d comments could not be checked.", $total_counts['error'], 'akismet' ), number_format( $total_counts['error'] ) ) );