Yes, stuck with creating a custom signup page for WordPress Multisite.

It's a well revised question, and many of us is seeking the answer. May be somebody got one, but still, I can't find any solid, holistic one for the issue. I'm trying to find a non .htaccess way - a PHP' or a WordPress' way.

Step 1:

I studied the most obvious article found in this quest:

Okay, now I've copied all the code of /wp-signup.php to a file in my theme named signup.php, make it a page template and called the page with the URL http://example.com/signup.

I made changes to the required places. Like instead of get_header( 'wp-signup' ); I used my custom one from my theme get_header('null');. That one (header-null.php) is pretty bare-bone in design and architecture from the default header.php file of my theme.

Alas! There is no header-wp-signup.php in anywhere of WordPress

Similarly I replaced get_footer( 'wp-signup' ); with:

    ?> <!-- /ending of php tag -->
    </div> <!-- /.container .site-area .not-logged-in-page -->

<?php wp_footer(); ?>

</body>
</html>

Step 2:

@toscho helped me solving two issues of recalling files that are already loaded. So, instead of showing absolute paths, I simply commented out the lines:

//require( dirname(__FILE__) . '/wp-load.php' );

and

//require( dirname( __FILE__ ) . '/wp-blog-header.php' );

Now I've a nice, working file for newly modified sign-up page. I need to drive the traffic from /wp-signup.php to here, not using .htaccess.

Step 3:

I found this WordPress.org Support thread very helpful:

Now I made a "mu-plugin" making a file in: wp-content/mu-plugins/sign-up-location.php. There I used two functions:

/**
 * Changing the Registration page URL.
 * 
 * @return string The URL of the new page.
 * --------------------------------------------------------------------------
 */
function project_signup_page() {
    $page =  network_site_url() .'signup/';
    return $page;
}
add_filter( 'wp_signup_location', 'project_signup_page' );


/**
 * Redirect from default signup page to custom page.
 * 
 * @return void
 * --------------------------------------------------------------------------
 */
function project_redirect_from_default_signup() {
    if( strpos($_SERVER['REQUEST_URI'], 'wp-signup.php')) {
        wp_redirect(network_site_url() .'signup/');
        exit();
    }
}
add_action( 'plugins_loaded', 'project_redirect_from_default_signup' );

The first one is changing the registration URL to my custom path. And the second one is my desired one, driving traffic from /wp-signup.php to /signup without .htaccess.

Note: Instead of creating MU Plugin, you can get the same affect using a regular plugin now.

Step 4 (furnishing steps):

As per @toscho's suggestion I replaced the page template thing with a Rewrite Endpoint:

<?php
/**
 * Rewrite endpoint : /register.
 *
 * @return void
 * --------------------------------------------------------------------------
 */
function project_registration_endpoint() {
    add_rewrite_endpoint( 'register', EP_ROOT );
    if( get_option("EDIT_REWRITE_RULE") != 1 ) {
        flush_rewrite_rules();
        update_option( "EDIT_REWRITE_RULE", 1 );
    }
}
add_action( 'init', 'project_registration_endpoint' );

/**
 * Custom Template for Registration.
 *
 * @param  string $template Template to be loaded.
 * @return string           Our custom template to show up.
 * --------------------------------------------------------------------------
 */
function project_custom_templates( $template ) {
    if( ! is_admin() ) {
        if( get_query_var('register') || strpos($_SERVER['REQUEST_URI'], 'wp-signup.php') ) {
            $template = get_template_directory() .'/signup.php';
        }
    }
    return $template;
}
add_filter( 'template_include', 'project_custom_templates' );

/**
 * Return a value for '/register'
 * Make sure that 'get_query_var( 'register' )' 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 project_set_epex_var( $vars ) {
    isset( $vars['register'] ) and $vars['register'] = true;
    return $vars;
}
add_filter( 'request', 'project_set_epex_var' );

Modified: And at that point, I changed the slug /signup to /register to resolve any possible conflict, that can happen. I changed the mu-plugin's strings accordingly. And make the page template retired.

Everything is working fine, and I got my desired thing :) ... except...

the success or error messages...
all the success or error messages are gone with wp_redirect(). :o

I checked my file, yes, the show_user_form() is there with $errors parameter, everything is fine, except the error or success messages.

How can I display the success and/or error messages in my custom page signup page?

In Bengali

I explained the whole thing in details with all the sources in Bengali, in my blog post - I'm afraid, automatic translation to Bengali is till not that good.

  • well done on getting to this point by the way... looks like a hack of a journey... – majick Feb 29 '16 at 15:00
up vote 1 down vote accepted

In your signup.php file, try changing the form action from wp-signup.php to signup.php... this way the form data is not passed through the redirect but rather directly back to the same file and this should preserve the $errors from the form posting.

  • hahaha! I overlook that tiny part... thank you @majick. thanks a lot. Hope this journey will solve the age-old mystery (a what?)... hahaha!! – Mayeenul Islam Mar 1 '16 at 4:38
  • glad i could help, it's always the little things eh? looks like your perserverence has paid off tho. :-) – majick Mar 1 '16 at 8:45
  • My perseverance! :o It's my mentors. Thanks @toscho for taking me this far. – Mayeenul Islam Mar 1 '16 at 10:14

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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