jamesalexhall
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: Alternative Registration PageThanks for you response MichaelH.
Below is the solution I have been working on this afternoon. Thought I would post incase it is of any use to anyone in future. It’s a page template which provides a starting point for building an alternative registation form. This will allow creation of a customised registration form without hacking at the core wordpress files. It is also unaffected by any plugins overiding the default registration page (i.e. Register Plus or Pie Register).
I would welcome any feedback as to how this might be improved.
<?php /* Template Name: ALTERNATIVE USER REG */ // FUNCTION TO PREVENT DATABASE ATTACK - BEGIN function check_input($value){ // Stripslashes if (get_magic_quotes_gpc()){ $value = stripslashes($value); } // Quote if not a number if (!is_numeric($value)){ $value = mysql_real_escape_string($value); } return $value; } // FUNCTION TO PREVENT DATABASE ATTACK - END // CHECK TO SEE IF FORM HAS BEEN SUBMITTED if($_POST['SubmitCheck']==1){ // CHECK TO ENSURE THAT USERNAME & PASSWORD FIELDS HAVE BEEN FILLED IN if((trim($_POST['UserName'])=="") || (trim($_POST['Email'])=="")){ echo "Please enter a valid Username/Password"; } else{ //GET VALUES SUBMITTED VIA FORM $user_name = check_input($_POST['UserName']); $user_email = check_input($_POST['Email']); // GET REQUIRED WORDPRESS LIBRARIES require_once(ABSPATH . WPINC . '/registration.php'); require_once(ABSPATH . WPINC . '/pluggable.php'); // CHECK WHETHER USERNAME EXISTS if(username_exists($user_name)){ echo "This username already exists. Please enter another."; } else{ // CHECK WHETHER EMAIL ALREADY EXISTS if(email_exists($user_email)){ echo "This email already exists. Please enter another."; } else{ // GENERATE A RANDOM PASSWORD $random_password = wp_generate_password( 12, false ); //CREATE THE WORDPRESS USER $user_id = wp_create_user( $user_name, $random_password, $user_email ); // SEND USER AND DATABASE ADMIN THE NOTIFICATION EMAIL wp_new_user_notification( $user_id, $plaintext_pass ); // THANK YOU MESSAGE echo "Thank you for registering. Please check your email."; } } } } else{ // IF THE FORM HASN'T BEEN SUBMITTED, OUTPUT THE REGISTRATION FORM echo '<form name="input" action="'.get_permalink().'" method="post">'; echo '<p>Username:<br /><input type="text" name="UserName" /></p>'; echo '<p>Email:<br /><input type="text" name="Email" /></p>'; echo '<input type="hidden" name="SubmitCheck" value="1" />'; echo '<p><input type="submit" value="Submit" /></p>'; echo '</form>'; } // By James Alex Hall at https://www.jamesalexhall.co.uk ?>
Viewing 1 replies (of 1 total)