Skip to content

Instantly share code, notes, and snippets.

@mayeenulislam
Last active March 1, 2016 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayeenulislam/3e332efd44a3388034c3 to your computer and use it in GitHub Desktop.
Save mayeenulislam/3e332efd44a3388034c3 to your computer and use it in GitHub Desktop.
Creating custom signup page for WordPress multisite
/**
* 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' );
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' );
<?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' );
<?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