PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.7.1
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.7.1
4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 340 releases
profile-builder / front-end / register.php

register.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 2.7.1, at front-end/register.php

208 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Function that changes the auto generated password with the one selected by the user.
4 */
5 function wppb_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'] : $key );
10 if( !empty( $key ) )
11 $key = sanitize_text_field( $key );
12
13 if ( !empty( $_POST['user_pass'] ) )
14 $password = $_POST['user_pass'];
15 elseif ( !is_null( $key ) ) {
16 $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->base_prefix . "signups WHERE activation_key = %s", $key ) ) );
17
18 if ( empty( $signup ) || $signup->active ) {
19 //bad key or already active
20 } else {
21 //check for password in signup meta
22 $meta = unserialize( $signup->meta );
23
24 if ( !empty($meta['user_pass']) )
25 $password = $meta['user_pass'];
26 }
27 }
28
29 return apply_filters( 'wppb_generated_random_password', $password, $key );
30 }
31 add_filter( 'random_password', 'wppb_signup_password_random_password_filter' );
32
33 /**
34 * Activate a signup.
35 *
36 *
37 * @param string $key The activation key provided to the user.
38 * @return array An array containing information about the activated user and/or blog
39 */
40 function wppb_activate_signup( $key ) {
41 global $wpdb;
42 $bloginfo = get_bloginfo( 'name' );
43 $wppb_general_settings = get_option( 'wppb_general_settings' );
44
45 $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->base_prefix."signups WHERE activation_key = %s", $key ) ) );
46
47 $user_login = ( ( isset( $wppb_general_settings['loginWith'] ) && ( $wppb_general_settings['loginWith'] == 'email' ) ) ? trim( $signup->user_email ) : trim( $signup->user_login ) );
48
49 $user_email = esc_sql( $signup->user_email );
50 /* the password is in hashed form in the signup table so we will add it later */
51 $password = NULL;
52
53 $user_id = username_exists( $user_login );
54
55 if ( empty( $signup ) )
56 return apply_filters( 'wppb_register_activate_user_error_message1', '<p class="error">'.__( 'Invalid activation key!', 'profile-builder' ).'</p>');
57
58 if ( $signup->active )
59 if ( empty( $signup->domain ) )
60 return apply_filters( 'wppb_register_activate_user_error_message2', '<p class="error">'.__( 'This username is now active!', 'profile-builder' ).'</p>', $user_id );
61
62 $meta = unserialize( $signup->meta );
63
64
65 if ( !$user_id )
66 $user_id = wppb_create_user( $user_login, $password, $user_email );
67 else
68 $user_already_exists = true;
69
70 if ( ! $user_id )
71 return apply_filters( 'wppb_register_activate_user_error_message4', '<p class="error">'.__('Could not create user!', 'profile-builder').'</p>' );
72
73 elseif ( isset( $user_already_exists ) && ( $user_already_exists == true ) )
74 return apply_filters( 'wppb_register_activate_user_error_message5', '<p class="error">'.__( 'This username is already activated!', 'profile-builder' ).'</p>' );
75
76 else{
77 $inserted_user = ( is_multisite() ? $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => current_time( 'mysql', true ) ), array( 'activation_key' => $key ) ) : $wpdb->update( $wpdb->base_prefix.'signups', array( 'active' => 1, 'activated' => current_time( 'mysql', true ) ), array( 'activation_key' => $key ) ) );
78
79 wppb_add_meta_to_user_on_activation( $user_id, '', $meta );
80
81 // if admin approval is activated, then block the user untill he gets approved
82 $wppb_generalSettings = get_option('wppb_general_settings');
83 if( isset( $wppb_generalSettings['adminApproval'] ) && ( $wppb_generalSettings['adminApproval'] == 'yes' ) ){
84 $user_data = get_userdata( $user_id );
85
86 if( $wppb_generalSettings != 'not_found' && ! empty( $wppb_generalSettings['adminApprovalOnUserRole'] ) ) {
87 foreach( $user_data->roles as $role ) {
88 if( in_array( $role, $wppb_generalSettings['adminApprovalOnUserRole'] ) ) {
89 wp_set_object_terms( $user_id, array( 'unapproved' ), 'user_status', false);
90 clean_object_term_cache( $user_id, 'user_status' );
91 } else {
92 add_filter( 'wppb_register_success_message', 'wppb_noAdminApproval_successMessage' );
93 }
94 }
95 } else {
96 wp_set_object_terms( $user_id, array( 'unapproved' ), 'user_status', false);
97 clean_object_term_cache( $user_id, 'user_status' );
98 }
99 }
100
101 if ( !isset( $wppb_generalSettings['adminApproval'] ) )
102 $wppb_generalSettings['adminApproval'] = 'no';
103
104 /* copy the hashed password from signup meta to wp user table */
105 if( !empty( $meta['user_pass'] ) ){
106 /* we might still have the base64 encoded password in signups and not the hash */
107 if( base64_encode(base64_decode($meta['user_pass'], true)) === $meta['user_pass'] )
108 $meta['user_pass'] = wp_hash_password( $meta['user_pass'] );
109
110 $wpdb->update( $wpdb->users, array('user_pass' => $meta['user_pass'] ), array('ID' => $user_id) );
111 wp_cache_delete( $user_id, 'users' );
112 }
113
114 wppb_notify_user_registration_email($bloginfo, $user_login, $user_email, 'sending', $password, $wppb_generalSettings['adminApproval']);
115
116 do_action( 'wppb_activate_user', $user_id, $password, $meta );
117
118 if( $inserted_user ) {
119 // CHECK FOR REDIRECT
120 $redirect_url = wppb_get_redirect_url( 'normal', 'after_success_email_confirmation', '', $user_login );
121 $redirect_delay = apply_filters( 'wppb_success_email_confirmation_redirect_delay', 3, $user_id );
122 $redirect_message = wppb_build_redirect( $redirect_url, $redirect_delay, 'after_success_email_confirmation' );
123
124 $success_message = apply_filters( 'wppb_success_email_confirmation', '<p class="wppb-success">' . __( 'Your email was successfully confirmed.', 'profile-builder' ) . '</p><!-- .success -->', $user_id );
125 $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.', 'profile-builder' ) . '</p>', $user_id );
126
127 $wppb_general_settings = get_option( 'wppb_general_settings', 'false' );
128
129 if ( !empty( $wppb_general_settings['adminApproval'] ) && $wppb_general_settings['adminApproval'] == 'yes' ){
130 $user_data = get_userdata( $user_id );
131
132 if( $wppb_general_settings != 'not_found' && ! empty( $wppb_general_settings['adminApprovalOnUserRole'] ) ) {
133 foreach( $user_data->roles as $role ) {
134 if( in_array( $role, $wppb_general_settings['adminApprovalOnUserRole'] ) ) {
135 return $success_message . $admin_approval_message . ( ! empty ( $redirect_message ) ? $redirect_message : '' );
136 } else {
137 wp_set_object_terms( $user_id, NULL, 'user_status' );
138 clean_object_term_cache( $user_id, 'user_status' );
139
140 return $success_message . ( ! empty ( $redirect_message ) ? $redirect_message : '' );
141 }
142 }
143 } else {
144 return $success_message . $admin_approval_message . ( ! empty ( $redirect_message ) ? $redirect_message : '' );
145 }
146 } else {
147 wp_set_object_terms( $user_id, NULL, 'user_status' );
148 clean_object_term_cache( $user_id, 'user_status' );
149
150 return $success_message . ( ! empty ( $redirect_message ) ? $redirect_message : '' );
151 }
152 } else {
153 return apply_filters('wppb_register_failed_user_activation', '<p class="error">'. __('There was an error while trying to activate the user.', 'profile-builder') .'</p><!-- .error -->');
154 }
155 }
156 }
157
158 //function to display the registration page
159 function wppb_front_end_register( $atts ){
160 extract( shortcode_atts( array( 'role' => get_option( 'default_role' ), 'form_name' => 'unspecified', 'redirect_url' => '', 'logout_redirect_url' => '', 'redirect_priority' => 'normal' ), $atts, 'wppb-register' ) );
161
162 global ${$form_name};
163
164 $$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' ) ) , 'redirect_url' => $redirect_url, 'logout_redirect_url' => $logout_redirect_url, 'redirect_priority' => $redirect_priority ) );
165
166 return $$form_name;
167 }
168
169 // function to choose whether to display the registration page or the validation message
170 function wppb_front_end_register_handler( $atts ){
171
172 return ( isset( $_GET['activation_key'] ) ? wppb_activate_signup ( sanitize_text_field( $_GET['activation_key'] ) ) : wppb_front_end_register( $atts ) );
173 }
174
175 add_action( 'user_register', 'wppbc_disable_admin_approval_for_user_role', 99, 1 );
176 function wppbc_disable_admin_approval_for_user_role( $user_id ) {
177 if ( current_user_can( 'delete_users' ) ) {
178 wp_set_object_terms( $user_id, NULL, 'user_status' );
179 clean_object_term_cache( $user_id, 'user_status' );
180 }
181 }
182
183 /* authors and contributors shouldn't be allowed to create pages with the register shortcode in them */
184 add_filter( 'the_content', 'wppb_maybe_remove_register_shortcode' );
185 function wppb_maybe_remove_register_shortcode( $content ){
186 if ( has_shortcode( $content, 'wppb-register' ) ){
187 $author_id = get_the_author_meta( 'ID' );
188 if( !empty( $author_id ) ){
189 if( !user_can( $author_id, 'edit_others_posts' ) ) {
190 remove_shortcode('wppb-register');
191 }
192 }
193 }
194
195 return $content;
196 }
197
198 /* custom redirect after registration on wp default register form */
199 function wppb_default_registration_redirect( $user_id ) {
200
201 $user_data = get_userdata( $user_id );
202
203 // CHECK FOR REDIRECT
204 $_POST['redirect_to'] = wppb_get_redirect_url( 'normal', 'after_registration', $_POST['redirect_to'], $user_data );
205 $_POST['redirect_to'] = apply_filters( 'wppb_after_registration_redirect_url', $_POST['redirect_to'] );
206
207 }
208 add_action( 'register_new_user', 'wppb_default_registration_redirect' );