[wp-hackers] Best practice: custom registration form

Frank Bueltge frank at bueltge.de
Wed Aug 4 08:13:54 UTC 2010


wp_login_form(array(
    'echo' => true,
    'redirect' => site_url($_SERVER['REQUEST_URI']),

    'form_id' => 'loginform',
    'label_username' => __('Username'),

    'label_password' => __('Password'),
    'label_remember' => __('Remember Me'),

    'label_log_in' => __('Log In'),
    'id_username' => 'user_login',

    'id_password' => 'user_pass',
    'id_remember' => 'rememberme',

    'id_submit' => 'wp-submit',
    'remember' => true,
    'value_username' => ,

    'value_remember' => false
));

This function is new with WP3.0 and its exactly for the login  via WP. I
inlcude this in my page-template and ready.
small example:

global $user_login;

if (is_user_logged_in()) {
    echo __( 'Hello, ' FB_BASIS_TEXTDOMAIN ), $user_login, '. <a
href="', wp_logout_url(), '" title="' . __( 'Logout',
FB_BASIS_TEXTDOMAIN ) . '">' . __( 'Logout', FB_BASIS_TEXTDOMAIN ) .
'</a>';

} else {
    wp_login_form();
}


Codey: http://codex.wordpress.org/Template_Tags/wp_login_form

And a tutorial from my, but only in german language:
http://bueltge.de/wordpress-login-formular/976/

Use also the code, this is multilanguage ;)


On Wed, Aug 4, 2010 at 1:49 AM, Daniel Cameron <dan at sproutventure.com>wrote:

> > 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' ) );
> _______________________________________________
> 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