Hello,
I need to redirect to a specific URL once a user has successfully registered from my custom registration page. Right now a successful registration is redirected to the WP login screen with a message that says: 'Registration complete. Please check your e-mail'.
Thanks for the help.
Arnav Joy answers:
here is the full modified code of your's , please check and let me know there is any modification required in this
please change $redirect_url = get_bloginfo('url');
<?php /* Template Name: Registration Page */ ?>
<?php
$redirect_url = get_bloginfo('url'); // change this as per your requirement
require_once(ABSPATH . WPINC . '/registration.php');
global $wpdb, $user_ID;
if($_POST){
//We shall SQL escape all inputs
$username = $wpdb->escape($_REQUEST['user_login']);
if(empty($username)) {
$err .= "User name should not be empty.<br />";
}
$email = $wpdb->escape($_REQUEST['user_email']);
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email)) {
$err .= "Please enter a valid email. <br />";
}
$random_password = wp_generate_password( 12, false );
$status = wp_create_user( $username, $random_password, $email );
if ( is_wp_error($status) )
$err .= "Username already exists. Please try another one. <br />";
else {
$from = get_option('admin_email');
$headers = 'From: '.$from . "\r\n";
$subject = "Registration successful";
$msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password <br />";
wp_mail( $email, $subject, $msg, $headers );
$err .= "Please check your email for login details.<br />";
?>
<script>location.href='<?php echo $redirect_url;?>'</script>
<?php
}
}
get_header(); ?>
<div class="post clearfix">
<div class="entry clearfix">
<div id="classiwrapper">
<h2><?php the_title(); ?></h2>
<?php if(!empty($err)) echo '<font color="red">'.$err.'</font>';?>
<form name="loginform" id="loginform" action="" method="post">
<p>
<label>Username:</label><br/>
<input type="text" name="user_login" class="textinput" value="" id="user_login" />
</p>
<p>
<label>Email Address:</label><br/>
<input type="text" name="user_email" class="textinput" value="" id="user_email" />
</p>
<?php do_action('register_form'); ?>
<p>
<input type="submit" id="submitbtn" class="submitbutton" name="submit" value="Register" />
</p>
<p class="statement">A password will be e-mailed to you.</p>
</form>
</div>
</div>
<!-- END entry -->
</div>
<!-- END post -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Denis Leblanc comments:
Arnav,
This worked great. Thanks so much.
d.
Abdelhadi Touil answers:
Hi.
Hope this helps you:
http://wpmu.org/redirect-wordpress-users-to-a-custom-thank-you-page-after-registration/
Abdelhadi Touil comments:
Here is the same question, and it's solved in Stack Overflow:
[[LINK href="http://stackoverflow.com/questions/9134281/wordpress-custom-registration-form-redirect-after"]]http://stackoverflow.com/questions/9134281/wordpress-custom-registration-form-redirect-after[[/LINK]]
Good luck :)
Denis Leblanc comments:
Thanks for that, I'll give it a shot.
Asad Iqbal answers:
Hi,
Did you try this plugin yet:
http://wordpress.org/extend/plugins/peters-login-redirect/
Let me know what do you think.
Denis Leblanc comments:
I did try this plugin but no dice. I'm guessing it's not working cause my registration page is custom.
Thanks.
Asad Iqbal comments:
Ok, do one thing. At the end of the code can you please the following line?
<script> location.href="http://domainname.com/your-page-address"; </script>
Romel Apuya answers:
can you post the code from you custom registration page?
Denis Leblanc comments:
Here's the code for the registration page template:
<?php /* Template Name: Registration Page */ ?>
<?php get_header(); ?>
<div class="post clearfix">
<div class="entry clearfix">
<div id="classiwrapper">
<h2><?php the_title(); ?></h2>
<form name="loginform" id="loginform" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" method="post">
<p>
<label>Username:</label><br/>
<input type="text" name="user_login" class="textinput" value="" id="user_login" />
</p>
<p>
<label>Email Address:</label><br/>
<input type="text" name="user_email" class="textinput" value="" id="user_email" />
</p>
<?php do_action('register_form'); ?>
<p>
<input type="submit" id="submitbtn" class="submitbutton" name="submit" value="Register" />
</p>
<p class="statement">A password will be e-mailed to you.</p>
</form>
</div>
</div>
<!-- END entry -->
</div>
<!-- END post -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Agus Setiawan answers:
hi, put this code to function.php
------------------------------------------------------
function __my_registration_redirect()
{
return home_url( '/my-page' );
}
add_filter( 'registration_redirect', '__my_registration_redirect' );
---------------------------------------------------------------
change "my-page" with your own page, hope this help.