[wp-hackers] internal redirects

Otto otto at ottodestruct.com
Tue Apr 27 17:47:47 UTC 2010


If you're going to do redirects, best to do them as early as possible.
I have plugin code that looks basically like this:

if (array_key_exists('my_check_thingy', $_GET) &&
$_GET['my_check_thingy'] == 1) { ?>
... logic for redirect ...
}

This happens right at plugin load. No waiting about, no loading the
query, just do it. Works fine, speedy as heck.

-Otto



On Tue, Apr 27, 2010 at 12:25 PM, scribu <scribu at gmail.com> wrote:
> You should hook your validation code before headers are sent, like this:
>
> function my_form_validation() {
>    // etc.
>
>    if ( $_POST[..] ... )
>        wp_redirect( ... );
>
>    // etc.
> }
> add_action('template_redirect', 'my_form_validation');
>
>
> --
> http://scribu.net
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list