Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created March 10, 2012 17:54
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisguitarguy/2012290 to your computer and use it in GitHub Desktop.
Save chrisguitarguy/2012290 to your computer and use it in GitHub Desktop.
Don't allow people to view the default WordPress registration page
<?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' );
}
@franz-josef-kaiser
Copy link

You could also use the login_redirect filter.

@chrisguitarguy
Copy link
Author

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

@franz-josef-kaiser
Copy link

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

@chrisguitarguy
Copy link
Author

Nah, good idea for a plugin, though!

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

@ericmosaic
Copy link

This plugin is currently not letting me goto /wp-admin once logged in as an admin. Any suggestions on how I could edit the plugin to allow access to wp-admin?

@madivad
Copy link

madivad commented Sep 12, 2017

Chris, awesome piece of work here. I originally tried a filter on [register_url](https://codex.wordpress.org/Plugin_API/Filter_Reference/register_url), for whatever reason, it didn't work. Not sure what I did wrong there, but this code worked perfectly. Cheers!

@xlxl11
Copy link

xlxl11 commented Nov 7, 2018

Produk unggulan QNC JELLY GAMAT obat maag kronis yang sudah terbukti ampuh dan efektif dalam membantu mengatasi, mengobati, menghilangkan, dan menyembuhkan berbagai penyakit. Terbuat dari 100% bahan alami tanpa bahan kimia sedikitpun sehingga aman dikonsumsi tanpa menimbulkan efek samping apapun untuk tubuh. Qnc jelly gamat sudah memiliki sertifikasi HALAL MUI dan sudah terdaftar BPOM RI jadi sudah tidak diragukan lagi khasiat dan kandungan dari Qnc jelly gamat.

@xlxl11
Copy link

xlxl11 commented Dec 7, 2018

Obat herbal QNC JELLY GAMAT obat radang empedu alami dibuat dari bahan alami yaitu teripang gamat laut sejenis hewan laut yang sudah banyak diteliti oleh para pakar kesehatan bahwa hewan ini mampu mempunyai banyak khasiat sebagai obat penyembuh berbagai macam penyakit dan ditambah dengan ekstrak buah dan sayuran yang dibutuhkan bagi kesehatan tubuh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment