PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.1
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.1
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 5 years ago FieldsShortcodeCallback.php 5 years ago FrontendProfileBuilder.php 5 years ago GlobalShortcodes.php 5 years ago LoginFormBuilder.php 5 years ago PasswordResetBuilder.php 5 years ago RegistrationFormBuilder.php 5 years ago builder-preview.php 5 years ago index.php 5 years ago
PasswordResetBuilder.php
363 lines
1 <?php namespace ProfilePress\Core\ShortcodeParser\Builder;
2
3 use ProfilePress\Core\Classes\FormRepository;
4
5 class PasswordResetBuilder
6 {
7 public function __construct()
8 {
9 add_shortcode('user-login', array($this, 'user_login'));
10 add_shortcode('reset-submit', array($this, 'submit_button'));
11
12 add_shortcode('enter-password', array($this, 'enter_password'));
13 add_shortcode('re-enter-password', array($this, 're_enter_password'));
14 add_shortcode('password-reset-submit', array($this, 'password_reset_submit'));
15
16 add_shortcode('reset-password-meter', array($this, 'password_meter'));
17
18 do_action('ppress_register_password_reset_form_shortcode');
19 }
20
21 /**
22 * parse the [user-login] shortcode
23 *
24 * @param array $atts
25 *
26 * @return string
27 */
28 public function user_login($atts)
29 {
30 // grab unofficial attributes
31 $other_atts_html = ppress_other_field_atts($atts);
32
33 $placeholder = esc_html__('Username or Email', 'wp-user-avatar');
34
35 $atts = shortcode_atts(
36 array(
37 'class' => '',
38 'id' => '',
39 'value' => '',
40 'title' => $placeholder,
41 'placeholder' => $placeholder,
42 ),
43 $atts
44 );
45
46 $atts = apply_filters('ppress_password_reset_username_field_atts', $atts);
47
48 $class = 'class="' . $atts['class'] . '"';
49 $placeholder = 'placeholder="' . $atts['placeholder'] . '"';
50 $id = ! empty($atts['id']) ? 'id="' . $atts['id'] . '"' : null;
51 $value = isset($_POST['user_login']) ? 'value="' . esc_attr($_POST['user_login']) . '"' : 'value=""';
52
53 $title = 'title="' . $atts['title'] . '"';
54
55 $html = "<input name=\"user_login\" type='text' $title $value $class $id $placeholder $other_atts_html required='required'/>";
56
57 return apply_filters('ppress_password_reset_username_field', $html, $atts);
58 }
59
60 protected function get_processing_label()
61 {
62 $form_type = FormRepository::PASSWORD_RESET_TYPE;
63 $form_id = isset($GLOBALS['pp_password_reset_form_id']) ? $GLOBALS['pp_password_reset_form_id'] : 0;
64
65 if (isset($GLOBALS['pp_melange_form_id'])) {
66 $form_id = $GLOBALS['pp_melange_form_id'];
67 $form_type = FormRepository::MELANGE_TYPE;
68 }
69
70 return ! empty($atts['processing_label']) ? $atts['processing_label'] : FormRepository::get_processing_label($form_id, $form_type);
71 }
72
73 /**
74 * Password reset submit button.
75 *
76 * @param $atts array shortcode param
77 *
78 * @return string HTML submit button
79 */
80 public function submit_button($atts)
81 {
82 // grab unofficial attributes
83 $other_atts_html = ppress_other_field_atts($atts);
84
85 $atts = shortcode_atts(
86 array(
87 'class' => '',
88 'id' => '',
89 'value' => '',
90 'title' => '',
91 'name' => 'password_reset_submit',
92 ),
93 $atts
94 );
95
96
97 $atts = apply_filters('ppress_password_reset_submit_field_atts', $atts);
98
99 $name = 'name="' . $atts['name'] . '"';
100 $class = 'class="pp-submit-form ' . $atts['class'] . '"';
101 $id = ! empty($atts['id']) ? 'id="' . $atts['id'] . '"' : '';
102
103 $value = ! empty($atts['value']) ? $atts['value'] : esc_html__('Get New Password', 'wp-user-avatar');
104
105 $title = 'title="' . $atts['title'] . '"';
106
107 $html = sprintf(
108 '<input data-pp-submit-label="%2$s" data-pp-processing-label="%3$s" type="submit" value="%2$s" %1$s>',
109 "$name $title $class $id $other_atts_html",
110 $value,
111 $this->get_processing_label()
112 );
113
114 return apply_filters('ppress_password_reset_submit_field', $html, $atts);
115 }
116
117
118 /**
119 * parse the [enter-password] shortcode
120 *
121 * @param array $atts
122 *
123 * @return string
124 */
125 public function enter_password($atts)
126 {
127 // grab unofficial attributes
128 $other_atts_html = ppress_other_field_atts($atts);
129
130 $atts = shortcode_atts(
131 array(
132 'class' => '',
133 'id' => '',
134 'value' => '',
135 'title' => '',
136 'placeholder' => '',
137 ),
138 $atts
139 );
140
141 $atts = apply_filters('ppress_password_reset_handler_password1_field_atts', $atts);
142
143 $class = 'class="' . $atts['class'] . '"';
144 $placeholder = 'placeholder="' . $atts['placeholder'] . '"';
145 $id = ! empty($atts['id']) ? 'id="' . $atts['id'] . '"' : null;
146 $value = isset($_POST['password1']) ? 'value="' . esc_attr($_POST['password1']) . '"' : 'value=""';
147
148 $title = 'title="' . $atts['title'] . '"';
149
150 $html = "<input name=\"password1\" type='password' $title $value $class $id $placeholder $other_atts_html autocomplete='off'>";
151
152 return apply_filters('ppress_password_reset_handler_password1_field', $html, $atts);
153 }
154
155
156 /**
157 * parse the [re-enter-password] shortcode
158 *
159 * @param array $atts
160 *
161 * @return string
162 */
163 function re_enter_password($atts)
164 {
165 // grab unofficial attributes
166 $other_atts_html = ppress_other_field_atts($atts);
167
168 $atts = shortcode_atts(
169 array(
170 'class' => '',
171 'id' => '',
172 'value' => '',
173 'title' => '',
174 'placeholder' => '',
175 ),
176 $atts
177 );
178
179 $atts = apply_filters('ppress_password_reset_handler_password2_field_atts', $atts);
180
181 $class = 'class="' . $atts['class'] . '"';
182 $placeholder = 'placeholder="' . $atts['placeholder'] . '"';
183 $id = ! empty($atts['id']) ? 'id="' . $atts['id'] . '"' : null;
184 $value = isset($_POST['password2']) ? 'value="' . esc_attr($_POST['password2']) . '"' : 'value=""';
185
186 $title = 'title="' . $atts['title'] . '"';
187
188 $html = "<input name=\"password2\" type='password' $title $value $class $id $placeholder $other_atts_html autocomplete='off'>";
189
190 return apply_filters('ppress_password_reset_handler_password2_field', $html, $atts);
191 }
192
193 /**
194 * Password strength meter field for password reset handler form.
195 * @see http://code.tutsplus.com/articles/using-the-included-password-strength-meter-script-in-wordpress--wp-34736
196 */
197 public static function password_meter($atts)
198 {
199 // grab unofficial attributes
200 $other_atts_html = ppress_other_field_atts($atts);
201
202 $atts = shortcode_atts(
203 array(
204 'class' => '',
205 'enforce' => 'true',
206 ),
207 $atts
208 );
209
210 $atts = apply_filters('ppress_password_reset_handler_meter_field_atts', $atts);
211
212 wp_localize_script('password-strength-meter', 'pwsL10n', array(
213 'empty' => esc_html__('Strength indicator'),
214 'short' => esc_html__('Very weak'),
215 'bad' => esc_html__('Weak'),
216 'good' => _x('Medium', 'password strength'),
217 'strong' => esc_html__('Strong'),
218 'mismatch' => esc_html__('Mismatch'),
219 ));
220
221 ob_start(); ?>
222 <?php if ('true' == $atts['enforce']) : ?>
223 <input type="hidden" name="pp_enforce_password_meter" value="true">
224 <?php endif; ?>
225 <div id="pp-pass-strength-result" <?php echo 'class="' . $atts['class'] . '"' . $other_atts_html; ?>><?php _e('Strength indicator'); ?></div>
226 <script type="text/javascript">
227 var pass_strength = 0;
228 jQuery(document).ready(function ($) {
229 var password1 = $('input[name=password1]');
230 var password2 = $('input[name=password2]');
231 var submitButton = $('input[name=reset_password]');
232 var strengthMeterId = $('#pp-pass-strength-result');
233
234 $('body').on('keyup', 'input[name=password1], input[name=password2]',
235 function (event) {
236 pp_checkPasswordStrength(password1, password2, strengthMeterId, submitButton, []);
237 }
238 );
239
240 if (password1.val() != '') {
241 // trigger 'keyup' event to check password strength when password field isn't empty.
242 $('body input[name=password1]').trigger('keyup');
243 }
244
245 submitButton.click(function () {
246 $('input[name=pp_enforce_password_meter]').val(pass_strength);
247 });
248 });
249
250 function pp_checkPasswordStrength($pass1, $pass2, $strengthResult, $submitButton, blacklistArray) {
251
252 var min_password_strength = <?php echo apply_filters('ppress_min_password_strength', 4); ?>;
253 var pass1 = $pass1.val();
254 var pass2 = $pass2.val();
255
256 <?php if('true' == $atts['enforce']) : ?>
257 // Reset the form & meter
258 $submitButton.attr('disabled', 'disabled').css("opacity", ".4");
259 <?php endif; ?>
260 $strengthResult.removeClass('short bad good strong');
261
262 // Extend our blacklist array with those from the inputs & site data
263 blacklistArray = blacklistArray.concat(wp.passwordStrength.userInputBlacklist());
264
265 // Get the password strength
266 var strength = wp.passwordStrength.meter(pass1, blacklistArray, pass2);
267
268 // Add the strength meter results
269 switch (strength) {
270
271 case 2:
272 $strengthResult.addClass('bad').html(pwsL10n.bad);
273 break;
274 case 3:
275 $strengthResult.addClass('good').html(pwsL10n.good);
276 if (min_password_strength === 3) {
277 pass_strength = 1;
278 }
279 break;
280 case 4:
281 $strengthResult.addClass('strong').html(pwsL10n.strong);
282 if (min_password_strength === 4) {
283 pass_strength = 1;
284 }
285 break;
286 case 5:
287 $strengthResult.addClass('short').html(pwsL10n.mismatch);
288 break;
289 default:
290 $strengthResult.addClass('short').html(pwsL10n.short);
291 }
292
293 // The meter function returns a result even if pass2 is empty,
294 // enable only the submit button if the password is strong
295 <?php if('true' == $atts['enforce']) : ?>
296 if (min_password_strength <= strength) {
297 $submitButton.removeAttr('disabled').css("opacity", "");
298 }
299 <?php endif; ?>
300
301 return strength;
302 }
303 </script>
304 <?php
305 return apply_filters('ppress_registration_password_meter_field', ob_get_clean(), $atts);
306 }
307
308 /**
309 * Password reset handler submit button.
310 *
311 * @param $atts array shortcode param
312 *
313 * @return string HTML submit button
314 */
315 function password_reset_submit($atts)
316 {
317 // grab unofficial attributes
318 $other_atts_html = ppress_other_field_atts($atts);
319
320 $atts = shortcode_atts(
321 array(
322 'class' => '',
323 'id' => '',
324 'title' => '',
325 'name' => 'reset_password',
326 ),
327 $atts
328 );
329
330 $atts = apply_filters('ppress_password_reset_handler_submit_field_atts', $atts);
331
332 $name = 'name="' . $atts['name'] . '"';
333 $class = 'class="pp-submit-form ' . $atts['class'] . '"';
334
335 $value = ! empty($atts['value']) ? $atts['value'] : esc_html__('Get New Password', 'wp-user-avatar');
336
337 $id = ! empty($atts['id']) ? 'id="' . $atts['id'] . '"' : '';
338
339 $title = 'title="' . $atts['title'] . '"';
340
341 $html = sprintf(
342 '<input data-pp-submit-label="%2$s" data-pp-processing-label="%3$s" type="submit" value="%2$s" %1$s>',
343 "$name $title $class $id $other_atts_html",
344 $value,
345 $this->get_processing_label()
346 );
347
348 return apply_filters('ppress_password_reset_handler_submit_field', $html, $atts);
349 }
350
351
352 /** Singleton poop */
353 static function get_instance()
354 {
355 static $instance = false;
356 if ( ! $instance) {
357 $instance = new self;
358 }
359
360 return $instance;
361 }
362 }
363