public
Last active

Don't allow people to view the default WordPress registration page

  • Download Gist
wpse45134.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<?php
/*
Plugin Name: Registration Redirect
Description: Don't allow people to view the default registration page
Author: Christopher Davis
Author URI: http://christopherdavis.me
License: GPL2
*/
 
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`
}
 
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 reset password page.
*/
function wpse45134_filter_option()
{
// use __return_zero because pre_option_{$opt} checks
// against `false`
add_filter( 'pre_option_users_can_register', '__return_zero' );
}

You could also use the login_redirect filter.

I don't think that applicable for this use case. They just wanted to stop people from viewing the default registration form.

Ah, ok. I thought this was a more general version as a plugin.

Nah, good idea for a plugin, though!

login_form_{$action} fires right after login_init, so it's a bit different than login_redirect.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.