PluginProbe ʕ •ᴥ•ʔ
Akismet Anti-spam: Spam Protection / 5.3.7
Akismet Anti-spam: Spam Protection v5.3.7
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 1 year ago views 1 year ago .htaccess 1 year ago LICENSE.txt 10 years ago akismet.php 1 year ago changelog.txt 2 years ago class.akismet-admin.php 1 year ago class.akismet-cli.php 1 year ago class.akismet-rest-api.php 1 year ago class.akismet-widget.php 1 year ago class.akismet.php 1 year ago index.php 12 years ago readme.txt 1 year ago wrapper.php 1 year ago
class.akismet-cli.php
187 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 } else {
31 $api_response = Akismet::recheck_comment( $comment_id, 'wp-cli' );
32 }
33
34 if ( 'true' === $api_response ) {
35 /* translators: %d: Comment ID. */
36 WP_CLI::line( sprintf( __( 'Comment #%d is spam.', 'akismet' ), $comment_id ) );
37 } elseif ( 'false' === $api_response ) {
38 /* translators: %d: Comment ID. */
39 WP_CLI::line( sprintf( __( 'Comment #%d is not spam.', 'akismet' ), $comment_id ) );
40 } elseif ( false === $api_response ) {
41 /* translators: %d: Comment ID. */
42 WP_CLI::error( __( 'Failed to connect to Akismet.', 'akismet' ) );
43 } elseif ( is_wp_error( $api_response ) ) {
44 /* translators: %d: Comment ID. */
45 WP_CLI::warning( sprintf( __( 'Comment #%d could not be checked.', 'akismet' ), $comment_id ) );
46 }
47 }
48 }
49
50 /**
51 * Recheck all comments in the Pending queue.
52 *
53 * ## EXAMPLES
54 *
55 * wp akismet recheck_queue
56 *
57 * @alias recheck-queue
58 */
59 public function recheck_queue() {
60 $batch_size = 100;
61 $start = 0;
62
63 $total_counts = array();
64
65 do {
66 $result_counts = Akismet_Admin::recheck_queue_portion( $start, $batch_size );
67
68 if ( $result_counts['processed'] > 0 ) {
69 foreach ( $result_counts as $key => $count ) {
70 if ( ! isset( $total_counts[ $key ] ) ) {
71 $total_counts[ $key ] = $count;
72 } else {
73 $total_counts[ $key ] += $count;
74 }
75 }
76 $start += $batch_size;
77 $start -= $result_counts['spam']; // These comments will have been removed from the queue.
78 }
79 } while ( $result_counts['processed'] > 0 );
80
81 /* translators: %d: Number of comments. */
82 WP_CLI::line( sprintf( _n( 'Processed %d comment.', 'Processed %d comments.', $total_counts['processed'], 'akismet' ), number_format( $total_counts['processed'] ) ) );
83
84 /* translators: %d: Number of comments. */
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 /* translators: %d: Number of comments. */
89 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'] ) ) );
90 }
91 }
92
93 /**
94 * Fetches stats from the Akismet API.
95 *
96 * ## OPTIONS
97 *
98 * [<interval>]
99 * : The time period for which to retrieve stats.
100 * ---
101 * default: all
102 * options:
103 * - days
104 * - months
105 * - all
106 * ---
107 *
108 * [--format=<format>]
109 * : Allows overriding the output of the command when listing connections.
110 * ---
111 * default: table
112 * options:
113 * - table
114 * - json
115 * - csv
116 * - yaml
117 * - count
118 * ---
119 *
120 * [--summary]
121 * : When set, will display a summary of the stats.
122 *
123 * ## EXAMPLES
124 *
125 * wp akismet stats
126 * wp akismet stats all
127 * wp akismet stats days
128 * wp akismet stats months
129 * wp akismet stats all --summary
130 */
131 public function stats( $args, $assoc_args ) {
132 $api_key = Akismet::get_api_key();
133
134 if ( empty( $api_key ) ) {
135 WP_CLI::error( __( 'API key must be set to fetch stats.', 'akismet' ) );
136 }
137
138 switch ( $args[0] ) {
139 case 'days':
140 $interval = '60-days';
141 break;
142 case 'months':
143 $interval = '6-months';
144 break;
145 default:
146 $interval = 'all';
147 break;
148 }
149
150 $request_args = array(
151 'blog' => get_option( 'home' ),
152 'key' => $api_key,
153 'from' => $interval,
154 );
155
156 $request_args = apply_filters( 'akismet_request_args', $request_args, 'get-stats' );
157
158 $response = Akismet::http_post( Akismet::build_query( $request_args ), 'get-stats' );
159
160 if ( empty( $response[1] ) ) {
161 WP_CLI::error( __( 'Currently unable to fetch stats. Please try again.', 'akismet' ) );
162 }
163
164 $response_body = json_decode( $response[1], true );
165
166 if ( is_null( $response_body ) ) {
167 WP_CLI::error( __( 'Stats response could not be decoded.', 'akismet' ) );
168 }
169
170 if ( isset( $assoc_args['summary'] ) ) {
171 $keys = array(
172 'spam',
173 'ham',
174 'missed_spam',
175 'false_positives',
176 'accuracy',
177 'time_saved',
178 );
179
180 WP_CLI\Utils\format_items( $assoc_args['format'], array( $response_body ), $keys );
181 } else {
182 $stats = $response_body['breakdown'];
183 WP_CLI\Utils\format_items( $assoc_args['format'], $stats, array_keys( end( $stats ) ) );
184 }
185 }
186 }
187