function ct_activation() { wp_schedule_event(time(), 'hourly', 'ct_hourly_event_hook'); //wp_schedule_event(time(), 'hourly', 'ct_send_sfw_log' ); wp_schedule_event(time(), 'daily', 'cleantalk_update_sfw'); cleantalk_update_sfw(); add_option('ct_plugin_do_activation_redirect', true); }
/** * After options update * @return array */ function ct_update_option($option_name) { global $show_ct_notice_online, $ct_notice_online_label, $ct_notice_trial_label, $trial_notice_showtime, $ct_options, $ct_data, $ct_server_timeout; $ct_options = ct_get_options(true); $ct_data = ct_get_data(true); if ($option_name !== 'cleantalk_settings') { return; } $api_key = $ct_options['apikey']; if (isset($_POST['cleantalk_settings']['apikey'])) { $api_key = trim($_POST['cleantalk_settings']['apikey']); $ct_options['apikey'] = $api_key; } if (@isset($_POST['cleantalk_settings']['spam_firewall']) && $_POST['cleantalk_settings']['spam_firewall'] == 1) { cleantalk_update_sfw(); } if (!ct_valid_key($api_key)) { return; } /*$ct_base_call_result = ct_base_call(array( 'message' => 'CleanTalk setup test', 'example' => null, 'sender_email' => '*****@*****.**', 'sender_nickname' => 'CleanTalk', 'post_info' => '', 'checkjs' => 1 ));*/ $key_valid = true; $app_server_error = false; $ct_data['testing_failed'] = 0; if (!function_exists('sendRawRequest')) { require_once 'cleantalk.class.php'; } $request = array(); $request['method_name'] = 'notice_validate_key'; $request['auth_key'] = $api_key; $url = 'https://api.cleantalk.org'; if (!function_exists('sendRawRequest')) { require_once 'cleantalk.class.php'; } $result = sendRawRequest($url, $request); if ($result) { $result = json_decode($result, true); if (isset($result['valid']) && $result['valid'] == 0) { $key_valid = false; $ct_data['testing_failed'] = 1; } } if (!$result || !isset($result['valid'])) { $app_server_error = true; $ct_data['testing_failed'] = 1; } update_option('cleantalk_data', $ct_data); if ($key_valid) { // Removes cookie for server errors if ($app_server_error) { setcookie($ct_notice_online_label, '', 1, '/'); // time 1 is exactly in past even clients time() is wrong unset($_COOKIE[$ct_notice_online_label]); } else { setcookie($ct_notice_online_label, (string) time(), strtotime("+14 days"), '/'); } setcookie($ct_notice_trial_label, '0', strtotime("+{$trial_notice_showtime} minutes"), '/'); } else { setcookie($ct_notice_online_label, 'BAD_KEY', 0, '/'); } }