PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.11
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.11
1.2.74 1.2.73 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 All 174 releases
← All changes | includes/class-account.php +118 -152 trunk1.2.11 View file →
@@ -8,13 +8,10 @@
8 8 class UsersWP_Account {
9 9
10 10
11 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 - add_filter( 'uwp_get_account_deletion_message', array( $this, 'get_deletion_message' ), 10, 2 );
16 - add_action( 'uwp_send_account_deletion_emails', array( $this, 'send_account_deletion_emails' ), 10, 2 );
12 + add_action( 'uwp_account_form_display', array($this, 'display_form'), 10, 1 );
13 + add_action('init', array($this, 'submit_handler'));
17 14 }
18 15
19 16 /**
20 17 * Displays the account form
@@ -23,27 +20,26 @@
23 20 *
24 21 * @param array $type Type of the form
25 22 *
26 23 */
27 - public function display_form( $type ) {
28 - if ( $type == 'account' ) {
29 - $design_style = uwp_get_option( 'design_style', 'bootstrap' );
30 - $bs_btn_class = $design_style ? 'btn btn-primary btn-block text-uppercase' : '';
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" : "";
31 28 ?>
32 29 <form class="uwp-account-form uwp_form mt-3" method="post" enctype="multipart/form-data">
33 - <?php do_action( 'uwp_template_fields', 'account' ); ?>
30 + <?php do_action('uwp_template_fields', 'account'); ?>
34 31 <input type="hidden" name="uwp_account_nonce" value="<?php echo esc_attr( wp_create_nonce( 'uwp-account-nonce' ) ); ?>" />
35 32 <input name="uwp_account_submit" class="<?php echo esc_attr( $bs_btn_class ); ?>" value="<?php esc_attr_e( 'Update Account', 'userswp' ); ?>" type="submit">
36 33 </form>
37 - <?php
38 - }
34 + <?php }
39 35
40 - if ( $type == 'change-password' ) {
41 - $design_style = uwp_get_option( 'design_style', 'bootstrap' );
42 - $bs_btn_class = $design_style ? 'btn btn-primary btn-block text-uppercase' : '';
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" : "";
43 39 ?>
44 40 <form class="uwp-account-form uwp_form mt-3" method="post" enctype="multipart/form-data">
45 - <?php do_action( 'uwp_template_fields', 'change' ); ?>
41 + <?php do_action('uwp_template_fields', 'change'); ?>
46 42 <input name="uwp_change_submit" class="<?php echo esc_attr( $bs_btn_class ); ?>" value="<?php esc_attr_e( 'Change Password', 'userswp' ); ?>" type="submit">
47 43 </form>
48 44 <?php
49 45 uwp_password_strength_inline_js();
@@ -48,10 +44,10 @@
48 44 <?php
49 45 uwp_password_strength_inline_js();
50 46 }
51 47
52 - if ( $type == 'delete-account' ) {
53 - if ( 1 == uwp_get_option( 'disable_account_delete' ) || current_user_can( 'administrator' ) ) {
48 + if ($type == 'delete-account') {
49 + if(1 == uwp_get_option('disable_account_delete') || current_user_can('administrator')){
54 50 return;
55 51 }
56 52 ?>
57 53 <form class="uwp-account-form uwp_form mt-3" method="post" enctype="multipart/form-data">
@@ -56,36 +52,35 @@
56 52 ?>
57 53 <form class="uwp-account-form uwp_form mt-3" method="post" enctype="multipart/form-data">
58 54
59 55 <?php
60 - $design_style = uwp_get_option( 'design_style', 'bootstrap' );
61 - $bs_btn_class = $design_style ? 'btn btn-primary btn-block text-uppercase' : '';
56 + $design_style = uwp_get_option("design_style","bootstrap");
57 + $bs_btn_class = $design_style ? "btn btn-primary btn-block text-uppercase" : "";
62 58
63 - do_action( 'uwp_template_fields', 'delete-account' );
59 + do_action('uwp_template_fields', 'delete-account');
64 60
65 61 $fields = (object) array(
66 - 'htmlvar_name' => 'password',
67 - 'field_type' => 'password',
68 - 'data_type' => 'VARCHAR',
62 + 'htmlvar_name' => 'password',
63 + 'field_type' => 'password',
64 + 'data_type' => 'VARCHAR',
69 65 'default_value' => '',
70 - 'is_required' => 1,
71 - 'help_text' => '',
72 - 'form_label' => __( 'Password', 'userswp' ),
73 - 'site_title' => __( 'Password', 'userswp' ),
66 + 'is_required' => 1,
67 + 'help_text' => '',
68 + 'form_label' => __('Password', 'userswp'),
69 + 'site_title' => __('Password', 'userswp'),
74 70 );
75 71
76 72 $obj = new UsersWP_Templates();
77 - $obj->template_fields_html( $fields, 'delete-account' );
73 + $obj->template_fields_html($fields, 'delete-account');
78 74
79 75 ?>
80 76 <input type="hidden" name="uwp_delete_account_nonce" value="<?php echo esc_attr( wp_create_nonce( 'uwp-delete-account-nonce' ) ); ?>" />
81 77 <input name="uwp_delete_account_submit" class="<?php echo esc_attr( $bs_btn_class ); ?>" value="<?php esc_attr_e( 'Delete Account', 'userswp' ); ?>" type="submit">
82 78 </form>
83 - <?php
84 - }
79 + <?php }
85 80
86 - if ( $type == 'wp2fa' && class_exists( '\WP2FA\WP2FA' ) ) {
87 - if ( 1 == uwp_get_option( 'disable_wp_2fa' ) ) {
81 + if($type == 'wp2fa' && class_exists('\WP2FA\WP2FA')){
82 + if(1 == uwp_get_option('disable_wp_2fa')){
88 83 return;
89 84 }
90 85 echo do_shortcode( '[wp-2fa-setup-form]' );
91 86 }
@@ -93,153 +88,124 @@
93 88
94 89 /**
95 90 * Handles the delete account form submission.
96 91 *
97 - * @since 1.2.1.2
98 - * @return void
92 + * @since 1.2.1.2
93 + * @package userswp
94 + *
95 + * @return void
99 96 */
100 97 public function submit_handler() {
101 - if ( ! isset( $_POST['uwp_delete_account_submit'] ) ) {
102 - return;
103 - }
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 + }
104 102
105 - if ( ! isset( $_POST['uwp_delete_account_nonce'] ) || ! wp_verify_nonce( $_POST['uwp_delete_account_nonce'], 'uwp-delete-account-nonce' ) ) {
106 - return;
107 - }
103 + global $uwp_notices;
108 104
109 - global $uwp_notices;
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() );
110 108
111 - $password = isset( $_POST['password'] ) ? sanitize_text_field( $_POST['password'] ) : '';
112 - $user_id = get_current_user_id();
113 - $user = get_user_by( 'id', $user_id );
109 + do_action('uwp_before_delete_account', $user_id);
114 110
115 - do_action( 'uwp_before_delete_account', $user_id );
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 + );
116 118
117 - if ( ! wp_check_password( $password, $user->data->user_pass, $user->ID ) ) {
118 - $uwp_notices[] = array(
119 - 'account' => aui()->alert(
120 - array(
121 - 'type' => 'error',
122 - 'content' => __( '<strong>Error</strong>: Incorrect password.', 'userswp' ),
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()
123 130 )
124 - ),
125 - );
126 - return;
127 - }
131 + );
128 132
129 - $errors = apply_filters( 'uwp_delete_account_validate', $user );
133 + $uwp_notices[] = array('account' => $message );
134 + return;
135 + }
130 136
131 - if ( ! empty( $errors->get_error_code() ) ) {
132 - $uwp_notices[] = array(
133 - 'account' => aui()->alert(
134 - array(
135 - 'type' => 'error',
136 - 'content' => $errors->get_error_message(),
137 - )
138 - ),
139 - );
140 - return;
141 - }
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;
142 140
143 - $ms_delete = apply_filters( 'uwp_delete_delete_from_network', true );
144 - $num_blogs_of_user = is_multisite() ? count( get_blogs_of_user( $user_id ) ) : 1;
145 - $delete_from_network = ( is_multisite() && ( $ms_delete == true || $num_blogs_of_user == 1 ) ) ? true : false;
141 + include_once( ABSPATH . 'wp-admin/includes/user.php' );
146 142
147 - include_once ABSPATH . 'wp-admin/includes/user.php';
143 + if ( is_multisite() ) {
148 144
149 - if ( is_multisite() ) {
150 - include_once ABSPATH . WPINC . '/ms-functions.php';
151 - include_once ABSPATH . 'wp-admin/includes/ms.php';
152 - }
145 + include_once( ABSPATH . WPINC . '/ms-functions.php' );
146 + include_once( ABSPATH . 'wp-admin/includes/ms.php' );
153 147
154 - $message = $this->get_deletion_message( '', $user );
148 + }
155 149
156 - if ( $delete_from_network ) {
157 - if ( in_array( $user->user_login, get_super_admins(), true ) ) {
158 - $uwp_notices[] = array(
159 - 'account' => aui()->alert(
160 - array(
161 - 'type' => 'error',
162 - 'content' => __( '<strong>Error</strong>: Super Administrators cannot be deleted.', 'userswp' ),
163 - )
164 - ),
165 - );
166 - return;
167 - }
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>';
168 155
169 - $deleted = wpmu_delete_user( $user_id );
170 - } else {
171 - $deleted = wp_delete_user( $user_id );
172 - }
156 + $message = apply_filters('uwp_account_delete_mail_message', $message, $user_id);
173 157
174 - if ( $deleted ) {
175 - $this->send_account_deletion_emails( $user, $message );
176 - }
158 + $user_email = sanitize_email( $user->user_email );
159 + $user_name = !empty($user->display_name) ? esc_attr( $user->display_name ) :'';
177 160
178 - do_action( 'uwp_after_delete_account', $user_id, $deleted );
161 + // Delete user
162 + if ( $delete_from_network ) {
179 163
180 - wp_logout();
181 - wp_safe_redirect( home_url() );
182 - exit();
183 - }
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 + );
184 172
185 - /**
186 - * Generate the account deletion message.
187 - *
188 - * @since 1.2.28
189 - * @param string $message The initial message (empty by default).
190 - * @param WP_User $user The user being deleted.
191 - * @return string The formatted deletion message.
192 - */
193 - public function get_deletion_message( $message, $user ) {
194 - $message_parts = array(
195 - 'header' => '<p><strong>' . esc_html__( 'Deleted user information:', 'userswp' ) . '</strong></p>',
196 - 'first_name' => '<p>' . esc_html__( 'First Name:', 'userswp' ) . ' ' . esc_html( $user->first_name ) . '</p>',
197 - 'last_name' => '<p>' . esc_html__( 'Last Name:', 'userswp' ) . ' ' . esc_html( $user->last_name ) . '</p>',
198 - 'username' => '<p>' . esc_html__( 'Username:', 'userswp' ) . ' ' . esc_html( $user->user_login ) . '</p>',
199 - 'email' => '<p>' . esc_html__( 'Email:', 'userswp' ) . ' ' . esc_html( $user->user_email ) . '</p>',
200 - );
173 + $uwp_notices[] = array('account' => $message );
174 + return;
175 + }
201 176
202 - /**
203 - * Filters the account deletion message parts.
204 - *
205 - * @since 1.2.28
206 - * @param array $message_parts The message parts.
207 - * @param WP_User $user The user being deleted.
208 - */
209 - $message_parts = apply_filters( 'uwp_account_deletion_message_parts', $message_parts, $user );
177 + $deleted = wpmu_delete_user( $user_id );
210 178
211 - $message .= implode( '', $message_parts );
179 + } else {
212 180
213 - /**
214 - * Filters the final account deletion message.
215 - *
216 - * @since 1.2.28
217 - * @param string $message The deletion message.
218 - * @param WP_User $user The user being deleted.
219 - */
220 - return apply_filters( 'uwp_account_deletion_message', $message, $user );
221 - }
181 + $deleted = wp_delete_user( $user_id );
222 182
223 - /**
224 - * Sends account deletion emails.
225 - *
226 - * @since 1.2.28
227 - * @param WP_User $user The user being deleted.
228 - * @param string $message The deletion message.
229 - */
230 - public function send_account_deletion_emails( $user, $message ) {
231 - $email_vars = array(
232 - 'login_details' => $message,
233 - 'user_name' => ! empty( $user->display_name ) ? esc_attr( $user->display_name ) : '',
234 - );
183 + }
235 184
236 - do_action( 'uwp_before_account_delete_email', $user, $email_vars );
185 + // notify on successful deletion.
186 + if($deleted){
237 187
238 - UsersWP_Mails::send( $user->user_email, 'account_delete', $email_vars );
239 - UsersWP_Mails::send( get_bloginfo( 'admin_email' ), 'account_delete', $email_vars, true );
188 + $email_vars = array();
189 + $email_vars['login_details'] = $message;
190 + $email_vars['user_name'] = $user_name;
240 191
241 - do_action( 'uwp_after_account_delete_email', $user, $email_vars );
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 + }
242 208 }
243 209 }
244 210
245 -new UsersWP_Account();
211 +new UsersWP_Account();