I'm developing my first Wordpress plugin, and I have one line which deletes an entry. I h开发者_开发问答ave to use query string parameters to pass in the action and the object id. My code is:
$pageText .= '<td><a href="'.$_SERVER['REQUEST_URI'].'?useraction=delete&domainid='.$file.'">Delete</a></td></tr>';
This creates a 'delete' link and populates the two parameters. Problem is, Wordpress gives me a "You do not have sufficient permissions to access this page." for passing in a variable in the query string.
Does anyone know how to properly pass variables in a plugin?
This creates a 'delete' link and populates the two parameters. Problem is, Wordpress gives me a "You do not have sufficient permissions to access this page." for passing in a variable in the query string.
I don't think that is the problem. I'd rather bet that by building the URL that way, you are dropping other request parameters (that are not preserved in REQUEST_URI) that you need to add again. To re-build the complete query string, the cleanest way would be using http_build_query()
:
$link = $_SERVER['REQUEST_URI']."?".
http_build_query(
Array('useraction' => 'delete', 'domainid' => $file)
+ $_GET);
$pageText .= '<td><a href="'$link">Delete</a></td></tr>';
The http_build_query (it is a bit hard to read) merges an array with your URL parameters, and the existing $_GET array together into a proper query string.
Pekka, The problem here is that you get huge URLs if someone keeps deleting. I am doing something similar with a "remove" parameter:
http://mydomain.org/wp-admin/admin.php?page=my_plugin&remove=2160735755&page=my_plugin&remove=2160735973&page=my_plugin
how do you "clean up" the query?
精彩评论