views:

11

answers:

1

I'm developing my first Wordpress plugin, and I have one line which deletes an entry. I have 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?

A: 

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
Turns out you were right. Thanks for the help!