[wp-hackers] Best practice: custom registration form

Daniel Cameron dan at sproutventure.com
Tue Aug 3 23:49:16 UTC 2010


> This what I end up using: a custom page template with a
> do_action('register_form').
>
> But when the template is called, the headers are already sent, so I
> wonder how you can send headers there (like wp_redirect does), even at
> the very beginning of the template ..
>

I'm building my own template ( basically using the core wp-login template
with a bunch of customizations ). This is how I'm doing a redirect, then I'm
using some additional functions to call the correct template(s).

public function redirectAwayFromLoginPage() {
global $pagenow;
 if( 'wp-login.php' == $pagenow ) {
$action = '?action=' . $_GET['action'];
 wp_redirect( site_url( $this->acount_login_url . $action ) );
}

 if ( $_GET['redirect_to'] == site_url('/wp-login.php') ) {
wp_redirect( site_url( $this->acount_login_url . '?action=register' ) );
 exit();
}

}
                add_action( 'init', array( $this,
'redirectAwayFromLoginPage' ) );


Something that I've seen people forget to do is filter the existing wp-core
functions that build urls to login/reg/password/logout. i.e.

                // Replace WP Login URIs
add_filter( 'logout_url', array( &$this, 'sv_string_replace_link' ) );
 add_filter( 'login_url', array( $this, 'sv_string_replace_link' ) );
add_filter( 'lostpassword_url', array( $this, 'sv_string_replace_link' ) );
 add_filter( 'register', array( $this, 'sv_string_replace_link' ) );


More information about the wp-hackers mailing list