wordpressmod-rewritequery-stringspecial-charactersurl-encoding

How do I prevent Wordpress from stripping the "at" sign (@) from the URL query string?


I am trying to pass an email address to a wordpress page like so:

http://www.website.com/?email=fakeemail@yeahwho.com

However, Wordpress turns it into this:

http://www.website.com/?email=fakeemailyeahwho.com 

I even try URL encoding it like so:

http://www.website.com/?email=fakeemail%40yeahwho.com

But Wordpress is too smart and still removes the %40.

I understand that @ is a reserved character, but I should be able to still use the URL encoded version. Alas, Wordpress does not want it to be so.

How can I force Wordpress to respect the @ sign? I'm guessing I'll either have to hack the internals, or do some mod_rewrite magic.


Solution

  • from http://www.webopius.com/content/137/using-custom-url-parameters-in-wordpress

    First, add this to your theme's functions.php file (or make a custom plugin to do it):

    add_filter('query_vars', 'parameter_queryvars' );
    function parameter_queryvars( $qvars )
    {
        $qvars[] = 'email';
        return $qvars;
    }
    

    Next, try passing ?email=fakeemail-AT-yeahwho.com in the URL and then converting it back with something like this:

    global $wp_query;
    if (isset($wp_query->query_vars['email']))
    {
        $getemail = str_replace( '-AT-', '@', $wp_query->query_vars['email']);
    }
    // now use $getemail
    

    This would only not work in the very rare occurrence of an email that actually has "-at-" in it. You could replace for an even more obscure string like '-AT6574892654738-' if you are concerned about this.

    Whatever your final solution, don't hack the core to get it to work. :)