Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/akismet
File: class.akismet-cli.php
<?php
[0] Fix | Delete
[1] Fix | Delete
WP_CLI::add_command( 'akismet', 'Akismet_CLI' );
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Filter spam comments.
[5] Fix | Delete
*/
[6] Fix | Delete
class Akismet_CLI extends WP_CLI_Command {
[7] Fix | Delete
/**
[8] Fix | Delete
* Checks one or more comments against the Akismet API.
[9] Fix | Delete
*
[10] Fix | Delete
* ## OPTIONS
[11] Fix | Delete
* <comment_id>...
[12] Fix | Delete
* : The ID(s) of the comment(s) to check.
[13] Fix | Delete
*
[14] Fix | Delete
* [--noaction]
[15] Fix | Delete
* : Don't change the status of the comment. Just report what Akismet thinks it is.
[16] Fix | Delete
*
[17] Fix | Delete
* ## EXAMPLES
[18] Fix | Delete
*
[19] Fix | Delete
* wp akismet check 12345
[20] Fix | Delete
*
[21] Fix | Delete
* @alias comment-check
[22] Fix | Delete
*/
[23] Fix | Delete
public function check( $args, $assoc_args ) {
[24] Fix | Delete
foreach ( $args as $comment_id ) {
[25] Fix | Delete
if ( isset( $assoc_args['noaction'] ) ) {
[26] Fix | Delete
// Check the comment, but don't reclassify it.
[27] Fix | Delete
$api_response = Akismet::check_db_comment( $comment_id, 'wp-cli' );
[28] Fix | Delete
}
[29] Fix | Delete
else {
[30] Fix | Delete
$api_response = Akismet::recheck_comment( $comment_id, 'wp-cli' );
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
if ( 'true' === $api_response ) {
[34] Fix | Delete
WP_CLI::line( sprintf( __( "Comment #%d is spam.", 'akismet' ), $comment_id ) );
[35] Fix | Delete
}
[36] Fix | Delete
else if ( 'false' === $api_response ) {
[37] Fix | Delete
WP_CLI::line( sprintf( __( "Comment #%d is not spam.", 'akismet' ), $comment_id ) );
[38] Fix | Delete
}
[39] Fix | Delete
else {
[40] Fix | Delete
if ( false === $api_response ) {
[41] Fix | Delete
WP_CLI::error( __( "Failed to connect to Akismet.", 'akismet' ) );
[42] Fix | Delete
}
[43] Fix | Delete
else if ( is_wp_error( $api_response ) ) {
[44] Fix | Delete
WP_CLI::warning( sprintf( __( "Comment #%d could not be checked.", 'akismet' ), $comment_id ) );
[45] Fix | Delete
}
[46] Fix | Delete
}
[47] Fix | Delete
}
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Recheck all comments in the Pending queue.
[52] Fix | Delete
*
[53] Fix | Delete
* ## EXAMPLES
[54] Fix | Delete
*
[55] Fix | Delete
* wp akismet recheck_queue
[56] Fix | Delete
*
[57] Fix | Delete
* @alias recheck-queue
[58] Fix | Delete
*/
[59] Fix | Delete
public function recheck_queue() {
[60] Fix | Delete
$batch_size = 100;
[61] Fix | Delete
$start = 0;
[62] Fix | Delete
[63] Fix | Delete
$total_counts = array();
[64] Fix | Delete
[65] Fix | Delete
do {
[66] Fix | Delete
$result_counts = Akismet_Admin::recheck_queue_portion( $start, $batch_size );
[67] Fix | Delete
[68] Fix | Delete
if ( $result_counts['processed'] > 0 ) {
[69] Fix | Delete
foreach ( $result_counts as $key => $count ) {
[70] Fix | Delete
if ( ! isset( $total_counts[ $key ] ) ) {
[71] Fix | Delete
$total_counts[ $key ] = $count;
[72] Fix | Delete
}
[73] Fix | Delete
else {
[74] Fix | Delete
$total_counts[ $key ] += $count;
[75] Fix | Delete
}
[76] Fix | Delete
}
[77] Fix | Delete
$start += $batch_size;
[78] Fix | Delete
$start -= $result_counts['spam']; // These comments will have been removed from the queue.
[79] Fix | Delete
}
[80] Fix | Delete
} while ( $result_counts['processed'] > 0 );
[81] Fix | Delete
[82] Fix | Delete
WP_CLI::line( sprintf( _n( "Processed %d comment.", "Processed %d comments.", $total_counts['processed'], 'akismet' ), number_format( $total_counts['processed'] ) ) );
[83] Fix | Delete
WP_CLI::line( sprintf( _n( "%d comment moved to Spam.", "%d comments moved to Spam.", $total_counts['spam'], 'akismet' ), number_format( $total_counts['spam'] ) ) );
[84] Fix | Delete
[85] Fix | Delete
if ( $total_counts['error'] ) {
[86] Fix | Delete
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'] ) ) );
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Fetches stats from the Akismet API.
[92] Fix | Delete
*
[93] Fix | Delete
* ## OPTIONS
[94] Fix | Delete
*
[95] Fix | Delete
* [<interval>]
[96] Fix | Delete
* : The time period for which to retrieve stats.
[97] Fix | Delete
* ---
[98] Fix | Delete
* default: all
[99] Fix | Delete
* options:
[100] Fix | Delete
* - days
[101] Fix | Delete
* - months
[102] Fix | Delete
* - all
[103] Fix | Delete
* ---
[104] Fix | Delete
*
[105] Fix | Delete
* [--format=<format>]
[106] Fix | Delete
* : Allows overriding the output of the command when listing connections.
[107] Fix | Delete
* ---
[108] Fix | Delete
* default: table
[109] Fix | Delete
* options:
[110] Fix | Delete
* - table
[111] Fix | Delete
* - json
[112] Fix | Delete
* - csv
[113] Fix | Delete
* - yaml
[114] Fix | Delete
* - count
[115] Fix | Delete
* ---
[116] Fix | Delete
*
[117] Fix | Delete
* [--summary]
[118] Fix | Delete
* : When set, will display a summary of the stats.
[119] Fix | Delete
*
[120] Fix | Delete
* ## EXAMPLES
[121] Fix | Delete
*
[122] Fix | Delete
* wp akismet stats
[123] Fix | Delete
* wp akismet stats all
[124] Fix | Delete
* wp akismet stats days
[125] Fix | Delete
* wp akismet stats months
[126] Fix | Delete
* wp akismet stats all --summary
[127] Fix | Delete
*/
[128] Fix | Delete
public function stats( $args, $assoc_args ) {
[129] Fix | Delete
$api_key = Akismet::get_api_key();
[130] Fix | Delete
[131] Fix | Delete
if ( empty( $api_key ) ) {
[132] Fix | Delete
WP_CLI::error( __( 'API key must be set to fetch stats.', 'akismet' ) );
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
switch ( $args[0] ) {
[136] Fix | Delete
case 'days':
[137] Fix | Delete
$interval = '60-days';
[138] Fix | Delete
break;
[139] Fix | Delete
case 'months':
[140] Fix | Delete
$interval = '6-months';
[141] Fix | Delete
break;
[142] Fix | Delete
default:
[143] Fix | Delete
$interval = 'all';
[144] Fix | Delete
break;
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
$response = Akismet::http_post(
[148] Fix | Delete
Akismet::build_query( array(
[149] Fix | Delete
'blog' => get_option( 'home' ),
[150] Fix | Delete
'key' => $api_key,
[151] Fix | Delete
'from' => $interval,
[152] Fix | Delete
) ),
[153] Fix | Delete
'get-stats'
[154] Fix | Delete
);
[155] Fix | Delete
[156] Fix | Delete
if ( empty( $response[1] ) ) {
[157] Fix | Delete
WP_CLI::error( __( 'Currently unable to fetch stats. Please try again.', 'akismet' ) );
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
$response_body = json_decode( $response[1], true );
[161] Fix | Delete
[162] Fix | Delete
if ( is_null( $response_body ) ) {
[163] Fix | Delete
WP_CLI::error( __( 'Stats response could not be decoded.', 'akismet' ) );
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
if ( isset( $assoc_args['summary'] ) ) {
[167] Fix | Delete
$keys = array(
[168] Fix | Delete
'spam',
[169] Fix | Delete
'ham',
[170] Fix | Delete
'missed_spam',
[171] Fix | Delete
'false_positives',
[172] Fix | Delete
'accuracy',
[173] Fix | Delete
'time_saved',
[174] Fix | Delete
);
[175] Fix | Delete
[176] Fix | Delete
WP_CLI\Utils\format_items( $assoc_args['format'], array( $response_body ), $keys );
[177] Fix | Delete
}
[178] Fix | Delete
else {
[179] Fix | Delete
$stats = $response_body['breakdown'];
[180] Fix | Delete
WP_CLI\Utils\format_items( $assoc_args['format'], $stats, array_keys( end( $stats ) ) );
[181] Fix | Delete
}
[182] Fix | Delete
}
[183] Fix | Delete
}
[184] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function