0

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!");
    }
}
4
  • there are a few examples here if you search for add_rewrite_endpoint, like this one.
    – Milo
    Mar 1, 2014 at 3:28
  • Well, I am trying to delete specific messages, so the message ID is what's being sent. I don't see how this would work. Mar 1, 2014 at 3:49
  • Use the AJAX API or use a page (front or backend) that is registered such that WordPress knows about it.
    – s_ha_dum
    Mar 1, 2014 at 3:52
  • I managed to get it. I ended up using the AJAX API. I didn't realize how simple that approach is actually. Thanks for all of your help! Mar 1, 2014 at 5:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.