PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.2.2
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.2.2
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 5 years ago FieldsShortcodeCallback.php 4 years ago FrontendProfileBuilder.php 4 years ago GlobalShortcodes.php 4 years ago LoginFormBuilder.php 5 years ago PasswordResetBuilder.php 5 years ago RegistrationFormBuilder.php 5 years ago index.php 5 years ago
RegistrationFormBuilder.php
268 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 valid_field_atts($atts)
78 {
79 if ( ! is_array($atts)) {
80 return $atts;
81 }
82
83 $invalid_atts = array('enforce', 'key', 'field_key', 'limit', 'options', 'checkbox_text');
84
85 $valid_atts = array();
86
87 foreach ($atts as $key => $value) {
88 if ( ! in_array($key, $invalid_atts)) {
89 $valid_atts[$key] = $value;
90 }
91 }
92
93 return $valid_atts;
94 }
95
96 public static function field_attributes($field_name, $atts, $required = 'false')
97 {
98 $_POST = self::GET_POST();
99
100 if ($field_name !== 'reg_submit') {
101 $atts['required'] = isset($atts['required']) ? $atts['required'] : $required;
102 }
103
104 if ( ! in_array($field_name, ['ignore_value'])) {
105 $atts['value'] = isset($_POST[$field_name]) ? esc_attr($_POST[$field_name]) : @esc_attr($atts['value']);
106 }
107
108 $output = [];
109
110 foreach ($atts as $key => $value) {
111 if ($key != 'required' && ! empty($value)) {
112 $value = esc_attr($value);
113 $output[] = "$key=\"$value\"";
114 }
115 }
116
117 $output = implode(' ', $output);
118
119 if (self::is_field_required($atts)) {
120 $output .= ' required="required"';
121 }
122
123 return $output;
124 }
125
126 /**
127 * Password strength meter field.
128 * @see http://code.tutsplus.com/articles/using-the-included-password-strength-meter-script-in-wordpress--wp-34736
129 */
130 public static function password_meter($atts)
131 {
132 $atts['enforce'] = isset($atts['enforce']) ? $atts['enforce'] : 'true';
133
134 $attributes = self::field_attributes('ignore_value', self::valid_field_atts(ppress_normalize_attributes($atts)));
135
136 wp_localize_script('password-strength-meter', 'pwsL10n', array(
137 'empty' => esc_html__('Strength indicator', 'wp-user-avatar'),
138 'short' => esc_html__('Very weak', 'wp-user-avatar'),
139 'bad' => esc_html__('Weak', 'wp-user-avatar'),
140 'good' => _x('Medium', 'password strength', 'wp-user-avatar'),
141 'strong' => esc_html__('Strong', 'wp-user-avatar'),
142 'mismatch' => esc_html__('Mismatch', 'wp-user-avatar'),
143 ));
144
145 ob_start(); ?>
146
147 <?php if ('true' == $atts['enforce']) : ?>
148 <input type="hidden" name="pp_enforce_password_meter" value="true">
149 <?php endif; ?>
150 <div id="pp-pass-strength-result" <?php echo $attributes; ?>><?php _e('Strength indicator'); ?></div>
151 <script type="text/javascript">
152 var pass_strength = 0;
153 (function ($) {
154 $(document).on('ready', function () {
155 var password1 = $('input[name=reg_password]');
156 var password2 = $('input[name=reg_password2]');
157 var submitButton = $('input[name=reg_submit]');
158 var strengthMeterId = $('#pp-pass-strength-result');
159
160 $('body').on('keyup', 'input[name=reg_password], input[name=reg_password2]', function () {
161 pp_checkPasswordStrength(password1, password2, strengthMeterId, submitButton, []);
162 }
163 );
164
165 // set a time delay to enable the checker function to initialize
166 setTimeout(function () {
167 if (password1.val() === '') return;
168 pp_checkPasswordStrength(password1, password2, strengthMeterId, submitButton, []);
169 }, 500);
170
171 submitButton.click(function () {
172 $('input[name=pp_enforce_password_meter]').val(pass_strength);
173 });
174 });
175 })(jQuery);
176
177 function pp_checkPasswordStrength($pass1, $pass2, $strengthResult, $submitButton, blacklistArray) {
178 var min_password_strength = <?php echo apply_filters('ppress_min_password_strength', 4); ?>;
179 var pass1 = $pass1.val();
180 var pass2 = $pass2.val();
181
182 <?php if('true' == $atts['enforce']) : ?>
183 // Reset the form & meter
184 $submitButton.attr('disabled', 'disabled').css("opacity", ".4");
185 <?php endif; ?>
186 $strengthResult.removeClass('short bad good strong');
187
188 // Extend our blacklist array with those from the inputs & site data
189 blacklistArray = blacklistArray.concat(wp.passwordStrength.userInputDisallowedList());
190
191 // Get the password strength
192 var strength = wp.passwordStrength.meter(pass1, blacklistArray, pass2);
193
194 // Add the strength meter results
195 switch (strength) {
196 case 1:
197 case 2:
198 $strengthResult.addClass('bad').html(pwsL10n.bad);
199 break;
200 case 3:
201 $strengthResult.addClass('good').html(pwsL10n.good);
202 if (min_password_strength === 3) {
203 pass_strength = 1;
204 }
205 break;
206 case 4:
207 $strengthResult.addClass('strong').html(pwsL10n.strong);
208 if (min_password_strength === 4) {
209 pass_strength = 1;
210 }
211 break;
212 case 5:
213 $strengthResult.addClass('short').html(pwsL10n.mismatch);
214 break;
215 default:
216 $strengthResult.addClass('short').html(pwsL10n.short);
217 }
218
219 // The meter function returns a result even if pass2 is empty,
220 // enable only the submit button if the password is strong
221 <?php if('true' == $atts['enforce']) : ?>
222 if (min_password_strength <= strength) {
223 $submitButton.removeAttr('disabled').css("opacity", "");
224 }
225 <?php endif; ?>
226
227 return strength;
228 }
229 </script>
230 <?php
231 return apply_filters('ppress_registration_password_meter_field', ob_get_clean(), $atts);
232 }
233
234 public static function select_role($atts)
235 {
236 $attributes = self::field_attributes('ignore_value', self::valid_field_atts(ppress_normalize_attributes($atts)));
237
238 if ( ! empty($atts['options'])) {
239 $selectible_roles = array_map('trim', explode(',', $atts['options']));
240 }
241
242 if (isset($selectible_roles)) {
243 $wp_roles = array_filter(ppress_get_editable_roles(), function ($value) use ($selectible_roles) {
244 // get the array key of the $value value.
245 $key = array_search($value, ppress_get_editable_roles());
246
247 return in_array($key, $selectible_roles);
248 });
249 } else {
250 $wp_roles = ppress_get_editable_roles();
251 }
252
253 $html = "<select name=\"reg_select_role\" $attributes>";
254
255 if (is_array($wp_roles)) {
256 foreach ($wp_roles as $key => $value) {
257 $_POST = self::GET_POST();
258 $selected = selected(@$_POST['reg_select_role'], $key, false);
259 $label = $value['name'];
260 $html .= "<option value='$key' id='select_role_$key' class='select_role_option' $selected>$label</option>";
261 }
262 }
263
264 $html .= '</select>';
265
266 return apply_filters('ppress_registration_select_role_field', $html, $atts);
267 }
268 }