-
-
Save mayeenulislam/3e332efd44a3388034c3 to your computer and use it in GitHub Desktop.
Creating custom signup page for WordPress multisite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return a value for '/signup' | |
* Make sure that 'get_query_var( 'signup' )' will not return just an empty string if it is set. | |
* | |
* @link http://wordpress.stackexchange.com/a/51450/22728 | |
* @link https://www.pmg.com/blog/a-mostly-complete-guide-to-the-wordpress-rewrite-api/ | |
* | |
* @param array $vars Query variables. | |
* @return array Modified query variables. | |
*/ | |
function nanotuts_set_epex_var( $vars ) { | |
isset( $vars['signup'] ) and $vars['signup'] = true; | |
return $vars; | |
} | |
add_filter( 'request', 'nanotuts_set_epex_var' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nanotuts_signup_scripts() { | |
wp_enqueue_style( 'nanotuts-signup-styles', get_template_directory_uri() .'/css/nanotuts-signup-style.css' ); | |
wp_enqueue_script( 'nanotuts-signup-scripts', get_template_directory_uri() .'/js/nanotuts-signup-scripts.js', array('jquery'), '1.0.0', true ); | |
} | |
add_action( 'wp_enqueue_scripts', 'nanotuts_signup_scripts' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Rewrite endpoint : /signup. | |
* @link https://gist.github.com/hasinhayder/c0f3968129a32df862a5#file-functions-php | |
* @return void | |
*/ | |
function nanotuts_registration_endpoint() { | |
add_rewrite_endpoint( 'signup', EP_ROOT ); | |
if( get_option("EDIT_REWRITE_RULE") != 1 ) { | |
flush_rewrite_rules(); | |
update_option( "EDIT_REWRITE_RULE", 1 ); | |
} | |
} | |
add_action( 'init', 'nanotuts_registration_endpoint' ); | |
/** | |
* Custom Template for Registration. | |
* | |
* @param string $template Template to be loaded. | |
* @return string Our custom template to show up. | |
*/ | |
function nanotuts_custom_templates( $template ) { | |
if( ! is_admin() ) { | |
if( get_query_var('signup') || strpos($_SERVER['REQUEST_URI'], 'wp-signup.php') ) { | |
$template = get_template_directory() .'/signup.php'; | |
} | |
} | |
return $template; | |
} | |
add_filter( 'template_include', 'nanotuts_custom_templates' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WP MU Plugin | |
* @author Mayeenul Islam (@mayeenulislam) | |
*/ | |
/** | |
* Changing the Registration page URL. | |
* @return string The URL of the new page. | |
*/ | |
function nanotuts_signup_page() { | |
$page = network_site_url() .'signup/'; | |
return $page; | |
} | |
add_filter( 'wp_signup_location', 'nanotuts_signup_page' ); | |
/** | |
* Redirect from default signup page to custom page. | |
* @return void | |
*/ | |
function nanotuts_redirect_from_default_signup() { | |
if( strpos($_SERVER['REQUEST_URI'], 'wp-signup.php')) { | |
wp_redirect(network_site_url() .'signup/'); | |
exit(); | |
} | |
} | |
add_action( 'plugins_loaded', 'nanotuts_redirect_from_default_signup' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment