PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.3.4
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.3.4
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / includes / class-account.php

class-account.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.3.4, at includes/class-account.php

211 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * User account related functions
4 *
5 * @since 1.2.1.2
6 * @author GeoDirectory Team <info@wpgeodirectory.com>
7 */
8 class UsersWP_Account {
9
10
11 public function __construct() {
12 add_action( 'uwp_account_form_display', array($this, 'display_form'), 10, 1 );
13 add_action('init', array($this, 'submit_handler'));
14 }
15
16 /**
17 * Displays the account form
18 *
19 * @since 1.0.0
20 *
21 * @param array $type Type of the form
22 *
23 */
24 public function display_form($type){
25 if ($type == 'account') {
26 $design_style = uwp_get_option("design_style","bootstrap");
27 $bs_btn_class = $design_style ? "btn btn-primary btn-block text-uppercase" : "";
28 ?>
29 <form class="uwp-account-form uwp_form mt-3" method="post" enctype="multipart/form-data">
30 <?php do_action('uwp_template_fields', 'account'); ?>
31 <input type="hidden" name="uwp_account_nonce" value="<?php echo wp_create_nonce( 'uwp-account-nonce' ); ?>" />
32 <input name="uwp_account_submit" class="<?php echo $bs_btn_class; ?>" value="<?php _e( 'Update Account', 'userswp' ); ?>" type="submit">
33 </form>
34 <?php }
35
36 if ($type == 'change-password') {
37 $design_style = uwp_get_option("design_style","bootstrap");
38 $bs_btn_class = $design_style ? "btn btn-primary btn-block text-uppercase" : "";
39 ?>
40 <form class="uwp-account-form uwp_form mt-3" method="post" enctype="multipart/form-data">
41 <?php do_action('uwp_template_fields', 'change'); ?>
42 <input name="uwp_change_submit" class="<?php echo $bs_btn_class; ?>" value="<?php _e( 'Change Password', 'userswp' ); ?>" type="submit">
43 </form>
44 <?php
45 uwp_password_strength_inline_js();
46 }
47
48 if ($type == 'delete-account') {
49 if(1 == uwp_get_option('disable_account_delete') || current_user_can('administrator')){
50 return;
51 }
52 ?>
53 <form class="uwp-account-form uwp_form mt-3" method="post" enctype="multipart/form-data">
54
55 <?php
56 $design_style = uwp_get_option("design_style","bootstrap");
57 $bs_btn_class = $design_style ? "btn btn-primary btn-block text-uppercase" : "";
58
59 do_action('uwp_template_fields', 'delete-account');
60
61 $fields = (object) array(
62 'htmlvar_name' => 'password',
63 'field_type' => 'password',
64 'data_type' => 'VARCHAR',
65 'default_value' => '',
66 'is_required' => 1,
67 'help_text' => '',
68 'form_label' => __('Password', 'userswp'),
69 'site_title' => __('Password', 'userswp'),
70 );
71
72 $obj = new UsersWP_Templates();
73 $obj->template_fields_html($fields, 'delete-account');
74
75 ?>
76 <input type="hidden" name="uwp_delete_account_nonce" value="<?php echo wp_create_nonce( 'uwp-delete-account-nonce' ); ?>" />
77 <input name="uwp_delete_account_submit" class="<?php echo $bs_btn_class; ?>" value="<?php _e( 'Delete Account', 'userswp' ); ?>" type="submit">
78 </form>
79 <?php }
80
81 if($type == 'wp2fa' && class_exists('\WP2FA\WP2FA')){
82 if(1 == uwp_get_option('disable_wp_2fa')){
83 return;
84 }
85 echo do_shortcode( '[wp-2fa-setup-form]' );
86 }
87 }
88
89 /**
90 * Handles the delete account form submission.
91 *
92 * @since 1.2.1.2
93 * @package userswp
94 *
95 * @return void
96 */
97 public function submit_handler() {
98 if (isset($_POST['uwp_delete_account_submit'])) {
99 if( ! isset( $_POST['uwp_delete_account_nonce'] ) || ! wp_verify_nonce( $_POST['uwp_delete_account_nonce'], 'uwp-delete-account-nonce' ) ) {
100 return;
101 }
102
103 global $uwp_notices;
104
105 $password = isset($_POST['password']) ? sanitize_text_field($_POST['password']) : "";
106 $user_id = get_current_user_id();
107 $user = get_user_by( 'id', get_current_user_id() );
108
109 do_action('uwp_before_delete_account', $user_id);
110
111 //check password
112 if ( !wp_check_password( $password, $user->data->user_pass, $user->ID) ) {
113 $message = aui()->alert(array(
114 'type'=>'error',
115 'content'=> __( '<strong>Error</strong>: Incorrect password.', 'userswp' )
116 )
117 );
118
119 $uwp_notices[] = array('account' => $message );
120 return;
121 }
122
123 $errors = apply_filters('uwp_delete_account_validate', $user);
124
125 $error_code = $errors->get_error_code();
126 if (!empty($error_code)) {
127 $message = aui()->alert(array(
128 'type'=>'error',
129 'content'=> $errors->get_error_message()
130 )
131 );
132
133 $uwp_notices[] = array('account' => $message );
134 return;
135 }
136
137 $ms_delete = apply_filters('uwp_delete_delete_from_network', true);
138 $num_blogs_of_user = is_multisite() ? count( get_blogs_of_user( $user_id ) ) : 1;
139 $delete_from_network = ( is_multisite() && ( $ms_delete == true || $num_blogs_of_user == 1 ) ) ? true : false;
140
141 include_once( ABSPATH . 'wp-admin/includes/user.php' );
142
143 if ( is_multisite() ) {
144
145 include_once( ABSPATH . WPINC . '/ms-functions.php' );
146 include_once( ABSPATH . 'wp-admin/includes/ms.php' );
147
148 }
149
150 $message = '<p><b>' . __('Deleted user information :', 'userswp') . '</b></p>
151 <p>' . __('First Name:', 'userswp') . ' ' . esc_attr( $user->first_name ) . '</p>
152 <p>' . __('Last Name:', 'userswp') . ' ' . esc_attr( $user->last_name ) . '</p>
153 <p>' . __('Username:', 'userswp') . ' ' . esc_attr( $user->user_login ). '</p>
154 <p>' . __('Email:', 'userswp') . ' ' . sanitize_email( $user->user_email ) . '</p>';
155
156 $message = apply_filters('uwp_account_delete_mail_message', $message, $user_id);
157
158 $user_email = sanitize_email( $user->user_email );
159 $user_name = !empty($user->display_name) ? esc_attr( $user->display_name ) :'';
160
161 // Delete user
162 if ( $delete_from_network ) {
163
164 // Global super-administrators are protected, and cannot be deleted.
165 $_super_admins = get_super_admins();
166 if ( in_array( $user->user_login, $_super_admins, true ) ) {
167 $message = aui()->alert(array(
168 'type'=>'error',
169 'content'=> __( '<strong>Error</strong>: Super Administrators cannot be deleted.', 'userswp' )
170 )
171 );
172
173 $uwp_notices[] = array('account' => $message );
174 return;
175 }
176
177 $deleted = wpmu_delete_user( $user_id );
178
179 } else {
180
181 $deleted = wp_delete_user( $user_id );
182
183 }
184
185 // notify on successful deletion.
186 if($deleted){
187
188 $email_vars = array();
189 $email_vars['login_details'] = $message;
190 $email_vars['user_name'] = $user_name;
191
192 UsersWP_Mails::send($user_email, 'account_delete', $email_vars);
193
194 UsersWP_Mails::send(get_bloginfo('admin_email'), 'account_delete', $email_vars, true);
195 }
196
197
198 do_action('uwp_after_delete_account', $user_id, $deleted);
199
200 // Logout
201 wp_logout();
202
203 // Redirect after deletion
204 $redirect_page = home_url();
205 wp_safe_redirect($redirect_page);
206 exit();
207 }
208 }
209 }
210
211 new UsersWP_Account();