Edit File by line
/home/barbar84/www/wp-conte.../plugins/akismet_...
File: class.akismet-admin.php
<?php
[0] Fix | Delete
[1] Fix | Delete
class Akismet_Admin {
[2] Fix | Delete
const NONCE = 'akismet-update-key';
[3] Fix | Delete
[4] Fix | Delete
private static $initiated = false;
[5] Fix | Delete
private static $notices = array();
[6] Fix | Delete
private static $allowed = array(
[7] Fix | Delete
'a' => array(
[8] Fix | Delete
'href' => true,
[9] Fix | Delete
'title' => true,
[10] Fix | Delete
),
[11] Fix | Delete
'b' => array(),
[12] Fix | Delete
'code' => array(),
[13] Fix | Delete
'del' => array(
[14] Fix | Delete
'datetime' => true,
[15] Fix | Delete
),
[16] Fix | Delete
'em' => array(),
[17] Fix | Delete
'i' => array(),
[18] Fix | Delete
'q' => array(
[19] Fix | Delete
'cite' => true,
[20] Fix | Delete
),
[21] Fix | Delete
'strike' => array(),
[22] Fix | Delete
'strong' => array(),
[23] Fix | Delete
);
[24] Fix | Delete
[25] Fix | Delete
public static function init() {
[26] Fix | Delete
if ( ! self::$initiated ) {
[27] Fix | Delete
self::init_hooks();
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
if ( isset( $_POST['action'] ) && $_POST['action'] == 'enter-key' ) {
[31] Fix | Delete
self::enter_api_key();
[32] Fix | Delete
}
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
public static function init_hooks() {
[36] Fix | Delete
// The standalone stats page was removed in 3.0 for an all-in-one config and stats page.
[37] Fix | Delete
// Redirect any links that might have been bookmarked or in browser history.
[38] Fix | Delete
if ( isset( $_GET['page'] ) && 'akismet-stats-display' == $_GET['page'] ) {
[39] Fix | Delete
wp_safe_redirect( esc_url_raw( self::get_page_url( 'stats' ) ), 301 );
[40] Fix | Delete
die;
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
self::$initiated = true;
[44] Fix | Delete
[45] Fix | Delete
add_action( 'admin_init', array( 'Akismet_Admin', 'admin_init' ) );
[46] Fix | Delete
add_action( 'admin_menu', array( 'Akismet_Admin', 'admin_menu' ), 5 ); # Priority 5, so it's called before Jetpack's admin_menu.
[47] Fix | Delete
add_action( 'admin_notices', array( 'Akismet_Admin', 'display_notice' ) );
[48] Fix | Delete
add_action( 'admin_enqueue_scripts', array( 'Akismet_Admin', 'load_resources' ) );
[49] Fix | Delete
add_action( 'activity_box_end', array( 'Akismet_Admin', 'dashboard_stats' ) );
[50] Fix | Delete
add_action( 'rightnow_end', array( 'Akismet_Admin', 'rightnow_stats' ) );
[51] Fix | Delete
add_action( 'manage_comments_nav', array( 'Akismet_Admin', 'check_for_spam_button' ) );
[52] Fix | Delete
add_action( 'admin_action_akismet_recheck_queue', array( 'Akismet_Admin', 'recheck_queue' ) );
[53] Fix | Delete
add_action( 'wp_ajax_akismet_recheck_queue', array( 'Akismet_Admin', 'recheck_queue' ) );
[54] Fix | Delete
add_action( 'wp_ajax_comment_author_deurl', array( 'Akismet_Admin', 'remove_comment_author_url' ) );
[55] Fix | Delete
add_action( 'wp_ajax_comment_author_reurl', array( 'Akismet_Admin', 'add_comment_author_url' ) );
[56] Fix | Delete
add_action( 'jetpack_auto_activate_akismet', array( 'Akismet_Admin', 'connect_jetpack_user' ) );
[57] Fix | Delete
[58] Fix | Delete
add_filter( 'plugin_action_links', array( 'Akismet_Admin', 'plugin_action_links' ), 10, 2 );
[59] Fix | Delete
add_filter( 'comment_row_actions', array( 'Akismet_Admin', 'comment_row_action' ), 10, 2 );
[60] Fix | Delete
[61] Fix | Delete
add_filter( 'plugin_action_links_'.plugin_basename( plugin_dir_path( __FILE__ ) . 'akismet.php'), array( 'Akismet_Admin', 'admin_plugin_settings_link' ) );
[62] Fix | Delete
[63] Fix | Delete
add_filter( 'wxr_export_skip_commentmeta', array( 'Akismet_Admin', 'exclude_commentmeta_from_export' ), 10, 3 );
[64] Fix | Delete
[65] Fix | Delete
add_filter( 'all_plugins', array( 'Akismet_Admin', 'modify_plugin_description' ) );
[66] Fix | Delete
[67] Fix | Delete
// priority=1 because we need ours to run before core's comment anonymizer runs, and that's registered at priority=10
[68] Fix | Delete
add_filter( 'wp_privacy_personal_data_erasers', array( 'Akismet_Admin', 'register_personal_data_eraser' ), 1 );
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
public static function admin_init() {
[72] Fix | Delete
if ( get_option( 'Activated_Akismet' ) ) {
[73] Fix | Delete
delete_option( 'Activated_Akismet' );
[74] Fix | Delete
if ( ! headers_sent() ) {
[75] Fix | Delete
wp_redirect( add_query_arg( array( 'page' => 'akismet-key-config', 'view' => 'start' ), class_exists( 'Jetpack' ) ? admin_url( 'admin.php' ) : admin_url( 'options-general.php' ) ) );
[76] Fix | Delete
}
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
load_plugin_textdomain( 'akismet' );
[80] Fix | Delete
add_meta_box( 'akismet-status', __('Comment History', 'akismet'), array( 'Akismet_Admin', 'comment_status_meta_box' ), 'comment', 'normal' );
[81] Fix | Delete
[82] Fix | Delete
if ( function_exists( 'wp_add_privacy_policy_content' ) ) {
[83] Fix | Delete
wp_add_privacy_policy_content(
[84] Fix | Delete
__( 'Akismet', 'akismet' ),
[85] Fix | Delete
__( 'We collect information about visitors who comment on Sites that use our Akismet anti-spam service. The information we collect depends on how the User sets up Akismet for the Site, but typically includes the commenter\'s IP address, user agent, referrer, and Site URL (along with other information directly provided by the commenter such as their name, username, email address, and the comment itself).', 'akismet' )
[86] Fix | Delete
);
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
public static function admin_menu() {
[91] Fix | Delete
if ( class_exists( 'Jetpack' ) )
[92] Fix | Delete
add_action( 'jetpack_admin_menu', array( 'Akismet_Admin', 'load_menu' ) );
[93] Fix | Delete
else
[94] Fix | Delete
self::load_menu();
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
public static function admin_head() {
[98] Fix | Delete
if ( !current_user_can( 'manage_options' ) )
[99] Fix | Delete
return;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
public static function admin_plugin_settings_link( $links ) {
[103] Fix | Delete
$settings_link = '<a href="'.esc_url( self::get_page_url() ).'">'.__('Settings', 'akismet').'</a>';
[104] Fix | Delete
array_unshift( $links, $settings_link );
[105] Fix | Delete
return $links;
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
public static function load_menu() {
[109] Fix | Delete
if ( class_exists( 'Jetpack' ) ) {
[110] Fix | Delete
$hook = add_submenu_page( 'jetpack', __( 'Akismet Anti-Spam' , 'akismet'), __( 'Akismet Anti-Spam' , 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
[111] Fix | Delete
}
[112] Fix | Delete
else {
[113] Fix | Delete
$hook = add_options_page( __('Akismet Anti-Spam', 'akismet'), __('Akismet Anti-Spam', 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
if ( $hook ) {
[117] Fix | Delete
add_action( "load-$hook", array( 'Akismet_Admin', 'admin_help' ) );
[118] Fix | Delete
}
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
public static function load_resources() {
[122] Fix | Delete
global $hook_suffix;
[123] Fix | Delete
[124] Fix | Delete
if ( in_array( $hook_suffix, apply_filters( 'akismet_admin_page_hook_suffixes', array(
[125] Fix | Delete
'index.php', # dashboard
[126] Fix | Delete
'edit-comments.php',
[127] Fix | Delete
'comment.php',
[128] Fix | Delete
'post.php',
[129] Fix | Delete
'settings_page_akismet-key-config',
[130] Fix | Delete
'jetpack_page_akismet-key-config',
[131] Fix | Delete
'plugins.php',
[132] Fix | Delete
) ) ) ) {
[133] Fix | Delete
wp_register_style( 'akismet.css', plugin_dir_url( __FILE__ ) . '_inc/akismet.css', array(), AKISMET_VERSION );
[134] Fix | Delete
wp_enqueue_style( 'akismet.css');
[135] Fix | Delete
[136] Fix | Delete
wp_register_script( 'akismet.js', plugin_dir_url( __FILE__ ) . '_inc/akismet.js', array('jquery'), AKISMET_VERSION );
[137] Fix | Delete
wp_enqueue_script( 'akismet.js' );
[138] Fix | Delete
[139] Fix | Delete
$inline_js = array(
[140] Fix | Delete
'comment_author_url_nonce' => wp_create_nonce( 'comment_author_url_nonce' ),
[141] Fix | Delete
'strings' => array(
[142] Fix | Delete
'Remove this URL' => __( 'Remove this URL' , 'akismet'),
[143] Fix | Delete
'Removing...' => __( 'Removing...' , 'akismet'),
[144] Fix | Delete
'URL removed' => __( 'URL removed' , 'akismet'),
[145] Fix | Delete
'(undo)' => __( '(undo)' , 'akismet'),
[146] Fix | Delete
'Re-adding...' => __( 'Re-adding...' , 'akismet'),
[147] Fix | Delete
)
[148] Fix | Delete
);
[149] Fix | Delete
[150] Fix | Delete
if ( isset( $_GET['akismet_recheck'] ) && wp_verify_nonce( $_GET['akismet_recheck'], 'akismet_recheck' ) ) {
[151] Fix | Delete
$inline_js['start_recheck'] = true;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
if ( apply_filters( 'akismet_enable_mshots', true ) ) {
[155] Fix | Delete
$inline_js['enable_mshots'] = true;
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
wp_localize_script( 'akismet.js', 'WPAkismet', $inline_js );
[159] Fix | Delete
}
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
/**
[163] Fix | Delete
* Add help to the Akismet page
[164] Fix | Delete
*
[165] Fix | Delete
* @return false if not the Akismet page
[166] Fix | Delete
*/
[167] Fix | Delete
public static function admin_help() {
[168] Fix | Delete
$current_screen = get_current_screen();
[169] Fix | Delete
[170] Fix | Delete
// Screen Content
[171] Fix | Delete
if ( current_user_can( 'manage_options' ) ) {
[172] Fix | Delete
if ( !Akismet::get_api_key() || ( isset( $_GET['view'] ) && $_GET['view'] == 'start' ) ) {
[173] Fix | Delete
//setup page
[174] Fix | Delete
$current_screen->add_help_tab(
[175] Fix | Delete
array(
[176] Fix | Delete
'id' => 'overview',
[177] Fix | Delete
'title' => __( 'Overview' , 'akismet'),
[178] Fix | Delete
'content' =>
[179] Fix | Delete
'<p><strong>' . esc_html__( 'Akismet Setup' , 'akismet') . '</strong></p>' .
[180] Fix | Delete
'<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '</p>' .
[181] Fix | Delete
'<p>' . esc_html__( 'On this page, you are able to set up the Akismet plugin.' , 'akismet') . '</p>',
[182] Fix | Delete
)
[183] Fix | Delete
);
[184] Fix | Delete
[185] Fix | Delete
$current_screen->add_help_tab(
[186] Fix | Delete
array(
[187] Fix | Delete
'id' => 'setup-signup',
[188] Fix | Delete
'title' => __( 'New to Akismet' , 'akismet'),
[189] Fix | Delete
'content' =>
[190] Fix | Delete
'<p><strong>' . esc_html__( 'Akismet Setup' , 'akismet') . '</strong></p>' .
[191] Fix | Delete
'<p>' . esc_html__( 'You need to enter an API key to activate the Akismet service on your site.' , 'akismet') . '</p>' .
[192] Fix | Delete
'<p>' . sprintf( __( 'Sign up for an account on %s to get an API Key.' , 'akismet'), '<a href="https://akismet.com/plugin-signup/" target="_blank">Akismet.com</a>' ) . '</p>',
[193] Fix | Delete
)
[194] Fix | Delete
);
[195] Fix | Delete
[196] Fix | Delete
$current_screen->add_help_tab(
[197] Fix | Delete
array(
[198] Fix | Delete
'id' => 'setup-manual',
[199] Fix | Delete
'title' => __( 'Enter an API Key' , 'akismet'),
[200] Fix | Delete
'content' =>
[201] Fix | Delete
'<p><strong>' . esc_html__( 'Akismet Setup' , 'akismet') . '</strong></p>' .
[202] Fix | Delete
'<p>' . esc_html__( 'If you already have an API key' , 'akismet') . '</p>' .
[203] Fix | Delete
'<ol>' .
[204] Fix | Delete
'<li>' . esc_html__( 'Copy and paste the API key into the text field.' , 'akismet') . '</li>' .
[205] Fix | Delete
'<li>' . esc_html__( 'Click the Use this Key button.' , 'akismet') . '</li>' .
[206] Fix | Delete
'</ol>',
[207] Fix | Delete
)
[208] Fix | Delete
);
[209] Fix | Delete
}
[210] Fix | Delete
elseif ( isset( $_GET['view'] ) && $_GET['view'] == 'stats' ) {
[211] Fix | Delete
//stats page
[212] Fix | Delete
$current_screen->add_help_tab(
[213] Fix | Delete
array(
[214] Fix | Delete
'id' => 'overview',
[215] Fix | Delete
'title' => __( 'Overview' , 'akismet'),
[216] Fix | Delete
'content' =>
[217] Fix | Delete
'<p><strong>' . esc_html__( 'Akismet Stats' , 'akismet') . '</strong></p>' .
[218] Fix | Delete
'<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '</p>' .
[219] Fix | Delete
'<p>' . esc_html__( 'On this page, you are able to view stats on spam filtered on your site.' , 'akismet') . '</p>',
[220] Fix | Delete
)
[221] Fix | Delete
);
[222] Fix | Delete
}
[223] Fix | Delete
else {
[224] Fix | Delete
//configuration page
[225] Fix | Delete
$current_screen->add_help_tab(
[226] Fix | Delete
array(
[227] Fix | Delete
'id' => 'overview',
[228] Fix | Delete
'title' => __( 'Overview' , 'akismet'),
[229] Fix | Delete
'content' =>
[230] Fix | Delete
'<p><strong>' . esc_html__( 'Akismet Configuration' , 'akismet') . '</strong></p>' .
[231] Fix | Delete
'<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '</p>' .
[232] Fix | Delete
'<p>' . esc_html__( 'On this page, you are able to update your Akismet settings and view spam stats.' , 'akismet') . '</p>',
[233] Fix | Delete
)
[234] Fix | Delete
);
[235] Fix | Delete
[236] Fix | Delete
$current_screen->add_help_tab(
[237] Fix | Delete
array(
[238] Fix | Delete
'id' => 'settings',
[239] Fix | Delete
'title' => __( 'Settings' , 'akismet'),
[240] Fix | Delete
'content' =>
[241] Fix | Delete
'<p><strong>' . esc_html__( 'Akismet Configuration' , 'akismet') . '</strong></p>' .
[242] Fix | Delete
( Akismet::predefined_api_key() ? '' : '<p><strong>' . esc_html__( 'API Key' , 'akismet') . '</strong> - ' . esc_html__( 'Enter/remove an API key.' , 'akismet') . '</p>' ) .
[243] Fix | Delete
'<p><strong>' . esc_html__( 'Comments' , 'akismet') . '</strong> - ' . esc_html__( 'Show the number of approved comments beside each comment author in the comments list page.' , 'akismet') . '</p>' .
[244] Fix | Delete
'<p><strong>' . esc_html__( 'Strictness' , 'akismet') . '</strong> - ' . esc_html__( 'Choose to either discard the worst spam automatically or to always put all spam in spam folder.' , 'akismet') . '</p>',
[245] Fix | Delete
)
[246] Fix | Delete
);
[247] Fix | Delete
[248] Fix | Delete
if ( ! Akismet::predefined_api_key() ) {
[249] Fix | Delete
$current_screen->add_help_tab(
[250] Fix | Delete
array(
[251] Fix | Delete
'id' => 'account',
[252] Fix | Delete
'title' => __( 'Account' , 'akismet'),
[253] Fix | Delete
'content' =>
[254] Fix | Delete
'<p><strong>' . esc_html__( 'Akismet Configuration' , 'akismet') . '</strong></p>' .
[255] Fix | Delete
'<p><strong>' . esc_html__( 'Subscription Type' , 'akismet') . '</strong> - ' . esc_html__( 'The Akismet subscription plan' , 'akismet') . '</p>' .
[256] Fix | Delete
'<p><strong>' . esc_html__( 'Status' , 'akismet') . '</strong> - ' . esc_html__( 'The subscription status - active, cancelled or suspended' , 'akismet') . '</p>',
[257] Fix | Delete
)
[258] Fix | Delete
);
[259] Fix | Delete
}
[260] Fix | Delete
}
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
// Help Sidebar
[264] Fix | Delete
$current_screen->set_help_sidebar(
[265] Fix | Delete
'<p><strong>' . esc_html__( 'For more information:' , 'akismet') . '</strong></p>' .
[266] Fix | Delete
'<p><a href="https://akismet.com/faq/" target="_blank">' . esc_html__( 'Akismet FAQ' , 'akismet') . '</a></p>' .
[267] Fix | Delete
'<p><a href="https://akismet.com/support/" target="_blank">' . esc_html__( 'Akismet Support' , 'akismet') . '</a></p>'
[268] Fix | Delete
);
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
public static function enter_api_key() {
[272] Fix | Delete
if ( ! current_user_can( 'manage_options' ) ) {
[273] Fix | Delete
die( __( 'Cheatin&#8217; uh?', 'akismet' ) );
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
if ( !wp_verify_nonce( $_POST['_wpnonce'], self::NONCE ) )
[277] Fix | Delete
return false;
[278] Fix | Delete
[279] Fix | Delete
foreach( array( 'akismet_strictness', 'akismet_show_user_comments_approved' ) as $option ) {
[280] Fix | Delete
update_option( $option, isset( $_POST[$option] ) && (int) $_POST[$option] == 1 ? '1' : '0' );
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
if ( ! empty( $_POST['akismet_comment_form_privacy_notice'] ) ) {
[284] Fix | Delete
self::set_form_privacy_notice_option( $_POST['akismet_comment_form_privacy_notice'] );
[285] Fix | Delete
} else {
[286] Fix | Delete
self::set_form_privacy_notice_option( 'hide' );
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
if ( Akismet::predefined_api_key() ) {
[290] Fix | Delete
return false; //shouldn't have option to save key if already defined
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
$new_key = preg_replace( '/[^a-f0-9]/i', '', $_POST['key'] );
[294] Fix | Delete
$old_key = Akismet::get_api_key();
[295] Fix | Delete
[296] Fix | Delete
if ( empty( $new_key ) ) {
[297] Fix | Delete
if ( !empty( $old_key ) ) {
[298] Fix | Delete
delete_option( 'wordpress_api_key' );
[299] Fix | Delete
self::$notices[] = 'new-key-empty';
[300] Fix | Delete
}
[301] Fix | Delete
}
[302] Fix | Delete
elseif ( $new_key != $old_key ) {
[303] Fix | Delete
self::save_key( $new_key );
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
return true;
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
public static function save_key( $api_key ) {
[310] Fix | Delete
$key_status = Akismet::verify_key( $api_key );
[311] Fix | Delete
[312] Fix | Delete
if ( $key_status == 'valid' ) {
[313] Fix | Delete
$akismet_user = self::get_akismet_user( $api_key );
[314] Fix | Delete
[315] Fix | Delete
if ( $akismet_user ) {
[316] Fix | Delete
if ( in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub' ) ) )
[317] Fix | Delete
update_option( 'wordpress_api_key', $api_key );
[318] Fix | Delete
[319] Fix | Delete
if ( $akismet_user->status == 'active' )
[320] Fix | Delete
self::$notices['status'] = 'new-key-valid';
[321] Fix | Delete
elseif ( $akismet_user->status == 'notice' )
[322] Fix | Delete
self::$notices['status'] = $akismet_user;
[323] Fix | Delete
else
[324] Fix | Delete
self::$notices['status'] = $akismet_user->status;
[325] Fix | Delete
}
[326] Fix | Delete
else
[327] Fix | Delete
self::$notices['status'] = 'new-key-invalid';
[328] Fix | Delete
}
[329] Fix | Delete
elseif ( in_array( $key_status, array( 'invalid', 'failed' ) ) )
[330] Fix | Delete
self::$notices['status'] = 'new-key-'.$key_status;
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
public static function dashboard_stats() {
[334] Fix | Delete
if ( did_action( 'rightnow_end' ) ) {
[335] Fix | Delete
return; // We already displayed this info in the "Right Now" section
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
if ( !$count = get_option('akismet_spam_count') )
[339] Fix | Delete
return;
[340] Fix | Delete
[341] Fix | Delete
global $submenu;
[342] Fix | Delete
[343] Fix | Delete
echo '<h3>' . esc_html( _x( 'Spam', 'comments' , 'akismet') ) . '</h3>';
[344] Fix | Delete
[345] Fix | Delete
echo '<p>'.sprintf( _n(
[346] Fix | Delete
'<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comment</a>.',
[347] Fix | Delete
'<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.',
[348] Fix | Delete
$count
[349] Fix | Delete
, 'akismet'), 'https://akismet.com/wordpress/', esc_url( add_query_arg( array( 'page' => 'akismet-admin' ), admin_url( isset( $submenu['edit-comments.php'] ) ? 'edit-comments.php' : 'edit.php' ) ) ), number_format_i18n($count) ).'</p>';
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
// WP 2.5+
[353] Fix | Delete
public static function rightnow_stats() {
[354] Fix | Delete
if ( $count = get_option('akismet_spam_count') ) {
[355] Fix | Delete
$intro = sprintf( _n(
[356] Fix | Delete
'<a href="%1$s">Akismet</a> has protected your site from %2$s spam comment already. ',
[357] Fix | Delete
'<a href="%1$s">Akismet</a> has protected your site from %2$s spam comments already. ',
[358] Fix | Delete
$count
[359] Fix | Delete
, 'akismet'), 'https://akismet.com/wordpress/', number_format_i18n( $count ) );
[360] Fix | Delete
} else {
[361] Fix | Delete
$intro = sprintf( __('<a href="%s">Akismet</a> blocks spam from getting to your blog. ', 'akismet'), 'https://akismet.com/wordpress/' );
[362] Fix | Delete
}
[363] Fix | Delete
[364] Fix | Delete
$link = add_query_arg( array( 'comment_status' => 'spam' ), admin_url( 'edit-comments.php' ) );
[365] Fix | Delete
[366] Fix | Delete
if ( $queue_count = self::get_spam_count() ) {
[367] Fix | Delete
$queue_text = sprintf( _n(
[368] Fix | Delete
'There&#8217;s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
[369] Fix | Delete
'There are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
[370] Fix | Delete
$queue_count
[371] Fix | Delete
, 'akismet'), number_format_i18n( $queue_count ), esc_url( $link ) );
[372] Fix | Delete
} else {
[373] Fix | Delete
$queue_text = sprintf( __( "There&#8217;s nothing in your <a href='%s'>spam queue</a> at the moment." , 'akismet'), esc_url( $link ) );
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
$text = $intro . '<br />' . $queue_text;
[377] Fix | Delete
echo "<p class='akismet-right-now'>$text</p>\n";
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
public static function check_for_spam_button( $comment_status ) {
[381] Fix | Delete
// The "Check for Spam" button should only appear when the page might be showing
[382] Fix | Delete
// a comment with comment_approved=0, which means an un-trashed, un-spammed,
[383] Fix | Delete
// not-yet-moderated comment.
[384] Fix | Delete
if ( 'all' != $comment_status && 'moderated' != $comment_status ) {
[385] Fix | Delete
return;
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
$link = '';
[389] Fix | Delete
[390] Fix | Delete
$comments_count = wp_count_comments();
[391] Fix | Delete
[392] Fix | Delete
echo '</div>';
[393] Fix | Delete
echo '<div class="alignleft actions">';
[394] Fix | Delete
[395] Fix | Delete
$classes = array(
[396] Fix | Delete
'button-secondary',
[397] Fix | Delete
'checkforspam',
[398] Fix | Delete
'button-disabled' // Disable button until the page is loaded
[399] Fix | Delete
);
[400] Fix | Delete
[401] Fix | Delete
if ( $comments_count->moderated > 0 ) {
[402] Fix | Delete
$classes[] = 'enable-on-load';
[403] Fix | Delete
[404] Fix | Delete
if ( ! Akismet::get_api_key() ) {
[405] Fix | Delete
$link = add_query_arg( array( 'page' => 'akismet-key-config' ), class_exists( 'Jetpack' ) ? admin_url( 'admin.php' ) : admin_url( 'options-general.php' ) );
[406] Fix | Delete
$classes[] = 'ajax-disabled';
[407] Fix | Delete
}
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
echo '<a
[411] Fix | Delete
class="' . esc_attr( implode( ' ', $classes ) ) . '"' .
[412] Fix | Delete
( ! empty( $link ) ? ' href="' . esc_url( $link ) . '"' : '' ) .
[413] Fix | Delete
/* translators: The placeholder is for showing how much of the process has completed, as a percent. e.g., "Checking for Spam (40%)" */
[414] Fix | Delete
' data-progress-label="' . esc_attr( __( 'Checking for Spam (%1$s%)', 'akismet' ) ) . '"
[415] Fix | Delete
data-success-url="' . esc_attr( remove_query_arg( array( 'akismet_recheck', 'akismet_recheck_error' ), add_query_arg( array( 'akismet_recheck_complete' => 1, 'recheck_count' => urlencode( '__recheck_count__' ), 'spam_count' => urlencode( '__spam_count__' ) ) ) ) ) . '"
[416] Fix | Delete
data-failure-url="' . esc_attr( remove_query_arg( array( 'akismet_recheck', 'akismet_recheck_complete' ), add_query_arg( array( 'akismet_recheck_error' => 1 ) ) ) ) . '"
[417] Fix | Delete
data-pending-comment-count="' . esc_attr( $comments_count->moderated ) . '"
[418] Fix | Delete
data-nonce="' . esc_attr( wp_create_nonce( 'akismet_check_for_spam' ) ) . '"
[419] Fix | Delete
' . ( ! in_array( 'ajax-disabled', $classes ) ? 'onclick="return false;"' : '' ) . '
[420] Fix | Delete
>' . esc_html__('Check for Spam', 'akismet') . '</a>';
[421] Fix | Delete
echo '<span class="checkforspam-spinner"></span>';
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
public static function recheck_queue() {
[425] Fix | Delete
global $wpdb;
[426] Fix | Delete
[427] Fix | Delete
Akismet::fix_scheduled_recheck();
[428] Fix | Delete
[429] Fix | Delete
if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) ) {
[430] Fix | Delete
return;
[431] Fix | Delete
}
[432] Fix | Delete
[433] Fix | Delete
if ( ! wp_verify_nonce( $_POST['nonce'], 'akismet_check_for_spam' ) ) {
[434] Fix | Delete
wp_send_json( array(
[435] Fix | Delete
'error' => __( "You don't have permission to do that."),
[436] Fix | Delete
));
[437] Fix | Delete
return;
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
$result_counts = self::recheck_queue_portion( empty( $_POST['offset'] ) ? 0 : $_POST['offset'], empty( $_POST['limit'] ) ? 100 : $_POST['limit'] );
[441] Fix | Delete
[442] Fix | Delete
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
[443] Fix | Delete
wp_send_json( array(
[444] Fix | Delete
'counts' => $result_counts,
[445] Fix | Delete
));
[446] Fix | Delete
}
[447] Fix | Delete
else {
[448] Fix | Delete
$redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : admin_url( 'edit-comments.php' );
[449] Fix | Delete
wp_safe_redirect( $redirect_to );
[450] Fix | Delete
exit;
[451] Fix | Delete
}
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
public static function recheck_queue_portion( $start = 0, $limit = 100 ) {
[455] Fix | Delete
global $wpdb;
[456] Fix | Delete
[457] Fix | Delete
$paginate = '';
[458] Fix | Delete
[459] Fix | Delete
if ( $limit <= 0 ) {
[460] Fix | Delete
$limit = 100;
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
if ( $start < 0 ) {
[464] Fix | Delete
$start = 0;
[465] Fix | Delete
}
[466] Fix | Delete
[467] Fix | Delete
$moderation = $wpdb->get_col( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0' LIMIT %d OFFSET %d", $limit, $start ) );
[468] Fix | Delete
[469] Fix | Delete
$result_counts = array(
[470] Fix | Delete
'processed' => count( $moderation ),
[471] Fix | Delete
'spam' => 0,
[472] Fix | Delete
'ham' => 0,
[473] Fix | Delete
'error' => 0,
[474] Fix | Delete
);
[475] Fix | Delete
[476] Fix | Delete
foreach ( $moderation as $comment_id ) {
[477] Fix | Delete
$api_response = Akismet::recheck_comment( $comment_id, 'recheck_queue' );
[478] Fix | Delete
[479] Fix | Delete
if ( 'true' === $api_response ) {
[480] Fix | Delete
++$result_counts['spam'];
[481] Fix | Delete
}
[482] Fix | Delete
elseif ( 'false' === $api_response ) {
[483] Fix | Delete
++$result_counts['ham'];
[484] Fix | Delete
}
[485] Fix | Delete
else {
[486] Fix | Delete
++$result_counts['error'];
[487] Fix | Delete
}
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
return $result_counts;
[491] Fix | Delete
}
[492] Fix | Delete
[493] Fix | Delete
// Adds an 'x' link next to author URLs, clicking will remove the author URL and show an undo link
[494] Fix | Delete
public static function remove_comment_author_url() {
[495] Fix | Delete
if ( !empty( $_POST['id'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
[496] Fix | Delete
$comment_id = intval( $_POST['id'] );
[497] Fix | Delete
$comment = get_comment( $comment_id, ARRAY_A );
[498] Fix | Delete
if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function