Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a specific wordpress registration page where I have a new user complete their registration form. However, if someone clicks on the "forgot password" link in the login section of my site and then clicks on register, they'll be able to register for the site without going through the normal registation form. How can I redirect the wp-login.php?action=register page to sample.com/register ?

Thanks in advance!

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Hook into login_form_register and throw people to your registration page with wp_redirect.

<?php
add_action( 'login_form_register', 'wpse45134_catch_register' );
/**
 * Redirects visitors to `wp-login.php?action=register` to 
 * `site.com/register`
 */
function wpse45134_catch_register()
{
    wp_redirect( home_url( '/register' ) );
    exit(); // always call `exit()` after `wp_redirect`
}

You can also hide the "register" link on that page by hijacking the user_can_register option on the login page. Hook into login_form_lostpassword and login_form_retrievepassword, from there add a filter to pre_option_users_can_register.

<?php
add_action( 'login_form_lostpassword', 'wpse45134_filter_option' );
add_action( 'login_form_retrievepassword', 'wpse45134_filter_option' );
/**
 * Simple wrapper around a call to add_filter to make sure we only
 * filter an option on the login page.
 */
function wpse45134_filter_option()
{
    // use __return_zero because pre_option_{$opt} checks
    // against `false`
    add_filter( 'pre_option_users_can_register', '__return_zero' );
}

As a plugin.

share|improve this answer
    
Thanks Christopher! Just one question, how do I implement this as a plugin? I've never created a wp plugin before but if you have a link for direction, etc. I'm comfortable with code and such –  BentCircle Mar 10 '12 at 18:32
    
You would just copy and paste the code above into a single PHP file, put in the plugin header (codex.wordpress.org/Writing_a_Plugin#File_Headers), drop the PHP file into your wp-content/plugins directory. Here is the complete thing as a plugin gist.github.com/2012290 –  chrisguitarguy Mar 10 '12 at 19:10
    
Thanks very much! –  BentCircle Mar 11 '12 at 12:53
add comment

protected by Community Sep 18 '12 at 16:15

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.