public function do_inactive_account_filtering() { add_filter('wp_mail_content_type', 'wskl_email_content_type', 10, 0); add_filter('wp_mail_from', 'wskl_email_from'); add_filter('wp_mail_from_name', 'wskl_email_from_name'); $post_alert = wskl_get_option('inactive-accounts_post_alert'); $post_deactivation = wskl_get_option('inactive-accounts_post_deactivation'); $active_span = wskl_get_option('inactive-accounts_active_span'); $alert = wskl_get_option('inactive-accounts_alert'); $target_role = wskl_get_option('inactive-accounts_target_role'); if ($post_alert < 1 || $post_deactivation < 1 || !$active_span || !$alert || !$target_role) { $message = __METHOD__ . ": Values are net properly set.\n"; $message .= " post_alert={$post_alert},\n"; $message .= " post_deactivation={$post_deactivation},\n"; $message .= " active_span={$active_span},\n"; $message .= " alert={$alert}\n"; $message .= " target_role={$target_role}"; error_log($message); return; } $now = time(); $alert_ts = $now - $active_span * DAY_IN_SECONDS + $alert * DAY_IN_SECONDS; $deactivate_ts = $now - $active_span * DAY_IN_SECONDS; $to_notified = wskl_get_alert_staged_users($deactivate_ts, $alert_ts, $target_role); $to_disabled = wskl_get_deactivation_staged_users($deactivate_ts, $target_role); $message = "Before inactive-accounts email notification."; $message .= count($to_notified) . " users will be alerted. "; $message .= count($to_disabled) . " users will be disabled. "; $message .= "Total " . (count($to_notified) + count($to_disabled)) . " users."; error_log($message); $start = microtime(TRUE); $this->process_alert($to_notified); $finish = microtime(TRUE); $notification_spent = $finish - $start; error_log(sprintf('Alert job finished. Execution time: %.04fms', $notification_spent * 1000)); $start = microtime(TRUE); $this->process_deactivation($to_disabled, $target_role); $finish = microtime(TRUE); $deactivation_spent = $finish - $start; error_log(sprintf('Deactivate job finished. Execution time: %.04fms', $deactivation_spent * 1000)); remove_filter('wp_mail_content_type', 'wskl_email_content_type'); remove_filter('wp_mail_from', 'wskl_email_from'); remove_filter('wp_mail_from_name', 'wskl_email_from_name'); // save recent jobs, up to 7. $recent_jobs = wskl_get_option('inactive-accounts_recent_jobs', array()); $recent_jobs[$this->cron_job_id] = array('timestamp' => $this->cron_job_id, 'total_notified' => count($to_notified), 'total_disabled' => count($to_disabled), 'notification_spent' => $notification_spent, 'deactivation_spent' => $deactivation_spent); $cnt = count($recent_jobs); if ($cnt > 7) { $recent_jobs = array_slice($recent_jobs, -7, 7); } ksort($recent_jobs); wskl_update_option('inactive-accounts_recent_jobs', $recent_jobs); }
/** * @used-by WSKL_Config_Editor::handle_form_submit() */ private static function update_wp_config_filter() { if (!wp_verify_nonce($_POST['wskl-config-filter-nonce'], 'wskl-config-filter-nonce')) { wp_die('Nonce verification error!'); } $values = array_map(function ($item) { return sanitize_text_field(trim($item)); }, explode("\n", wskl_POST('wskl-config-filter'))); wskl_update_option('config_editor_keys_to_filter', $values); self::$keys_to_filter = array_merge(self::$fixed_filtered_keys, $values); add_action('admin_notices', function () { echo '<div class="updated settings-error notice is-dismissible"><p><strong>' . __('Settings saved.') . '</strong></p></div>'; }); }