PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / trunk
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress vtrunk
4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / ShortcodeParser / Builder / PasswordResetBuilder.php
wp-user-avatar / src / ShortcodeParser / Builder Last commit date
EditProfileBuilder.php 3 years ago FieldsShortcodeCallback.php 4 months ago FrontendProfileBuilder.php 10 months ago GlobalShortcodes.php 3 years ago LoginFormBuilder.php 2 years ago PasswordResetBuilder.php 1 month ago RegistrationFormBuilder.php 1 year ago index.php 5 years ago
PasswordResetBuilder.php
374 lines
1 <?php
2
3 namespace ProfilePress\Core\ShortcodeParser\Builder;
4
5 use ProfilePress\Core\Classes\FormRepository;
6
7 class PasswordResetBuilder
8 {
9 public function __construct()
10 {
11 add_shortcode('user-login', array($this, 'user_login'));
12 add_shortcode('reset-submit', array($this, 'submit_button'));
13
14 add_shortcode('enter-password', array($this, 'enter_password'));
15 add_shortcode('re-enter-password', array($this, 're_enter_password'));
16 add_shortcode('password-reset-submit', array($this, 'password_reset_submit'));
17
18 add_shortcode('reset-password-meter', array($this, 'password_meter'));
19
20 do_action('ppress_register_password_reset_form_shortcode');
21 }
22
23 /**
24 * parse the [user-login] shortcode
25 *
26 * @param array $atts
27 *
28 * @return string
29 */
30 public function user_login($atts)
31 {
32 // grab unofficial attributes
33 $other_atts_html = ppress_other_field_atts($atts);
34
35 $placeholder = esc_html__('Username or Email', 'wp-user-avatar');
36
37 $atts = shortcode_atts(
38 array(
39 'class' => '',
40 'id' => '',
41 'value' => '',
42 'title' => $placeholder,
43 'placeholder' => $placeholder,
44 ),
45 $atts
46 );
47
48 $atts = apply_filters('ppress_password_reset_username_field_atts', $atts);
49
50 $class = 'class="' . esc_attr($atts['class']) . '"';
51 $placeholder = 'placeholder="' . esc_attr($atts['placeholder']) . '"';
52 $id = ! empty($atts['id']) ? 'id="' . esc_attr($atts['id']) . '"' : null;
53 $value = isset($_POST['user_login']) ? 'value="' . esc_attr($_POST['user_login']) . '"' : 'value=""';
54
55 $title = 'title="' . esc_attr($atts['title']) . '"';
56
57 $html = "<input name=\"user_login\" type='text' $title $value $class $id $placeholder $other_atts_html required='required'/>";
58
59 return apply_filters('ppress_password_reset_username_field', $html, $atts);
60 }
61
62 protected function get_processing_label($atts)
63 {
64 $form_type = FormRepository::PASSWORD_RESET_TYPE;
65 $form_id = isset($GLOBALS['pp_password_reset_form_id']) ? esc_attr($GLOBALS['pp_password_reset_form_id']) : 0;
66
67 if (isset($GLOBALS['pp_melange_form_id'])) {
68 $form_id = esc_html($GLOBALS['pp_melange_form_id']);
69 $form_type = FormRepository::MELANGE_TYPE;
70 }
71
72 return ! empty($atts['processing_label']) ? esc_attr($atts['processing_label']) : FormRepository::get_processing_label($form_id, $form_type);
73 }
74
75 /**
76 * Password reset submit button.
77 *
78 * @param $atts array shortcode param
79 *
80 * @return string HTML submit button
81 */
82 public function submit_button($atts)
83 {
84 // grab unofficial attributes
85 $other_atts_html = ppress_other_field_atts($atts);
86
87 $atts = shortcode_atts(
88 array(
89 'class' => '',
90 'id' => '',
91 'value' => '',
92 'title' => '',
93 'processing_label' => '',
94 'name' => 'password_reset_submit',
95 ),
96 $atts
97 );
98
99
100 $atts = apply_filters('ppress_password_reset_submit_field_atts', $atts);
101
102 $name = 'name="' . esc_attr($atts['name']) . '"';
103 $class = 'class="pp-submit-form ' . esc_attr($atts['class']) . '"';
104 $id = ! empty($atts['id']) ? 'id="' . esc_attr($atts['id']) . '"' : '';
105
106 $value = ! empty($atts['value']) ? esc_attr($atts['value']) : esc_html__('Get New Password', 'wp-user-avatar');
107
108 $title = 'title="' . esc_attr($atts['title']) . '"';
109
110 $html = sprintf(
111 '<input data-pp-submit-label="%2$s" data-pp-processing-label="%3$s" type="submit" value="%2$s" %1$s>',
112 "$name $title $class $id $other_atts_html",
113 $value,
114 $this->get_processing_label($atts)
115 );
116
117 return apply_filters('ppress_password_reset_submit_field', $html, $atts);
118 }
119
120
121 /**
122 * parse the [enter-password] shortcode
123 *
124 * @param array $atts
125 *
126 * @return string
127 */
128 public function enter_password($atts)
129 {
130 // grab unofficial attributes
131 $other_atts_html = ppress_other_field_atts($atts);
132
133 $atts = shortcode_atts(
134 array(
135 'class' => '',
136 'id' => '',
137 'value' => '',
138 'title' => '',
139 'placeholder' => '',
140 ),
141 $atts
142 );
143
144 $atts = apply_filters('ppress_password_reset_handler_password1_field_atts', $atts);
145
146 $class = 'class="' . esc_attr($atts['class']) . '"';
147 $placeholder = 'placeholder="' . esc_attr($atts['placeholder']) . '"';
148 $id = ! empty($atts['id']) ? 'id="' . esc_attr($atts['id']) . '"' : null;
149 $value = 'value=""';
150
151 $title = 'title="' . esc_attr($atts['title']) . '"';
152
153 $html = "<input name=\"password1\" type='password' $title $value $class $id $placeholder $other_atts_html autocomplete='off'>";
154
155 return apply_filters('ppress_password_reset_handler_password1_field', $html, $atts);
156 }
157
158
159 /**
160 * parse the [re-enter-password] shortcode
161 *
162 * @param array $atts
163 *
164 * @return string
165 */
166 function re_enter_password($atts)
167 {
168 // grab unofficial attributes
169 $other_atts_html = ppress_other_field_atts($atts);
170
171 $atts = shortcode_atts(
172 array(
173 'class' => '',
174 'id' => '',
175 'value' => '',
176 'title' => '',
177 'placeholder' => '',
178 ),
179 $atts
180 );
181
182 $atts = apply_filters('ppress_password_reset_handler_password2_field_atts', $atts);
183
184 $class = 'class="' . esc_attr($atts['class']) . '"';
185 $placeholder = 'placeholder="' . esc_attr($atts['placeholder']) . '"';
186 $id = ! empty($atts['id']) ? 'id="' . esc_attr($atts['id']) . '"' : null;
187 $value = 'value=""';
188
189 $title = 'title="' . esc_attr($atts['title']) . '"';
190
191 $html = "<input name=\"password2\" type='password' $title $value $class $id $placeholder $other_atts_html autocomplete='off'>";
192
193 return apply_filters('ppress_password_reset_handler_password2_field', $html, $atts);
194 }
195
196 /**
197 * Password strength meter field for password reset handler form.
198 * @see http://code.tutsplus.com/articles/using-the-included-password-strength-meter-script-in-wordpress--wp-34736
199 */
200 public static function password_meter($atts)
201 {
202 // grab unofficial attributes
203 $other_atts_html = ppress_other_field_atts($atts);
204
205 $atts = shortcode_atts(
206 array(
207 'class' => '',
208 'enforce' => 'true',
209 ),
210 $atts
211 );
212
213 $atts = apply_filters('ppress_password_reset_handler_meter_field_atts', $atts);
214
215 if (isset($atts['enforce']) && in_array($atts['enforce'], ['1', 'true', true], true)) {
216 $atts['enforce'] = 'true';
217 }
218
219 wp_localize_script('password-strength-meter', 'pwsL10n', array(
220 'empty' => esc_html__('Strength indicator', 'wp-user-avatar'),
221 'short' => esc_html__('Very weak', 'wp-user-avatar'),
222 'bad' => esc_html__('Weak', 'wp-user-avatar'),
223 'good' => _x('Medium', 'password strength', 'wp-user-avatar'),
224 'strong' => esc_html__('Strong', 'wp-user-avatar'),
225 'mismatch' => esc_html__('Mismatch', 'wp-user-avatar'),
226 ));
227
228 ob_start(); ?>
229 <?php if ('true' == $atts['enforce']) : ?>
230 <input type="hidden" name="pp_enforce_password_meter" value="true">
231 <?php endif; ?>
232 <div id="pp-pass-strength-result" <?php echo 'class="' . esc_attr($atts['class']) . '"' . $other_atts_html; ?>>
233 <?php _e('Strength indicator', 'wp-user-avatar'); ?>
234 </div>
235 <script type="text/javascript">
236 var pass_strength = 0;
237 jQuery(document).ready(function ($) {
238 var password1 = $('input[name=password1]');
239 var password2 = $('input[name=password2]');
240 var submitButton = $('input[name=reset_password]');
241 var strengthMeterId = $('#pp-pass-strength-result');
242
243 $('body').on('keyup', 'input[name=password1], input[name=password2]',
244 function (event) {
245 pp_checkPasswordStrength(password1, password2, strengthMeterId, submitButton, []);
246 }
247 );
248
249 if (password1.val() != '') {
250 // trigger 'keyup' event to check password strength when password field isn't empty.
251 $('body input[name=password1]').trigger('keyup');
252 }
253
254 submitButton.on('click', function () {
255 $('input[name=pp_enforce_password_meter]').val(pass_strength);
256 });
257 });
258
259 function pp_checkPasswordStrength($pass1, $pass2, $strengthResult, $submitButton, blacklistArray) {
260
261 var min_password_strength = <?php echo apply_filters('ppress_min_password_strength', 4); ?>;
262 var pass1 = $pass1.val();
263 var pass2 = $pass2.val();
264
265 <?php if('true' == $atts['enforce']) : ?>
266 // Reset the form & meter
267 $submitButton.attr('disabled', 'disabled').css("opacity", ".4");
268 <?php endif; ?>
269 $strengthResult.removeClass('short bad good strong');
270
271 // Extend our blacklist array with those from the inputs & site data
272 blacklistArray = blacklistArray.concat(wp.passwordStrength.userInputBlacklist());
273
274 // Get the password strength
275 var strength = wp.passwordStrength.meter(pass1, blacklistArray, pass2);
276
277 // Add the strength meter results
278 switch (strength) {
279
280 case 2:
281 $strengthResult.addClass('bad').html(pwsL10n.bad);
282 break;
283 case 3:
284 $strengthResult.addClass('good').html(pwsL10n.good);
285 if (min_password_strength === 3) {
286 pass_strength = 1;
287 }
288 break;
289 case 4:
290 $strengthResult.addClass('strong').html(pwsL10n.strong);
291 if (min_password_strength === 4) {
292 pass_strength = 1;
293 }
294 break;
295 case 5:
296 $strengthResult.addClass('short').html(pwsL10n.mismatch);
297 break;
298 default:
299 $strengthResult.addClass('short').html(pwsL10n.short);
300 }
301
302 // The meter function returns a result even if pass2 is empty,
303 // enable only the submit button if the password is strong
304 <?php if('true' == $atts['enforce']) : ?>
305 if (min_password_strength <= strength) {
306 $submitButton.removeAttr('disabled').css("opacity", "");
307 }
308 <?php endif; ?>
309
310 return strength;
311 }
312 </script>
313 <?php
314 return apply_filters('ppress_registration_password_meter_field', ob_get_clean(), $atts);
315 }
316
317 /**
318 * Password reset handler submit button.
319 *
320 * @param $atts array shortcode param
321 *
322 * @return string HTML submit button
323 */
324 function password_reset_submit($atts)
325 {
326 // grab unofficial attributes
327 $other_atts_html = ppress_other_field_atts($atts);
328
329 $atts = shortcode_atts(
330 array(
331 'class' => '',
332 'id' => '',
333 'title' => '',
334 'value' => '',
335 'processing_label' => '',
336 'name' => 'reset_password',
337 ),
338 $atts
339 );
340
341 $atts = apply_filters('ppress_password_reset_handler_submit_field_atts', $atts);
342
343 $name = 'name="' . esc_attr($atts['name']) . '"';
344 $class = 'class="pp-submit-form ' . esc_attr($atts['class']) . '"';
345
346 $value = ! empty($atts['value']) ? esc_attr($atts['value']) : esc_html__('Get New Password', 'wp-user-avatar');
347
348 $id = ! empty($atts['id']) ? 'id="' . esc_attr($atts['id']) . '"' : '';
349
350 $title = 'title="' . esc_attr($atts['title']) . '"';
351
352 $html = sprintf(
353 '<input data-pp-submit-label="%2$s" data-pp-processing-label="%3$s" type="submit" value="%2$s" %1$s>',
354 "$name $title $class $id $other_atts_html",
355 $value,
356 $this->get_processing_label($atts)
357 );
358
359 return apply_filters('ppress_password_reset_handler_submit_field', $html, $atts);
360 }
361
362
363 /** Singleton poop */
364 static function get_instance()
365 {
366 static $instance = false;
367 if ( ! $instance) {
368 $instance = new self;
369 }
370
371 return $instance;
372 }
373 }
374