/** * Handle actions for both individual items and bulk update * * @since 1.0 */ public function process_actions() { global $wc_points_rewards; // get the current action (if any) $action = $this->current_action(); // get the set of users to operate on $user_ids = isset($_REQUEST['user_id']) ? array_map('absint', (array) $_REQUEST['user_id']) : array(); // no action, or invalid action if (false === $action || empty($user_ids) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'wc_points_rewards_update') && !wp_verify_nonce($_REQUEST['_wpnonce'], 'bulk-points')) { return; } $success_count = $error_count = 0; // process the users foreach ($user_ids as $user_id) { // perform the action switch ($action) { case 'update': if (WC_Points_Rewards_Manager::set_points_balance($user_id, $_REQUEST['points_balance'][$user_id], 'admin-adjustment')) { $success_count++; } else { $error_count++; } break; } } // build the result message(s) switch ($action) { case 'update': if ($success_count > 0) { $wc_points_rewards->admin_message_handler->add_message(sprintf(_n('%d customer updated.', '%s customers updated.', $success_count, 'wc_points_rewards'), $success_count)); } if ($error_count > 0) { $wc_points_rewards->admin_message_handler->add_message(sprintf(_n('%d customer could not be updated.', '%s customers could not be updated.', $error_count, 'wc_points_rewards'), $error_count)); } break; } }