Skip to content

Instantly share code, notes, and snippets.

@rustyeddy
Last active August 29, 2015 14:13
Show Gist options
  • Save rustyeddy/f43303114d077b676918 to your computer and use it in GitHub Desktop.
Save rustyeddy/f43303114d077b676918 to your computer and use it in GitHub Desktop.
Properly Handling URL requests in WordPress
/*
* We need to add our query variables
*/
add_filter( 'query_vars', 'mb_register_variables' );
function mb_register_variables( $qv )
{
$qv[] = 'Badge';
$qv[] = 'Username';
$qv[] = 'Password';
return $qv;
}
/*
* Now respond to the query variables
*/
add_action( 'parse_request', 'mb_parse_request' );
function mb_parse_request( $wp )
{
//print_r( $wp->query_vars );
if ( array_key_exists('Badge', $wp->query_vars) &&
array_key_exists('Password', $wp->query_vars ) &&
array_key_exists('Username', $wp->query_vars ) ) {
$b = $wp->query_vars['Badge'];
$p = $wp->query_vars['Password'];
$u = $wp->query_vars['Username'];
do_something_important();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment