| 1 |
<?php |
| 2 |
/** |
| 3 |
* Function that changes the auto generated password with the one selected by the user. |
| 4 |
*/ |
| 5 |
function signup_password_random_password_filter( $password ) { |
| 6 |
global $wpdb; |
| 7 |
|
| 8 |
$key = ( !empty( $_GET['key'] ) ? $_GET['key'] : null ); |
| 9 |
$key = ( !empty( $_POST['key'] ) ? $_POST['key'] : null ); |
| 10 |
|
| 11 |
if ( !empty( $_POST['user_pass'] ) ) |
| 12 |
$password = $_POST['user_pass']; |
| 13 |
|
| 14 |
elseif ( !is_null( $key ) ) { |
| 15 |
$signup = ( is_multisite() ? $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->signups . " WHERE activation_key = %s", $key ) ) : $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "signups WHERE activation_key = %s", $key ) ) ); |
| 16 |
|
| 17 |
if ( empty( $signup ) || $signup->active ) { |
| 18 |
//bad key or already active |
| 19 |
} else { |
| 20 |
//check for password in signup meta |
| 21 |
$meta = unserialize( $signup->meta ); |
| 22 |
|
| 23 |
$password = $meta['user_pass']; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
return apply_filters( 'wppb_generated_random_password', $password, $key ); |
| 28 |
} |
| 29 |
add_filter( 'random_password', 'signup_password_random_password_filter' ); |
| 30 |
|
| 31 |
/** |
| 32 |
* Activate a signup. |
| 33 |
* |
| 34 |
* |
| 35 |
* @param string $key The activation key provided to the user. |
| 36 |
* @return array An array containing information about the activated user and/or blog |
| 37 |
*/ |
| 38 |
function wppb_activate_signup( $key ) { |
| 39 |
global $wpdb; |
| 40 |
$bloginfo = get_bloginfo( 'name' ); |
| 41 |
$wppb_general_settings = get_option( 'wppb_general_settings' ); |
| 42 |
|
| 43 |
$signup = ( is_multisite() ? $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) ) : $wpdb->get_row( $wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."signups WHERE activation_key = %s", $key ) ) ); |
| 44 |
|
| 45 |
if ( empty( $signup ) ) |
| 46 |
return apply_filters( 'wppb_register_activate_user_error_message1', '<p class="error">'.__( 'Invalid activation key!', 'profilebuilder' ).'</p>'); |
| 47 |
|
| 48 |
if ( $signup->active ) |
| 49 |
if ( empty( $signup->domain ) ) |
| 50 |
return apply_filters( 'wppb_register_activate_user_error_message2', '<p class="error">'.__( 'This username is now active!', 'profilebuilder' ).'</p>' ); |
| 51 |
|
| 52 |
$meta = unserialize( $signup->meta ); |
| 53 |
|
| 54 |
$user_login = ( ( isset( $wppb_general_settings['loginWith'] ) && ( $wppb_general_settings['loginWith'] == 'email' ) ) ? trim( $signup->user_email ) : trim( $signup->user_login ) ); |
| 55 |
|
| 56 |
$user_email = esc_sql( $signup->user_email ); |
| 57 |
/* the password is in hashed form in the signup table so we will add it later */ |
| 58 |
$password = NULL; |
| 59 |
|
| 60 |
$user_id = username_exists( $user_login ); |
| 61 |
|
| 62 |
if ( !$user_id ) |
| 63 |
$user_id = wppb_create_user( $user_login, $password, $user_email ); |
| 64 |
else |
| 65 |
$user_already_exists = true; |
| 66 |
|
| 67 |
if ( ! $user_id ) |
| 68 |
return apply_filters( 'wppb_register_activate_user_error_message4', '<p class="error">'.__('Could not create user!', 'profilebuilder').'</p>' ); |
| 69 |
|
| 70 |
elseif ( isset( $user_already_exists ) && ( $user_already_exists == true ) ) |
| 71 |
return apply_filters( 'wppb_register_activate_user_error_message5', '<p class="error">'.__( 'This username is already activated!', 'profilebuilder' ).'</p>' ); |
| 72 |
|
| 73 |
else{ |
| 74 |
$inserted_user = ( is_multisite() ? $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $current_time( 'mysql', true ) ), array( 'activation_key' => $key ) ) : $wpdb->update( $wpdb->prefix.'signups', array( 'active' => 1, 'activated' => current_time( 'mysql', true ) ), array( 'activation_key' => $key ) ) ); |
| 75 |
|
| 76 |
wppb_add_meta_to_user_on_activation( $user_id, '', $meta ); |
| 77 |
|
| 78 |
// if admin approval is activated, then block the user untill he gets approved |
| 79 |
$wppb_generalSettings = get_option('wppb_general_settings'); |
| 80 |
if ( isset( $wppb_generalSettings['adminApproval'] ) && ( $wppb_generalSettings['adminApproval'] == 'yes' ) ){ |
| 81 |
wp_set_object_terms( $user_id, array( 'unapproved' ), 'user_status', false ); |
| 82 |
clean_object_term_cache( $user_id, 'user_status' ); |
| 83 |
} |
| 84 |
|
| 85 |
if ( !isset( $wppb_generalSettings['adminApproval'] ) ) |
| 86 |
$wppb_generalSettings['adminApproval'] = 'no'; |
| 87 |
|
| 88 |
/* copy the hashed password from signup meta to wp user table */ |
| 89 |
if( !empty( $meta['user_pass'] ) ){ |
| 90 |
/* we might still have the base64 encoded password in signups and not the hash */ |
| 91 |
if( base64_encode(base64_decode($meta['user_pass'], true)) === $meta['user_pass'] ) |
| 92 |
$meta['user_pass'] = wp_hash_password( $meta['user_pass'] ); |
| 93 |
|
| 94 |
$wpdb->update( $wpdb->users, array('user_pass' => $meta['user_pass'] ), array('ID' => $user_id) ); |
| 95 |
} |
| 96 |
|
| 97 |
wppb_notify_user_registration_email($bloginfo, $user_login, $user_email, 'sending', $password, $wppb_generalSettings['adminApproval']); |
| 98 |
|
| 99 |
do_action( 'wppb_activate_user', $user_id, $password, $meta ); |
| 100 |
|
| 101 |
if ( $inserted_user ){ |
| 102 |
$success_message = apply_filters('wppb_success_email_confirmation', '<p class="wppb-success">'. __('Your email was successfully confirmed.', 'profilebuilder') .'</p><!-- .success -->'); |
| 103 |
$admin_approval_message = apply_filters('wppb_email_confirmation_with_admin_approval', '<p class="alert">'. __('Before you can access your account, an administrator needs to approve it. You will be notified via email.', 'profilebuilder') . '</p>' ); |
| 104 |
|
| 105 |
$wppb_general_settings = get_option( 'wppb_general_settings', 'false' ); |
| 106 |
if ( !empty( $wppb_general_settings['adminApproval'] ) && $wppb_general_settings['adminApproval'] == 'yes' ){ |
| 107 |
return $success_message . $admin_approval_message; |
| 108 |
} else { |
| 109 |
return $success_message; |
| 110 |
} |
| 111 |
} else { |
| 112 |
return apply_filters('wppb_register_failed_user_activation', '<p class="error">'. __('There was an error while trying to activate the user.', 'profilebuilder') .'</p><!-- .error -->'); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
//function to display the registration page |
| 118 |
function wppb_front_end_register( $atts ){ |
| 119 |
extract( shortcode_atts( array( 'role' => get_option( 'default_role' ), 'form_name' => 'unspecified' ), $atts, 'wppb-register' ) ); |
| 120 |
global $$form_name; |
| 121 |
$$form_name = new Profile_Builder_Form_Creator( array( 'form_type' => 'register', 'form_name' => $form_name, 'role' => ( is_object( get_role( $role ) ) ? $role : get_option( 'default_role' ) ) ) ); |
| 122 |
|
| 123 |
return $$form_name; |
| 124 |
} |
| 125 |
|
| 126 |
// function to choose whether to display the registration page or the validation message |
| 127 |
function wppb_front_end_register_handler( $atts ){ |
| 128 |
|
| 129 |
return ( isset( $_GET['activation_key'] ) ? wppb_activate_signup ( $_GET['activation_key'] ) : wppb_front_end_register( $atts ) ); |
| 130 |
} |