public function process_actions() { if ('delete' === $this->current_action()) { // In our file that handles the request, verify the nonce. $nonce = esc_attr($_REQUEST['_wpnonce']); if (!wp_verify_nonce($nonce, self::$nonce)) { die('Nonce check failed.'); } Evaluate_Manager::delete_metric(absint($_GET['metric_id'])); wp_redirect(add_query_arg()); exit; } if (isset($_POST['action']) && $_POST['action'] == 'bulk-delete' || isset($_POST['action2']) && $_POST['action2'] == 'bulk-delete') { $delete_ids = esc_sql($_POST['bulk-delete']); // loop over the array of record IDs and delete them foreach ($delete_ids as $metric_id) { Evaluate_Manager::delete_metric($metric_id); } wp_redirect(add_query_arg()); exit; } }
return; } global $wpdb; // TODO: Verify nonce. $metric_type = Evaluate_Metrics::get_metric_types()[$_POST['type']]; $options = $metric_type->filter_options($_POST['options']); $data = array('name' => sanitize_text_field($_POST['name']), 'type' => sanitize_text_field($_POST['type']), 'options' => serialize($options)); if (empty($_POST['metric_id'])) { $data['created'] = current_time('mysql', 1); $wpdb->insert(Evaluate::$metric_table, $data); $metric_id = $wpdb->insert_id; } else { $wpdb->update(Evaluate::$metric_table, $data, array('metric_id' => $_POST['metric_id'])); $metric_id = $_POST['metric_id']; } wp_redirect(add_query_arg('metric_id', $metric_id)); exit; } public static function delete_metric($metric_id) { global $wpdb; $wpdb->delete(Evaluate::$metric_table, array('metric_id' => $metric_id), array('%d')); } public static function get_metrics_count() { global $wpdb; return $wpdb->get_var("SELECT COUNT(*) FROM " . Evaluate::$metric_table); } } Evaluate_Manager::init();