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 / RegistrationFormBuilder.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 4 weeks ago RegistrationFormBuilder.php 1 year ago index.php 5 years ago
RegistrationFormBuilder.php
255 lines
1 <?php
2
3 namespace ProfilePress\Core\ShortcodeParser\Builder;
4
5 use ProfilePress\Core\Classes\FormRepository;
6
7 class RegistrationFormBuilder
8 {
9 public static function initialize()
10 {
11 $instance = new FieldsShortcodeCallback(FormRepository::REGISTRATION_TYPE);
12
13 add_shortcode('reg-username', array($instance, 'username'));
14 add_shortcode('reg-password', array($instance, 'password'));
15 add_shortcode('reg-confirm-password', array($instance, 'confirm_password'));
16 add_shortcode('reg-email', array($instance, 'email'));
17 add_shortcode('reg-confirm-email', array($instance, 'confirm_email'));
18 add_shortcode('reg-website', array($instance, 'website'));
19 add_shortcode('reg-nickname', array($instance, 'nickname'));
20 add_shortcode('reg-display-name', array($instance, 'display_name'));
21 add_shortcode('reg-first-name', array($instance, 'first_name'));
22 add_shortcode('reg-last-name', array($instance, 'last_name'));
23 add_shortcode('reg-bio', array($instance, 'bio'));
24 add_shortcode('reg-avatar', array($instance, 'avatar'));
25 add_shortcode('reg-cover-image', array($instance, 'cover_image'));
26 add_shortcode('reg-cpf', array($instance, 'custom_profile_field'));
27 add_shortcode('reg-submit', array($instance, 'submit'));
28 add_shortcode('reg-password-meter', array(__CLASS__, 'password_meter'));
29 add_shortcode('reg-select-role', array(__CLASS__, 'select_role'));
30
31 // custom fields shortcodes
32 add_shortcode('reg-text-box', array($instance, 'textbox_field'));
33 add_shortcode('reg-textarea', array($instance, 'textarea_field'));
34 add_shortcode('reg-select-dropdown', array($instance, 'select_dropdown_field'));
35 add_shortcode('reg-checkbox-list', array($instance, 'checkbox_list_field'));
36 add_shortcode('reg-single-checkbox', array($instance, 'single_checkbox_field'));
37 add_shortcode('reg-cf-password', array($instance, 'cf_password_field'));
38 add_shortcode('reg-country', array($instance, 'country_field'));
39 add_shortcode('reg-date-field', array($instance, 'date_field'));
40 add_shortcode('reg-number-field', array($instance, 'number_field'));
41 add_shortcode('reg-radio-buttons', array($instance, 'radio_buttons_field'));
42
43 do_action('ppress_register_registration_form_shortcode');
44 }
45
46 public static function GET_POST()
47 {
48 return array_merge($_GET, $_POST);
49 }
50
51 /**
52 * Is field a required field?
53 *
54 * @param array $atts
55 *
56 * @return bool
57 */
58 public static function is_field_required($atts)
59 {
60 $atts = ppress_normalize_attributes($atts);
61
62 return isset($atts['required']) && ($atts['required'] === true || $atts['required'] == 'true' || $atts['required'] == '1');
63 }
64
65 /**
66 * Rewrite custom field key to something more human readable.
67 *
68 * @param string $key field key
69 *
70 * @return string
71 */
72 public static function human_readable_field_key($key)
73 {
74 return ucfirst(str_replace('_', ' ', $key));
75 }
76
77 public static function field_attributes($field_name, $atts, $required = 'false')
78 {
79 $_POST = self::GET_POST();
80
81 if ($field_name !== 'reg_submit') {
82 $atts['required'] = isset($atts['required']) ? $atts['required'] : $required;
83 }
84
85 if ( ! in_array($field_name, ['ignore_value'])) {
86 $atts['value'] = isset($_POST[$field_name]) ? esc_attr($_POST[$field_name]) : esc_attr(ppress_var($atts, 'value'));
87 }
88
89 $output = [];
90
91 foreach ($atts as $key => $value) {
92 if ($key != 'required' && ! empty($value)) {
93 $value = esc_attr($value);
94 $key = esc_attr($key);
95 $output[] = "$key=\"$value\"";
96 }
97 }
98
99 $output = implode(' ', $output);
100
101 if (self::is_field_required($atts)) {
102 $output .= ' required="required"';
103 }
104
105 return $output;
106 }
107
108 /**
109 * Password strength meter field.
110 * @see http://code.tutsplus.com/articles/using-the-included-password-strength-meter-script-in-wordpress--wp-34736
111 */
112 public static function password_meter($atts)
113 {
114 $atts['enforce'] = isset($atts['enforce']) ? $atts['enforce'] : 'true';
115
116 if (in_array($atts['enforce'], ['1', 'true', true], true)) {
117 $atts['enforce'] = 'true';
118 }
119
120 $attributes = self::field_attributes('ignore_value', FieldsShortcodeCallback::sanitize_field_attributes(ppress_normalize_attributes($atts)));
121
122 wp_localize_script('password-strength-meter', 'pwsL10n', array(
123 'empty' => esc_html__('Strength indicator', 'wp-user-avatar'),
124 'short' => esc_html__('Very weak', 'wp-user-avatar'),
125 'bad' => esc_html__('Weak', 'wp-user-avatar'),
126 'good' => _x('Medium', 'password strength', 'wp-user-avatar'),
127 'strong' => esc_html__('Strong', 'wp-user-avatar'),
128 'mismatch' => esc_html__('Mismatch', 'wp-user-avatar'),
129 ));
130
131 ob_start(); ?>
132
133 <?php if ('true' == $atts['enforce']) : ?>
134 <input type="hidden" name="pp_enforce_password_meter" value="true">
135 <?php endif; ?>
136 <div id="pp-pass-strength-result" <?php echo $attributes; ?>><?php _e('Strength indicator', 'wp-user-avatar'); ?></div>
137 <script type="text/javascript">
138 var pass_strength = 0;
139 (function ($) {
140 $(function () {
141 var password1 = $('input[name=reg_password]');
142 var password2 = $('input[name=reg_password2]');
143 var submitButton = $('input[name=reg_submit]');
144 var strengthMeterId = $('#pp-pass-strength-result');
145
146 $('body').on('keyup', 'input[name=reg_password], input[name=reg_password2]', function () {
147 pp_checkPasswordStrength(password1, password2, strengthMeterId, submitButton, []);
148 }
149 );
150
151 // set a time delay to enable the checker function to initialize
152 setTimeout(function () {
153 if (password1.val() === '') return;
154 pp_checkPasswordStrength(password1, password2, strengthMeterId, submitButton, []);
155 }, 500);
156
157 submitButton.on('click', function () {
158 $('input[name=pp_enforce_password_meter]').val(pass_strength);
159 });
160 });
161 })(jQuery);
162
163 function pp_checkPasswordStrength($pass1, $pass2, $strengthResult, $submitButton, blacklistArray) {
164 var min_password_strength = <?php echo apply_filters('ppress_min_password_strength', 4); ?>;
165 var pass1 = $pass1.val();
166 var pass2 = $pass2.val();
167
168 <?php if('true' == $atts['enforce']) : ?>
169 // Reset the form & meter
170 $submitButton.attr('disabled', 'disabled').css("opacity", ".4");
171 <?php endif; ?>
172 $strengthResult.removeClass('short bad good strong');
173
174 // Extend our blacklist array with those from the inputs & site data
175 blacklistArray = blacklistArray.concat(wp.passwordStrength.userInputDisallowedList());
176
177 // Get the password strength
178 var strength = wp.passwordStrength.meter(pass1, blacklistArray, pass2);
179
180 // Add the strength meter results
181 switch (strength) {
182 case 1:
183 case 2:
184 $strengthResult.addClass('bad').html(pwsL10n.bad);
185 break;
186 case 3:
187 $strengthResult.addClass('good').html(pwsL10n.good);
188 if (min_password_strength === 3) {
189 pass_strength = 1;
190 }
191 break;
192 case 4:
193 $strengthResult.addClass('strong').html(pwsL10n.strong);
194 if (min_password_strength === 4) {
195 pass_strength = 1;
196 }
197 break;
198 case 5:
199 $strengthResult.addClass('short').html(pwsL10n.mismatch);
200 break;
201 default:
202 $strengthResult.addClass('short').html(pwsL10n.short);
203 }
204
205 // The meter function returns a result even if pass2 is empty,
206 // enable only the submit button if the password is strong
207 <?php if('true' == $atts['enforce']) : ?>
208 if (min_password_strength <= strength) {
209 $submitButton.removeAttr('disabled').css("opacity", "");
210 }
211 <?php endif; ?>
212
213 return strength;
214 }
215 </script>
216 <?php
217 return apply_filters('ppress_registration_password_meter_field', ob_get_clean(), $atts);
218 }
219
220 public static function select_role($atts)
221 {
222 $attributes = self::field_attributes('ignore_value', FieldsShortcodeCallback::sanitize_field_attributes(ppress_normalize_attributes($atts)));
223
224 if ( ! empty($atts['options'])) {
225 $selectible_roles = array_map('trim', explode(',', $atts['options']));
226 }
227
228 if (isset($selectible_roles)) {
229 $wp_roles = array_filter(ppress_get_editable_roles(), function ($value) use ($selectible_roles) {
230 // get the array key of the $value value.
231 $key = array_search($value, ppress_get_editable_roles());
232
233 return in_array($key, $selectible_roles);
234 });
235
236 } else {
237 $wp_roles = ppress_get_editable_roles();
238 }
239
240 $html = "<select name=\"reg_select_role\" $attributes>";
241
242 if (is_array($wp_roles)) {
243 foreach ($wp_roles as $key => $value) {
244 $_POST = self::GET_POST();
245 $selected = selected($_POST['reg_select_role'] ?? '', $key, false);
246 $label = $value['name'];
247 $html .= "<option value='$key' id='select_role_$key' class='select_role_option' $selected>$label</option>";
248 }
249 }
250
251 $html .= '</select>';
252
253 return apply_filters('ppress_registration_select_role_field', $html, $atts);
254 }
255 }