PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.0.4
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.0.4
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.0.4, at front-end/register.php

120 lines 5.8 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 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 $password = base64_decode( $meta['user_pass'] );
58
59 $user_id = username_exists( $user_login );
60
61 if ( !$user_id )
62 $user_id = wppb_create_user( $user_login, $password, $user_email );
63 else
64 $user_already_exists = true;
65
66 if ( ! $user_id )
67 return apply_filters( 'wppb_register_activate_user_error_message4', '<p class="error">'.__('Could not create user!', 'profilebuilder').'</p>' );
68
69 elseif ( isset( $user_already_exists ) && ( $user_already_exists == true ) )
70 return apply_filters( 'wppb_register_activate_user_error_message5', '<p class="error">'.__( 'This username is already activated!', 'profilebuilder' ).'</p>' );
71
72 else{
73 $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 ) ) );
74
75 wppb_add_meta_to_user_on_activation( $user_id, '', $meta );
76
77 // if admin approval is activated, then block the user untill he gets approved
78 $wppb_generalSettings = get_option('wppb_general_settings');
79 if ( isset( $wppb_generalSettings['adminApproval'] ) && ( $wppb_generalSettings['adminApproval'] == 'yes' ) ){
80 wp_set_object_terms( $user_id, array( 'unapproved' ), 'user_status', false );
81 clean_object_term_cache( $user_id, 'user_status' );
82 }
83
84 if ( !isset( $wppb_generalSettings['adminApproval'] ) )
85 $wppb_generalSettings['adminApproval'] = 'no';
86
87 wppb_notify_user_registration_email($bloginfo, $user_login, $user_email, 'sending', $password, $wppb_generalSettings['adminApproval']);
88
89 do_action( 'wppb_activate_user', $user_id, $password, $meta );
90
91 if ( $inserted_user ){
92 $success_message = apply_filters('wppb_success_email_confirmation', '<p class="wppb-success">'. __('Your email was successfully confirmed.', 'profilebuilder') .'</p><!-- .success -->');
93 $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>' );
94
95 $wppb_general_settings = get_option( 'wppb_general_settings', 'false' );
96 if ( !empty( $wppb_general_settings['adminApproval'] ) && $wppb_general_settings['adminApproval'] == 'yes' ){
97 return $success_message . $admin_approval_message;
98 } else {
99 return $success_message;
100 }
101 } else {
102 return apply_filters('wppb_register_failed_user_activation', '<p class="error">'. __('There was an error while trying to activate the user.', 'profilebuilder') .'</p><!-- .error -->');
103 }
104 }
105 }
106
107 //function to display the registration page
108 function wppb_front_end_register( $atts ){
109 extract( shortcode_atts( array( 'role' => get_option( 'default_role' ), 'form_name' => 'unspecified' ), $atts, 'wppb-register' ) );
110 global $$form_name;
111 $$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' ) ) ) );
112
113 return $$form_name;
114 }
115
116 // function to choose whether to display the registration page or the validation message
117 function wppb_front_end_register_handler( $atts ){
118
119 return ( isset( $_GET['activation_key'] ) ? wppb_activate_signup ( $_GET['activation_key'] ) : wppb_front_end_register( $atts ) );
120 }