I have a WP plugin which uses the request parameter “type” to determine what code-file to load in order to do some processing. The code which handles this is as follows:
add_shortcode ('myplugin_frontend_main', 'MyPlugin_user_dispatcher');
function MyPlugin_user_dispatcher ($args=array())
{
$type = $_GET['type'];
$func = $_GET['func'];
$typefile = ucwords($type). '.php';
require_once(dirname(__FILE__) . "/$typefile");
$class = 'MyPlugin_Controller_' . ucfirst($type);
$object = new $class();
echo $object->$func($args);
}
The strange thing is this, if I call
http://localhost/wordpress/?page_id=4&type=userform&func=edit&noheader=true&ot=product_add&id=14&store=1
and add
var_dump ($_GET);
exit ();
to the code, my var_dump() prints out the following:
array
'page_id' => string '4' (length=1)
'type' => string 'user' (length=4)
'func' => string 'main' (length=4)
'store' => string '1' (length=1)
So somehow, $_GET does not contain what I call through the address bar (or by clicking on a link with the same content).
Does anybody have any idea what’s going on here?
Greetings/Thanks
R
WordPress will typically filter off query arguments unless you tell it about those arguments and ask it not to.
From this older tutorial, you can see how to add a new query variable to WordPress (so it won’t get stripped out):
There is an alternative suggestion in the first answer of this question:
Once you do that, though, you need to also be aware of some reserved terms within WordPress. There are just some terms you can’t use for custom data because they’re already used elsewhere. The full list of reserved terms is in the Codex.
A quick glance shows that “type” is in the reserved list … which could be why it’s changing when you try to use it.