I am trying to develop a module in my WordPress plugin that will delete an entry from the database. The only issue is related to the trigger action. I've tried to send my users directly to the page using plugins_url('path/to/page.php?del_message=53
. My thoughts were to send the users to my page and use a basic $_GET
variable to retrieve the message ID. Unfortunately I can do that, but it will not load the WP header or any other functions.
What is the proper way to send a variable and retrieve a value? This is my current code on the page I attempted to send my users.
global $wpdb;
$table_name = $wpdb->prefix . "authordiscuss";
if(isset($_GET['del_message'])){
// CHECK IF CURRENT USER IS AUTHOR
echo 'Checking...<br />';
$messageid = $_GET['del_message'];
$authorid = $wpdb->query("SELECT userid FROM $table_name WHERE id=$messageid");
if(get_current_user_id() == $authorid){
// Delete message
echo $authorid . ' ' . $messageid;
$wpdb->query("DELETE FROM $table_name WHERE id=$messageid");
}else{
echo 'DIE!';
wp_die("You are not the message's author!");
}
}
add_rewrite_endpoint
, like this one.