Admin: Custom Query Returning Permissions Error

I think the problem is that by just appending ?deleteUser=XX you get an ‘illegal’ url, for example:

http://localhost/wordpress/wp-admin/edit.php?post_type=type&page=mypage?deleteUser=xxx

Instead, use WordPress’ add_query_arg:

    $url = $_SERVER['REQUEST_URI'];
    $url = add_query_arg('test','val',$url);

which gives:

http://localhost/wordpress/wp-admin/edit.php?post_type=type&page=mypage&deleteUser=xxx

Personally, I wouldn’t use $_SERVER['REQUEST_URI']; and instead hard-code the url of the page using admin_url. Also, see @Joshua comments on using the WordPress in-built functions which handle sanitization of your SQL statements.

Final point, you will want to perform nonce-checks (as well permission checks – should the current user be able to delete/modify table?). For the nonce-check you can do:

 $url = wp_nonce_url( $url, 'my-nonce-action' );

to add the nonce to the url the user is directed to. Then prior to deleting/modifying anything, use wp_verify_nonce to verify the nonce.

error code: 523