Last active
January 1, 2016 06:09
-
-
Save timersys/8103166 to your computer and use it in GitHub Desktop.
Wordpress Front end registration
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
/*************************** | |
INSIDE FUNCTIONS.PHP | |
****************************/ | |
/** | |
* Formulario de registro | |
*/ | |
//change register url for our custom one | |
add_filter('register_url', function(){ return site_url('registrese');}); | |
//Add extra fields to form | |
add_action('register_form','aulala_register_form'); | |
function aulala_register_form (){ | |
$first_name = ( isset( $_POST['first_name'] ) ) ? $_POST['first_name']: ''; | |
$last_name = ( isset( $_POST['last_name'] ) ) ? $_POST['last_name']: ''; | |
?> | |
<p> | |
<label for="first_name"><?php _e('Nombre','mydomain') ?><br /> | |
<input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr(stripslashes($first_name)); ?>" size="25" /></label> | |
</p> | |
<p> | |
<label for="first_name"><?php _e('Apellidos','mydomain') ?><br /> | |
<input type="text" name="last_name" id="first_name" class="input" value="<?php echo esc_attr(stripslashes($last_name)); ?>" size="25" /></label> | |
</p> | |
<?php | |
} | |
//2. Add validation. In this case, we make sure first_name is required. | |
add_filter('registration_errors', 'aulala_registration_errors', 10, 3); | |
function aulala_registration_errors ($errors, $sanitized_user_login, $user_email) { | |
if ( empty( $_POST['first_name'] ) ) | |
$errors->add( 'first_name_error', __('<strong>ERROR</strong>: Debes ingresar tu nombre.','mydomain') ); | |
if ( empty( $_POST['last_name'] ) ) | |
$errors->add( 'first_name_error', __('<strong>ERROR</strong>: Debes ingresar tus apellidos.','mydomain') ); | |
return $errors; | |
} | |
//3. Finally, save our extra registration user meta. | |
add_action('user_register', 'aulala_user_register'); | |
function aulala_user_register ($user_id) { | |
if ( isset( $_POST['first_name'] ) ) | |
update_user_meta($user_id, 'first_name', $_POST['first_name']); | |
if ( isset( $_POST['last_name'] ) ) | |
update_user_meta($user_id, 'last_name', $_POST['last_name']); | |
} | |
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
/*************************** | |
INSIDE FRONT END TEMPLATE | |
****************************/ | |
<?php if( isset($_GET['register']) && $_GET['register'] == 'true' ):?> | |
<h3><?php _e('Gracias por registrarte! Recibirás el password en tu email en unos minutos');?></h3> | |
<?php else: ?> | |
<form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" class="wp-user-form"> | |
<?php do_action('register_form'); ?> | |
<p> | |
<label for="user_login"><?php _e('Nombre de Usuario','mydomain') ?><br /> | |
<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="25" /></label> | |
</p> | |
<p> | |
<label for="user_email"><?php _e('Email','mydomain') ?><br /> | |
<input type="text" name="user_email" id="user_email" class="input" value="<?php echo esc_attr(stripslashes($user_email)); ?>" size="25" /></label> | |
</p> | |
<input type="submit" name="user-submit" value="<?php _e('Registrarse!'); ?>" class="user-submit" tabindex="103" /> | |
<input type="hidden" name="redirect_to" value="<?php echo isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI']: ''; ?>?register=true" /> | |
<input type="hidden" name="user-cookie" value="1" /> | |
</div> | |
</form> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment