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
EditProfileBuilder.php
186 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\ShortcodeParser\Builder; |
| 4 | |
| 5 | use ProfilePress\Core\Classes\FormRepository; |
| 6 | |
| 7 | class EditProfileBuilder |
| 8 | { |
| 9 | public function __construct() |
| 10 | { |
| 11 | $instance = new FieldsShortcodeCallback(FormRepository::EDIT_PROFILE_TYPE); |
| 12 | |
| 13 | add_shortcode('edit-profile-username', array($instance, 'username')); |
| 14 | |
| 15 | add_shortcode('edit-profile-password', array($instance, 'password')); |
| 16 | |
| 17 | add_shortcode('edit-profile-confirm-password', array($instance, 'confirm_password')); |
| 18 | |
| 19 | add_shortcode('edit-profile-password-meter', array(__CLASS__, 'password_meter')); |
| 20 | |
| 21 | add_shortcode('edit-profile-email', array($instance, 'email')); |
| 22 | |
| 23 | add_shortcode('edit-profile-confirm-email', array($instance, 'confirm_email')); |
| 24 | |
| 25 | add_shortcode('edit-profile-website', array($instance, 'website')); |
| 26 | |
| 27 | add_shortcode('edit-profile-nickname', array($instance, 'nickname')); |
| 28 | |
| 29 | add_shortcode('edit-profile-display-name', array($instance, 'display_name')); |
| 30 | |
| 31 | add_shortcode('edit-profile-first-name', array($instance, 'first_name')); |
| 32 | |
| 33 | add_shortcode('edit-profile-last-name', array($instance, 'last_name')); |
| 34 | |
| 35 | add_shortcode('edit-profile-bio', array($instance, 'bio')); |
| 36 | |
| 37 | add_shortcode('delete-avatar-button', array($instance, 'remove_user_avatar')); |
| 38 | add_shortcode('pp-remove-avatar-button', array($instance, 'remove_user_avatar')); |
| 39 | |
| 40 | add_shortcode('edit-profile-avatar', array($instance, 'avatar')); |
| 41 | |
| 42 | add_shortcode('edit-profile-cover-image', array($instance, 'cover_image')); |
| 43 | add_shortcode('pp-remove-cover-image-button', array($instance, 'remove_cover_image')); |
| 44 | |
| 45 | add_shortcode('edit-profile-cpf', array($instance, 'custom_profile_field')); |
| 46 | |
| 47 | add_shortcode('edit-profile-submit', array($instance, 'submit')); |
| 48 | |
| 49 | add_shortcode('edit-profile-text-box', array($instance, 'textbox_field')); |
| 50 | add_shortcode('edit-profile-textarea', array($instance, 'textarea_field')); |
| 51 | add_shortcode('edit-profile-select-dropdown', array($instance, 'select_dropdown_field')); |
| 52 | add_shortcode('edit-profile-checkbox-list', array($instance, 'checkbox_list_field')); |
| 53 | add_shortcode('edit-profile-single-checkbox', array($instance, 'single_checkbox_field')); |
| 54 | add_shortcode('edit-profile-cf-password', array($instance, 'cf_password_field')); |
| 55 | add_shortcode('edit-profile-country', array($instance, 'country_field')); |
| 56 | add_shortcode('edit-profile-date-field', array($instance, 'date_field')); |
| 57 | add_shortcode('edit-profile-number-field', array($instance, 'number_field')); |
| 58 | add_shortcode('edit-profile-radio-buttons', array($instance, 'radio_buttons_field')); |
| 59 | |
| 60 | do_action('ppress_register_edit_profile_form_shortcode'); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Password strength meter field. |
| 65 | */ |
| 66 | public static function password_meter($atts) |
| 67 | { |
| 68 | // grab unofficial attributes |
| 69 | $other_atts_html = ppress_other_field_atts($atts); |
| 70 | |
| 71 | $atts = shortcode_atts( |
| 72 | array( |
| 73 | 'class' => '', |
| 74 | 'enforce' => 'false', |
| 75 | ), |
| 76 | $atts |
| 77 | ); |
| 78 | |
| 79 | $atts = apply_filters('ppress_edit_profile_password_meter_field_atts', $atts); |
| 80 | |
| 81 | wp_localize_script('password-strength-meter', 'pwsL10n', array( |
| 82 | 'empty' => esc_html__('Strength indicator'), |
| 83 | 'short' => esc_html__('Very weak'), |
| 84 | 'bad' => esc_html__('Weak'), |
| 85 | 'good' => _x('Medium', 'password strength'), |
| 86 | 'strong' => esc_html__('Strong'), |
| 87 | 'mismatch' => esc_html__('Mismatch'), |
| 88 | )); |
| 89 | |
| 90 | ob_start(); ?> |
| 91 | |
| 92 | <?php if ('true' == $atts['enforce']) : ?> |
| 93 | <input type="hidden" name="pp_enforce_password_meter" value="true"> |
| 94 | <?php endif; ?> |
| 95 | <div id="pp-pass-strength-result" <?php echo 'class="' . $atts['class'] . '"' . $other_atts_html; ?>><?php _e('Strength indicator'); ?></div> |
| 96 | <script type="text/javascript"> |
| 97 | var pass_strength = 0; |
| 98 | jQuery(document).ready(function ($) { |
| 99 | var password1 = $('input[name=eup_password]'); |
| 100 | var password2 = $('input[name=eup_password2]'); |
| 101 | var submitButton = $('input[name=eup_submit]'); |
| 102 | var strengthMeterId = $('#pp-pass-strength-result'); |
| 103 | |
| 104 | $('body').on('keyup', 'input[name=eup_password], input[name=eup_password2]', |
| 105 | function (event) { |
| 106 | pp_checkPasswordStrength(password1, password2, strengthMeterId, submitButton, []); |
| 107 | } |
| 108 | ); |
| 109 | |
| 110 | if (password1.val() != '') { |
| 111 | // trigger 'keyup' event to check password strength when password field isn't empty. |
| 112 | $('body input[name=eup_password]').trigger('keyup'); |
| 113 | } |
| 114 | |
| 115 | submitButton.click(function () { |
| 116 | $('input[name=pp_enforce_password_meter]').val(pass_strength); |
| 117 | }); |
| 118 | }); |
| 119 | |
| 120 | function pp_checkPasswordStrength($pass1, $pass2, $strengthResult, $submitButton, blacklistArray) { |
| 121 | var min_password_strength = <?php echo apply_filters('ppress_min_password_strength', 4); ?>; |
| 122 | var pass1 = $pass1.val(); |
| 123 | var pass2 = $pass2.val(); |
| 124 | |
| 125 | <?php if('true' == $atts['enforce']) : ?> |
| 126 | // Reset the form & meter |
| 127 | $submitButton.attr('disabled', 'disabled').css("opacity", ".4"); |
| 128 | <?php endif; ?> |
| 129 | $strengthResult.removeClass('short bad good strong'); |
| 130 | |
| 131 | // Extend our blacklist array with those from the inputs & site data |
| 132 | blacklistArray = blacklistArray.concat(wp.passwordStrength.userInputBlacklist()); |
| 133 | |
| 134 | // Get the password strength |
| 135 | var strength = wp.passwordStrength.meter(pass1, blacklistArray, pass2); |
| 136 | |
| 137 | // Add the strength meter results |
| 138 | switch (strength) { |
| 139 | case 2: |
| 140 | $strengthResult.addClass('bad').html(pwsL10n.bad); |
| 141 | break; |
| 142 | case 3: |
| 143 | $strengthResult.addClass('good').html(pwsL10n.good); |
| 144 | if (min_password_strength === 3) { |
| 145 | pass_strength = 1; |
| 146 | } |
| 147 | break; |
| 148 | case 4: |
| 149 | $strengthResult.addClass('strong').html(pwsL10n.strong); |
| 150 | if (min_password_strength === 4) { |
| 151 | pass_strength = 1; |
| 152 | } |
| 153 | break; |
| 154 | case 5: |
| 155 | $strengthResult.addClass('short').html(pwsL10n.mismatch); |
| 156 | break; |
| 157 | default: |
| 158 | $strengthResult.addClass('short').html(pwsL10n.short); |
| 159 | } |
| 160 | |
| 161 | // The meter function returns a result even if pass2 is empty, |
| 162 | // enable only the submit button if the password is strong |
| 163 | <?php if('true' == $atts['enforce']) : ?> |
| 164 | if (min_password_strength <= strength) { |
| 165 | $submitButton.removeAttr('disabled').css("opacity", ""); |
| 166 | } |
| 167 | <?php endif; ?> |
| 168 | |
| 169 | return strength; |
| 170 | } |
| 171 | </script> |
| 172 | <?php |
| 173 | return apply_filters('ppress_edit_profile_password_meter_field', ob_get_clean(), $atts); |
| 174 | } |
| 175 | |
| 176 | public static function get_instance() |
| 177 | { |
| 178 | static $instance = false; |
| 179 | |
| 180 | if ( ! $instance) { |
| 181 | $instance = new self; |
| 182 | } |
| 183 | |
| 184 | return $instance; |
| 185 | } |
| 186 | } |