I’m trying to build a plugin to manage a custom table in WordPress. In this plugin I’m gonna write 3 functions. First one to fetch data from database as you can see in the screenshot below. The second function is to update record status. And the last function is to delete a record.
My problem is I don’t know how to link the function to the links in Action column. WordPress doesn’t allow me or I don’t know how to send a query to to delete or update records.
I want if I click on update, status of the record I click choose will be changed then reload the page. And if I click on delete then reload the page, it will delete that record. I can write the functions but no luck to send ID query to it.
Please help. Thank you.
<?php
/*
Plugin Name: Manage Custom Table
Plugin URI: http://_adddress.com
Description: Testing Plugin
Author: XXXXXXXXXX
Version: 1.0
*/
require_once('functions/functions.php');
add_action('admin_menu','ManageCustomTable_admin_actions');
function ManageCustomTable_admin_actions() {
add_options_page('Manage Custom Table','Manage Custom Table','manage_options',__FILE__,'ManageCustomTable_admin');
}
function ManageCustomTable_admin(){
global $wpdb;
$data = $wpdb->get_results ("
SELECT
id,
school_id,
added_date,
campus_status
FROM
table_campus
");
?>
<style>.notice-warning {display:none;}</style>
<table class="widefat" style="margin:20px auto; width:97%;">
<thead>
<tr>
<th>ID</th>
<th>School ID</th>
<th>Added Date</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID</th>
<th>School ID</th>
<th>Added Date</th>
<th>Status</th>
<th>Action</th>
</tr>
</tfoot>
<tbody>
<?php
foreach ($data as $data) {
echo '<tr>';
echo '<td>'. $data->id.'</td>';
echo '<td>'. $data->school_id.'</td>';
echo '<td>'. $data->added_date.'</td>';
echo '<td>'. $data->campus_status.'</td>';
echo '<td>';
?>
<a href=#> Update </a>
<a href=#> Delete </a>
<?php
echo '</td></tr>';
}
?>
</tbody>
</table>
<?php
}
?>
Just create a php file and put your form inside that file.Then inside your plugin main php file include the file you have created.
say you create a delete.php,update.php
Then inside your php main plugin file
your anchor tag for delete and update should have an identifier. eg the
$data-id
delete.php
update.php
check whether your identifier isset
Hope that helps.