PluginProbe ʕ •ᴥ•ʔ
Akismet Anti-spam: Spam Protection / 4.2.5
Akismet Anti-spam: Spam Protection v4.2.5
5.7 3.0.4 3.0.5 3.1 3.1.1 3.1.10 3.1.11 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2 3.3 3.3.1 3.3.2 3.3.3 3.3.4 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 5.0 5.0.1 5.0.2 5.1 5.2 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.3.7 5.4 5.5 5.6 trunk 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.4.0 2.4.1 2.5.0 2.5.1 2.5.10 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 3.0.0 3.0.0-RC1 3.0.1 3.0.2 3.0.3
akismet / class.akismet-cli.php
akismet Last commit date
_inc 4 years ago views 3 years ago .htaccess 4 years ago LICENSE.txt 10 years ago akismet.php 3 years ago changelog.txt 3 years ago class.akismet-admin.php 3 years ago class.akismet-cli.php 7 years ago class.akismet-rest-api.php 7 years ago class.akismet-widget.php 4 years ago class.akismet.php 3 years ago index.php 12 years ago readme.txt 3 years ago wrapper.php 7 years ago
class.akismet-cli.php
185 lines
1 <?php
2
3 WP_CLI::add_command( 'akismet', 'Akismet_CLI' );
4
5 /**
6 * Filter spam comments.
7 */
8 class Akismet_CLI extends WP_CLI_Command {
9 /**
10 * Checks one or more comments against the Akismet API.
11 *
12 * ## OPTIONS
13 * <comment_id>...
14 * : The ID(s) of the comment(s) to check.
15 *
16 * [--noaction]
17 * : Don't change the status of the comment. Just report what Akismet thinks it is.
18 *
19 * ## EXAMPLES
20 *
21 * wp akismet check 12345
22 *
23 * @alias comment-check
24 */
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' );
30 }
31 else {
32 $api_response = Akismet::recheck_comment( $comment_id, 'wp-cli' );
33 }
34
35 if ( 'true' === $api_response ) {
36 WP_CLI::line( sprintf( __( "Comment #%d is spam.", 'akismet' ), $comment_id ) );
37 }
38 else if ( 'false' === $api_response ) {
39 WP_CLI::line( sprintf( __( "Comment #%d is not spam.", 'akismet' ), $comment_id ) );
40 }
41 else {
42 if ( false === $api_response ) {
43 WP_CLI::error( __( "Failed to connect to Akismet.", 'akismet' ) );
44 }
45 else if ( is_wp_error( $api_response ) ) {
46 WP_CLI::warning( sprintf( __( "Comment #%d could not be checked.", 'akismet' ), $comment_id ) );
47 }
48 }
49 }
50 }
51
52 /**
53 * Recheck all comments in the Pending queue.
54 *
55 * ## EXAMPLES
56 *
57 * wp akismet recheck_queue
58 *
59 * @alias recheck-queue
60 */
61 public function recheck_queue() {
62 $batch_size = 100;
63 $start = 0;
64
65 $total_counts = array();
66
67 do {
68 $result_counts = Akismet_Admin::recheck_queue_portion( $start, $batch_size );
69
70 if ( $result_counts['processed'] > 0 ) {
71 foreach ( $result_counts as $key => $count ) {
72 if ( ! isset( $total_counts[ $key ] ) ) {
73 $total_counts[ $key ] = $count;
74 }
75 else {
76 $total_counts[ $key ] += $count;
77 }
78 }
79 $start += $batch_size;
80 $start -= $result_counts['spam']; // These comments will have been removed from the queue.
81 }
82 } while ( $result_counts['processed'] > 0 );
83
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'] ) ) );
86
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'] ) ) );
89 }
90 }
91
92 /**
93 * Fetches stats from the Akismet API.
94 *
95 * ## OPTIONS
96 *
97 * [<interval>]
98 * : The time period for which to retrieve stats.
99 * ---
100 * default: all
101 * options:
102 * - days
103 * - months
104 * - all
105 * ---
106 *
107 * [--format=<format>]
108 * : Allows overriding the output of the command when listing connections.
109 * ---
110 * default: table
111 * options:
112 * - table
113 * - json
114 * - csv
115 * - yaml
116 * - count
117 * ---
118 *
119 * [--summary]
120 * : When set, will display a summary of the stats.
121 *
122 * ## EXAMPLES
123 *
124 * wp akismet stats
125 * wp akismet stats all
126 * wp akismet stats days
127 * wp akismet stats months
128 * wp akismet stats all --summary
129 */
130 public function stats( $args, $assoc_args ) {
131 $api_key = Akismet::get_api_key();
132
133 if ( empty( $api_key ) ) {
134 WP_CLI::error( __( 'API key must be set to fetch stats.', 'akismet' ) );
135 }
136
137 switch ( $args[0] ) {
138 case 'days':
139 $interval = '60-days';
140 break;
141 case 'months':
142 $interval = '6-months';
143 break;
144 default:
145 $interval = 'all';
146 break;
147 }
148
149 $response = Akismet::http_post(
150 Akismet::build_query( array(
151 'blog' => get_option( 'home' ),
152 'key' => $api_key,
153 'from' => $interval,
154 ) ),
155 'get-stats'
156 );
157
158 if ( empty( $response[1] ) ) {
159 WP_CLI::error( __( 'Currently unable to fetch stats. Please try again.', 'akismet' ) );
160 }
161
162 $response_body = json_decode( $response[1], true );
163
164 if ( is_null( $response_body ) ) {
165 WP_CLI::error( __( 'Stats response could not be decoded.', 'akismet' ) );
166 }
167
168 if ( isset( $assoc_args['summary'] ) ) {
169 $keys = array(
170 'spam',
171 'ham',
172 'missed_spam',
173 'false_positives',
174 'accuracy',
175 'time_saved',
176 );
177
178 WP_CLI\Utils\format_items( $assoc_args['format'], array( $response_body ), $keys );
179 }
180 else {
181 $stats = $response_body['breakdown'];
182 WP_CLI\Utils\format_items( $assoc_args['format'], $stats, array_keys( end( $stats ) ) );
183 }
184 }
185 }