| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | /** |
| 3 | 4 | * Form related functions |
| 4 | 5 | * |
| 5 | 6 | * This class defines all code necessary to handle UsersWP forms like login. register etc. |
| @@ -8,2748 +9,4932 @@ | ||
| 8 | 9 | * @author GeoDirectory Team <info@wpgeodirectory.com> |
| 9 | 10 | */ |
| 10 | 11 | class UsersWP_Forms { |
| 11 | 12 | |
| 12 | - protected $generated_password; | |
| 13 | + protected $generated_password; | |
| 13 | 14 | |
| 14 | - /** | |
| 15 | - * Initialize UsersWP notices. | |
| 16 | - * | |
| 17 | - * @since 1.0.0 | |
| 18 | - * @package userswp | |
| 19 | - * | |
| 20 | - * @return void | |
| 21 | - */ | |
| 22 | - public function init_notices() { | |
| 23 | - global $uwp_notices; | |
| 24 | - $uwp_notices = array(); | |
| 25 | - } | |
| 15 | + /** | |
| 16 | + * Logs the error message. | |
| 17 | + * | |
| 18 | + * @param array|object|string $log Error message. | |
| 19 | + * | |
| 20 | + * @return void | |
| 21 | + * @since 1.0.0 | |
| 22 | + * @package userswp | |
| 23 | + * | |
| 24 | + */ | |
| 25 | + public static function uwp_error_log( $log ) { | |
| 26 | + uwp_error_log( $log ); | |
| 27 | + } | |
| 26 | 28 | |
| 27 | - /** | |
| 28 | - * Handles all UsersWP forms. | |
| 29 | - * | |
| 30 | - * @since 1.0.0 | |
| 31 | - * @package userswp | |
| 32 | - * | |
| 33 | - * @return void | |
| 34 | - */ | |
| 35 | - public function handler() | |
| 36 | - { | |
| 37 | - global $uwp_notices; | |
| 29 | + /** | |
| 30 | + * Initialize UsersWP notices. | |
| 31 | + * | |
| 32 | + * @return void | |
| 33 | + * @package userswp | |
| 34 | + * | |
| 35 | + * @since 1.0.0 | |
| 36 | + */ | |
| 37 | + public function init_notices() { | |
| 38 | + global $uwp_notices; | |
| 39 | + $uwp_notices = array(); | |
| 40 | + } | |
| 38 | 41 | |
| 39 | - ob_start(); | |
| 42 | + /** | |
| 43 | + * Handles all UsersWP forms. | |
| 44 | + * | |
| 45 | + * @return void | |
| 46 | + * @package userswp | |
| 47 | + * | |
| 48 | + * @since 1.0.0 | |
| 49 | + */ | |
| 50 | + public function handler() { | |
| 51 | + global $uwp_notices; | |
| 40 | 52 | |
| 41 | - $errors = null; | |
| 42 | - $message = null; | |
| 43 | - $redirect = false; | |
| 44 | - $processed = false; | |
| 45 | - $type = null; | |
| 53 | + ob_start(); | |
| 46 | 54 | |
| 47 | - $login_page_url = wp_login_url(); | |
| 55 | + $errors = null; | |
| 56 | + $message = null; | |
| 57 | + $redirect = false; | |
| 58 | + $processed = false; | |
| 59 | + $type = null; | |
| 48 | 60 | |
| 49 | - if (isset($_POST['uwp_register_nonce'])) { | |
| 50 | - $auto_login = uwp_get_option('uwp_registration_action', false); | |
| 51 | - $errors = $this->process_register($_POST, $_FILES); | |
| 52 | - if (!is_wp_error($errors)) { | |
| 53 | - $message = $errors; | |
| 54 | - } | |
| 55 | - $force_redirect = apply_filters('uwp_registration_force_redirect', false, $_POST, $_FILES); | |
| 56 | - if ($auto_login == 'auto_approve_login' || $force_redirect) { | |
| 57 | - $reg_redirect_page_id = uwp_get_option('register_redirect_to', ''); | |
| 58 | - if(isset( $_REQUEST['redirect_to'] )){ | |
| 59 | - $reg_redirect_to = esc_url($_REQUEST['redirect_to']); | |
| 60 | - } elseif ( isset($reg_redirect_page_id) && (int)$reg_redirect_page_id > 0) { | |
| 61 | - $reg_redirect_to = get_permalink($reg_redirect_page_id); | |
| 62 | - } else { | |
| 63 | - $reg_redirect_to = home_url('/'); | |
| 64 | - } | |
| 65 | - $redirect = apply_filters('uwp_register_redirect', $reg_redirect_to); | |
| 66 | - } | |
| 67 | - $processed = true; | |
| 68 | - $type = 'register'; | |
| 69 | - } elseif (isset($_POST['uwp_login_nonce'])) { | |
| 70 | - $errors = $this->process_login($_POST); | |
| 71 | - $redirect_page_id = uwp_get_option('login_redirect_to', -1); | |
| 72 | - if (isset($redirect_page_id) && (int)$redirect_page_id > 0) { | |
| 73 | - $redirect_to = get_permalink($redirect_page_id); | |
| 74 | - } elseif(isset( $_REQUEST['redirect_to'] ) && !empty($data['redirect_to'])){ | |
| 75 | - $redirect_to = esc_url($_REQUEST['redirect_to']); | |
| 76 | - } else { | |
| 77 | - $redirect_to = home_url('/'); | |
| 78 | - } | |
| 79 | - $redirect = apply_filters('uwp_login_redirect', $redirect_to); | |
| 80 | - $processed = true; | |
| 81 | - $type = 'login'; | |
| 82 | - } elseif (isset($_POST['uwp_forgot_nonce'])) { | |
| 83 | - $errors = $this->process_forgot($_POST); | |
| 84 | - $message = __('Please check your email.', 'userswp'); | |
| 85 | - $processed = true; | |
| 86 | - } elseif (isset($_POST['uwp_change_nonce'])) { | |
| 87 | - $errors = $this->process_change($_POST); | |
| 88 | - $message = __('Password changed successfully', 'userswp'); | |
| 89 | - $processed = true; | |
| 90 | - } elseif (isset($_POST['uwp_reset_submit'])) { | |
| 91 | - $errors = $this->process_reset($_POST); | |
| 92 | - $message = sprintf(__('Password updated successfully. Please <a href="%s">login</a> with your new password', 'userswp'), $login_page_url); | |
| 93 | - $processed = true; | |
| 94 | - } elseif (isset($_POST['uwp_account_nonce'])) { | |
| 95 | - $errors = $this->process_account($_POST, $_FILES); | |
| 96 | - $message = __('Account updated successfully.', 'userswp'); | |
| 97 | - $processed = true; | |
| 98 | - } elseif (isset($_POST['uwp_avatar_submit'])) { | |
| 99 | - $errors = $this->process_upload_submit($_POST, $_FILES, 'avatar'); | |
| 100 | - if (!is_wp_error($errors)) { | |
| 101 | - $redirect = $errors; | |
| 102 | - } | |
| 103 | - $message = __('Avatar cropped successfully.', 'userswp'); | |
| 104 | - $processed = true; | |
| 105 | - } elseif (isset($_POST['uwp_banner_submit'])) { | |
| 106 | - $errors = $this->process_upload_submit($_POST, $_FILES, 'banner'); | |
| 107 | - if (!is_wp_error($errors)) { | |
| 108 | - $redirect = $errors; | |
| 109 | - } | |
| 110 | - $message = __('Banner cropped successfully.', 'userswp'); | |
| 111 | - $processed = true; | |
| 112 | - } elseif (isset($_POST['uwp_avatar_crop'])) { | |
| 113 | - $errors = $this->process_image_crop($_POST, 'avatar', true); | |
| 114 | - if (!is_wp_error($errors)) { | |
| 115 | - $redirect = $errors; | |
| 116 | - } | |
| 117 | - $message = __('Avatar cropped successfully.', 'userswp'); | |
| 118 | - $processed = true; | |
| 119 | - } elseif (isset($_POST['uwp_banner_crop'])) { | |
| 120 | - $errors = $this->process_image_crop($_POST, 'banner', true); | |
| 121 | - if (!is_wp_error($errors)) { | |
| 122 | - $redirect = $errors; | |
| 123 | - } | |
| 124 | - $message = __('Banner cropped successfully.', 'userswp'); | |
| 125 | - $processed = true; | |
| 126 | - } | |
| 61 | + if ( isset( $_POST['uwp_avatar_submit'] ) ) { | |
| 62 | + $errors = $this->process_upload_submit( $_POST, $_FILES, 'avatar' ); | |
| 63 | + if ( ! is_wp_error( $errors ) ) { | |
| 64 | + $redirect = $errors; | |
| 65 | + } | |
| 66 | + $message = __( 'Avatar cropped successfully.', 'userswp' ); | |
| 67 | + $processed = true; | |
| 68 | + } elseif ( isset( $_POST['uwp_banner_submit'] ) ) { | |
| 69 | + $errors = $this->process_upload_submit( $_POST, $_FILES, 'banner' ); | |
| 70 | + if ( ! is_wp_error( $errors ) ) { | |
| 71 | + $redirect = $errors; | |
| 72 | + } | |
| 73 | + $message = __( 'Banner cropped successfully.', 'userswp' ); | |
| 74 | + $processed = true; | |
| 75 | + } elseif ( isset( $_POST['uwp_avatar_crop'] ) ) { | |
| 76 | + $errors = $this->process_image_crop( $_POST, 'avatar', true ); | |
| 77 | + if ( ! is_wp_error( $errors ) ) { | |
| 78 | + $redirect = $errors; | |
| 79 | + } | |
| 80 | + $message = __( 'Avatar cropped successfully.', 'userswp' ); | |
| 81 | + $processed = true; | |
| 82 | + } elseif ( isset( $_POST['uwp_banner_crop'] ) ) { | |
| 83 | + $errors = $this->process_image_crop( $_POST, 'banner', true ); | |
| 84 | + if ( ! is_wp_error( $errors ) ) { | |
| 85 | + $redirect = $errors; | |
| 86 | + } | |
| 87 | + $message = __( 'Banner cropped successfully.', 'userswp' ); | |
| 88 | + $processed = true; | |
| 89 | + } elseif ( isset( $_POST['uwp_avatar_reset'] ) ) { | |
| 90 | + $errors = $this->process_image_reset( 'avatar' ); | |
| 91 | + if ( ! is_wp_error( $errors ) ) { | |
| 92 | + $redirect = $errors; | |
| 93 | + } | |
| 94 | + $message = __( 'Avatar reset successfully.', 'userswp' ); | |
| 95 | + $processed = true; | |
| 96 | + } elseif ( isset( $_POST['uwp_banner_reset'] ) ) { | |
| 97 | + $errors = $this->process_image_reset( 'banner' ); | |
| 98 | + if ( ! is_wp_error( $errors ) ) { | |
| 99 | + $redirect = $errors; | |
| 100 | + } | |
| 101 | + $message = __( 'Banner reset successfully.', 'userswp' ); | |
| 102 | + $processed = true; | |
| 103 | + } | |
| 127 | 104 | |
| 128 | - if ($processed) { | |
| 129 | - if (is_wp_error($errors)) { | |
| 130 | - echo '<div class="uwp-alert-error text-center">'; | |
| 131 | - echo $errors->get_error_message(); | |
| 132 | - echo '</div>'; | |
| 133 | - } else { | |
| 134 | - if ($redirect) { | |
| 135 | - wp_safe_redirect($redirect); | |
| 136 | - exit(); | |
| 137 | - } else { | |
| 138 | - echo '<div class="uwp-alert-success text-center">'; | |
| 139 | - echo $message; | |
| 140 | - echo '</div>'; | |
| 141 | - } | |
| 142 | - } | |
| 143 | - } | |
| 105 | + if ( $processed ) { | |
| 144 | 106 | |
| 145 | - if($type){ | |
| 146 | - $uwp_notices[] = array($type => ob_get_contents()); | |
| 147 | - }else{ | |
| 148 | - $uwp_notices[] = ob_get_contents(); | |
| 149 | - } | |
| 107 | + if ( is_wp_error( $errors ) ) { | |
| 108 | + echo aui()->alert( | |
| 109 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 110 | + 'type' => 'error', | |
| 111 | + 'class' => 'text-center', | |
| 112 | + 'content' => wp_kses_post( $errors->get_error_message() ), | |
| 113 | + ) | |
| 114 | + ); | |
| 115 | + } elseif ( $redirect ) { | |
| 116 | + wp_safe_redirect( $redirect ); | |
| 117 | + exit(); | |
| 118 | + } else { | |
| 119 | + echo aui()->alert( | |
| 120 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 121 | + 'type' => 'success', | |
| 122 | + 'class' => 'text-center', | |
| 123 | + 'content' => wp_kses_post( $message ), | |
| 124 | + ) | |
| 125 | + ); | |
| 126 | + } | |
| 127 | + } | |
| 150 | 128 | |
| 129 | + if ( $type ) { | |
| 130 | + $uwp_notices[] = array( $type => ob_get_contents() ); | |
| 131 | + } else { | |
| 132 | + $uwp_notices[] = ob_get_contents(); | |
| 133 | + } | |
| 151 | 134 | |
| 152 | - ob_end_clean(); | |
| 135 | + ob_end_clean(); | |
| 136 | + } | |
| 153 | 137 | |
| 154 | - } | |
| 138 | + /** | |
| 139 | + * Processes avatar and banner uploads form submission. | |
| 140 | + * | |
| 141 | + * @param array $data Submitted $_POST data | |
| 142 | + * @param array $files Submitted $_FILES data | |
| 143 | + * | |
| 144 | + * @return bool|WP_Error|string File url to crop. | |
| 145 | + * @package userswp | |
| 146 | + * | |
| 147 | + * @since 1.0.0 | |
| 148 | + */ | |
| 149 | + public function process_upload_submit( $data = array(), $files = array(), $type = 'avatar' ) { | |
| 155 | 150 | |
| 156 | - /** | |
| 157 | - * Displays UsersWP notices in forms. | |
| 158 | - * | |
| 159 | - * @since 1.0.0 | |
| 160 | - * @package userswp | |
| 161 | - * | |
| 162 | - * @param string $type Form type | |
| 163 | - * | |
| 164 | - * @return void | |
| 165 | - */ | |
| 166 | - public function display_notices($type) { | |
| 167 | - global $uwp_notices; | |
| 151 | + $file_obj = new UsersWP_Files(); | |
| 168 | 152 | |
| 169 | - if (is_array($uwp_notices)) { | |
| 170 | - foreach ($uwp_notices as $notice) { | |
| 153 | + $current_user_id = get_current_user_id(); | |
| 154 | + if ( ! $current_user_id ) { | |
| 155 | + return false; | |
| 156 | + } | |
| 171 | 157 | |
| 172 | - // If the notification is type specific then only output on that type | |
| 173 | - if(is_array($notice)){ | |
| 174 | - foreach($notice as $key => $val){ | |
| 175 | - if( $key == $type ){ echo $val; } | |
| 176 | - } | |
| 177 | - }else{ | |
| 178 | - if (!empty($notice)) { | |
| 179 | - echo $notice; | |
| 180 | - } | |
| 181 | - } | |
| 158 | + if ( ! isset( $data['uwp_upload_nonce'] ) || ! wp_verify_nonce( $data['uwp_upload_nonce'], 'uwp-upload-nonce' ) ) { | |
| 159 | + return false; | |
| 160 | + } | |
| 182 | 161 | |
| 183 | - } | |
| 162 | + do_action( 'uwp_before_validate', $type ); | |
| 184 | 163 | |
| 185 | - } | |
| 164 | + $result = $file_obj->validate_uploads( $files, $type ); | |
| 186 | 165 | |
| 187 | - if ($type == 'change') { | |
| 188 | - $user_id = get_current_user_id(); | |
| 189 | - $password_nag = get_user_option('default_password_nag', $user_id); | |
| 166 | + $result = apply_filters( 'uwp_validate_result', $result, $type, $data ); | |
| 190 | 167 | |
| 191 | - if ($password_nag) { | |
| 192 | - $change_page = uwp_get_page_id('change_page', false); | |
| 193 | - $remove_nag_url = add_query_arg('uwp_remove_nag', 'yes', get_permalink($change_page)); | |
| 168 | + if ( is_wp_error( $result ) ) { | |
| 169 | + return $result; | |
| 170 | + } | |
| 194 | 171 | |
| 195 | - if (isset($_GET['uwp_remove_nag']) && $_GET['uwp_remove_nag'] == 'yes') { | |
| 196 | - delete_user_meta( $user_id, 'default_password_nag' ); | |
| 197 | - $message = sprintf(__('We have removed the system generated password warning for you. From this point forward you can continue to access our site as usual. To go to home page, <a href="%s">click here</a>.', 'userswp'), home_url('/')); | |
| 198 | - echo '<div class="uwp-alert-success text-center">'; | |
| 199 | - echo $message; | |
| 200 | - echo '</div>'; | |
| 201 | - } else { | |
| 202 | - $message = sprintf(__('<strong>Warning</strong>: You seems like you are using a system generated password. Please change the password in this page. If this is not a problem for you, you can remove this warning by <a href="%s">clicking here</a>.', 'userswp'), $remove_nag_url); | |
| 203 | - echo '<div class="uwp-alert-warning text-center">'; | |
| 204 | - echo $message; | |
| 205 | - echo '</div>'; | |
| 206 | - } | |
| 207 | - } | |
| 208 | - } | |
| 209 | - } | |
| 172 | + $profile_url = uwp_build_profile_tab_url( $current_user_id ); | |
| 210 | 173 | |
| 211 | - /** | |
| 212 | - * Processes register form submission. | |
| 213 | - * | |
| 214 | - * @since 1.0.0 | |
| 215 | - * @package userswp | |
| 216 | - * | |
| 217 | - * @param array $data Submitted $_POST data | |
| 218 | - * @param array $files Submitted $_FILES data | |
| 219 | - * | |
| 220 | - * @return bool|WP_Error|string | |
| 221 | - */ | |
| 222 | - public function process_register($data = array(), $files = array()) { | |
| 174 | + $url = add_query_arg( | |
| 175 | + array( | |
| 176 | + 'uwp_crop' => $result[ 'uwp_' . $type . '_file' ], | |
| 177 | + 'type' => $type, | |
| 178 | + ), | |
| 179 | + $profile_url | |
| 180 | + ); | |
| 223 | 181 | |
| 224 | - $errors = new WP_Error(); | |
| 225 | - $file_obj = new UsersWP_Files(); | |
| 182 | + return $url; | |
| 183 | + } | |
| 226 | 184 | |
| 227 | - if( ! isset( $data['uwp_register_nonce'] ) || ! wp_verify_nonce( $data['uwp_register_nonce'], 'uwp-register-nonce' ) ) { | |
| 228 | - return false; | |
| 229 | - } | |
| 185 | + /** | |
| 186 | + * Processes avatar and banner uploads image crop. | |
| 187 | + * | |
| 188 | + * @param array $data Submitted $_POST data | |
| 189 | + * @param string $type Image type. Default 'avatar'. | |
| 190 | + * @param bool $unlink_prev_img True to remove previous image. Default false; | |
| 191 | + * | |
| 192 | + * @return bool|WP_Error|string Profile url. | |
| 193 | + * @since 1.0.12 New param $unlink_prev_img introduced. | |
| 194 | + * @package userswp | |
| 195 | + * | |
| 196 | + * @since 1.0.0 | |
| 197 | + */ | |
| 198 | + public function process_image_crop( $data = array(), $type = 'avatar', $unlink_prev_img = false ) { | |
| 199 | + global $wpdb; | |
| 200 | + if ( ! is_user_logged_in() ) { | |
| 201 | + return false; | |
| 202 | + } | |
| 230 | 203 | |
| 231 | - if (!get_option('users_can_register')) { | |
| 232 | - $errors->add('register_disabled', __('<strong>ERROR</strong>: User registration is currently not allowed.', 'userswp')); | |
| 233 | - return $errors; | |
| 234 | - } | |
| 204 | + if ( empty( $_POST['uwp_crop_nonce'] ) || ! wp_verify_nonce( $_POST['uwp_crop_nonce'], 'uwp_crop_nonce_' . $type ) ) { | |
| 205 | + return; | |
| 206 | + } | |
| 235 | 207 | |
| 236 | - $reg_terms_page_id = uwp_get_option('register_terms_page', ''); | |
| 237 | - $reg_terms_page_id = apply_filters('uwp_reg_terms_page_id', $reg_terms_page_id); | |
| 238 | - if (!empty($reg_terms_page_id)) { | |
| 239 | - if (!isset($data['agree_terms']) || $data['agree_terms'] != 'yes') { | |
| 240 | - $errors->add('accept_tos', __('<strong>ERROR</strong>: You must accept our terms and conditions.', 'userswp')); | |
| 241 | - return $errors; | |
| 242 | - } | |
| 243 | - } | |
| 208 | + // If is current user's profile (profile.php) | |
| 209 | + if ( is_admin() && defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) { | |
| 210 | + $user_id = get_current_user_id(); | |
| 211 | + // If is another user's profile page | |
| 212 | + } elseif ( is_admin() && current_user_can( 'manage_options' ) && ! empty( $_GET['user_id'] ) && is_numeric( $_GET['user_id'] ) ) { | |
| 213 | + $user_id = absint( $_GET['user_id'] ); | |
| 214 | + // Otherwise something is wrong. | |
| 215 | + } else { | |
| 216 | + $user_id = get_current_user_id(); | |
| 217 | + } | |
| 244 | 218 | |
| 245 | - do_action('uwp_before_validate', 'register'); | |
| 219 | + // Ensure we have a valid URL with an allowed meme type. | |
| 220 | + $image_url = $this->normalize_url( esc_url( $data['uwp_crop'] ) ); | |
| 221 | + $filetype = wp_check_filetype( $image_url ); | |
| 246 | 222 | |
| 247 | - $result = uwp_validate_fields($data, 'register'); | |
| 248 | - | |
| 249 | - $result = apply_filters('uwp_validate_result', $result, 'register', $data); | |
| 223 | + $errors = new WP_Error(); | |
| 224 | + if ( empty( $image_url ) || empty( $filetype['ext'] ) ) { | |
| 225 | + $errors->add( 'something_wrong', __( 'Something went wrong. Please contact site admin.', 'userswp' ) ); | |
| 226 | + } | |
| 250 | 227 | |
| 251 | - if (is_wp_error($result)) { | |
| 252 | - return $result; | |
| 253 | - } | |
| 228 | + if ( $errors->has_errors() ) { | |
| 229 | + return $errors; | |
| 230 | + } | |
| 254 | 231 | |
| 255 | - $uploads_result = $file_obj->uwp_validate_uploads($files, 'register'); | |
| 232 | + // Retrieve current thumbnail. | |
| 233 | + $current_field = 'avatar' === $type ? 'avatar_thumb' : 'banner_thumb'; | |
| 234 | + $current_thumbnail = $this->normalize_url( uwp_get_usermeta( $user_id, $current_field, '' ) ); | |
| 235 | + $thumb_postfix = '_uwp_' . $type . '_thumb'; | |
| 256 | 236 | |
| 257 | - if (is_wp_error($uploads_result)) { | |
| 258 | - return $uploads_result; | |
| 259 | - } | |
| 237 | + if ( $image_url ) { | |
| 238 | + if ( $type == 'avatar' ) { | |
| 239 | + $avatar_size = uwp_get_upload_image_size(); | |
| 240 | + $full_width = $avatar_size['width']; | |
| 241 | + } else { | |
| 242 | + $banner_size = uwp_get_upload_image_size( 'banner' ); | |
| 243 | + $full_width = $banner_size['width']; | |
| 244 | + } | |
| 260 | 245 | |
| 261 | - do_action('uwp_after_validate', 'register'); | |
| 246 | + add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 ); | |
| 247 | + $uploads = wp_upload_dir(); | |
| 248 | + remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' ); | |
| 249 | + $upload_url = $uploads['baseurl']; | |
| 250 | + $upload_path = $uploads['basedir']; | |
| 251 | + $image_path = str_replace( $upload_url, $upload_path, $image_url ); | |
| 252 | + $ext = $filetype['ext']; // to get extension | |
| 253 | + $name = sanitize_file_name( pathinfo( $image_path, PATHINFO_FILENAME ) ); //file name without extension | |
| 254 | + $thumb_image_name = $name . $thumb_postfix . '.' . $ext; | |
| 255 | + $thumb_image_location = str_replace( $name . '.' . $ext, $thumb_image_name, $image_path ); | |
| 256 | + //Get the new coordinates to crop the image. | |
| 257 | + $x = $data['x']; | |
| 258 | + $y = $data['y']; | |
| 259 | + $w = $data['w']; | |
| 260 | + $h = $data['h']; | |
| 261 | + //Scale the image based on cropped width setting | |
| 262 | + $scale = $full_width / $w; | |
| 263 | + //$scale = 1; // no scaling | |
| 262 | 264 | |
| 263 | - $result = array_merge( $result, $uploads_result ); | |
| 265 | + // check we are not editing another user file | |
| 266 | + $db_value = trailingslashit( $uploads['subdir'] ) . $thumb_image_name; | |
| 267 | + $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta'; | |
| 268 | + $file_exists = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$meta_table} WHERE ( `avatar_thumb` = %s OR `banner_thumb` = %s ) ", $db_value, $db_value ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 264 | 269 | |
| 265 | - $error_code = $errors->get_error_code(); | |
| 266 | - if (!empty($error_code)) { | |
| 267 | - return $errors; | |
| 268 | - } | |
| 270 | + // if file already exists then we should not be cropping it. | |
| 271 | + if ( $file_exists ) { | |
| 272 | + wp_die( esc_html__( 'Something went wrong. Please contact site admin.', 'userswp' ), 403 ); | |
| 273 | + } | |
| 269 | 274 | |
| 270 | - if (isset($result['password']) && !empty($result['password'])) { | |
| 271 | - $password = $result['password']; | |
| 272 | - $generated_password = false; | |
| 273 | - } else { | |
| 274 | - $password = wp_generate_password(); | |
| 275 | - $this->generated_password = $password; | |
| 276 | - $generated_password = true; | |
| 277 | - } | |
| 275 | + $cropped = uwp_resizeThumbnailImage( $thumb_image_location, $image_path, $x, $y, $w, $h, $scale ); | |
| 276 | + $cropped = str_replace( $upload_path, $upload_url, $cropped ); | |
| 278 | 277 | |
| 279 | - $first_name = ""; | |
| 280 | - if (isset($result['uwp_account_first_name']) && !empty($result['uwp_account_first_name'])) { | |
| 281 | - $first_name = $result['uwp_account_first_name']; | |
| 282 | - } | |
| 278 | + // Remove previous avatar/banner | |
| 279 | + $unlink_img = ''; | |
| 280 | + if ( $unlink_prev_img && $current_thumbnail ) { | |
| 281 | + $unlink_img = untrailingslashit( $upload_path ) . '/' . ltrim( $current_thumbnail, '/' ); | |
| 282 | + } | |
| 283 | 283 | |
| 284 | - $last_name = ""; | |
| 285 | - if (isset($result['uwp_account_last_name']) && !empty($result['uwp_account_last_name'])) { | |
| 286 | - $last_name = $result['uwp_account_last_name']; | |
| 287 | - } | |
| 284 | + // remove the uploads path for easy migrations | |
| 285 | + $cropped = str_replace( $upload_url, '', $cropped ); | |
| 286 | + if ( $type == 'avatar' ) { | |
| 287 | + uwp_update_usermeta( $user_id, 'avatar_thumb', $cropped ); | |
| 288 | + } else { | |
| 289 | + uwp_update_usermeta( $user_id, 'banner_thumb', $cropped ); | |
| 290 | + } | |
| 288 | 291 | |
| 289 | - if (isset($result['uwp_account_display_name']) && !empty($result['uwp_account_display_name'])) { | |
| 290 | - $display_name = $result['uwp_account_display_name']; | |
| 291 | - } else { | |
| 292 | - if (!empty($first_name) || !empty($last_name)) { | |
| 293 | - $display_name = $first_name . ' ' . $last_name; | |
| 294 | - } else { | |
| 295 | - $display_name = $result['uwp_account_username']; | |
| 296 | - } | |
| 297 | - } | |
| 292 | + if ( $unlink_img && $unlink_img != $thumb_image_location && is_file( $unlink_img ) && file_exists( $unlink_img ) ) { | |
| 293 | + @unlink( $unlink_img ); | |
| 294 | + $unlink_ori_img = str_replace( '_uwp_' . $type . '_thumb' . '.', '.', $unlink_img ); | |
| 295 | + if ( is_file( $unlink_ori_img ) && file_exists( $unlink_ori_img ) ) { | |
| 296 | + @unlink( $unlink_ori_img ); | |
| 297 | + } | |
| 298 | + } | |
| 299 | + } | |
| 298 | 300 | |
| 299 | - $description = ""; | |
| 300 | - if (isset($result['uwp_account_bio']) && !empty($result['uwp_account_bio'])) { | |
| 301 | - $description = $result['uwp_account_bio']; | |
| 302 | - } | |
| 301 | + if ( is_admin() ) { | |
| 302 | + if ( $user_id == get_current_user_id() ) { | |
| 303 | + $redirect_url = admin_url( 'profile.php' ); | |
| 304 | + } else { | |
| 305 | + $redirect_url = admin_url( 'user-edit.php?user_id=' . $user_id ); | |
| 306 | + } | |
| 307 | + } elseif ( uwp_current_page_url() ) { | |
| 308 | + $redirect_url = uwp_current_page_url(); | |
| 309 | + } else { | |
| 310 | + $redirect_url = uwp_build_profile_tab_url( $user_id ); | |
| 311 | + } | |
| 303 | 312 | |
| 313 | + return $redirect_url; | |
| 314 | + } | |
| 304 | 315 | |
| 305 | - $args = array( | |
| 306 | - 'user_login' => $result['uwp_account_username'], | |
| 307 | - 'user_email' => $result['uwp_account_email'], | |
| 308 | - 'user_pass' => $password, | |
| 309 | - 'display_name' => $display_name, | |
| 310 | - 'first_name' => $first_name, | |
| 311 | - 'last_name' => $last_name, | |
| 312 | - 'description' => $description | |
| 313 | - ); | |
| 316 | + /** | |
| 317 | + * Normalizes a URL. | |
| 318 | + * | |
| 319 | + */ | |
| 320 | + public function normalize_url( $url ) { | |
| 314 | 321 | |
| 315 | - $user_id = wp_insert_user( $args ); | |
| 322 | + // Normalize. | |
| 323 | + $url = wp_normalize_path( $url ); | |
| 316 | 324 | |
| 317 | - if (!$user_id) { | |
| 318 | - $errors->add('registerfail', sprintf(__('<strong>Error</strong>: Something went wrong.', 'userswp'), get_option('admin_email'))); | |
| 319 | - return $errors; | |
| 320 | - } | |
| 325 | + // Remove query vars. | |
| 326 | + $url = strtok( $url, '?' ); | |
| 321 | 327 | |
| 322 | - $result = apply_filters('uwp_before_extra_fields_save', $result, 'register', $user_id); | |
| 328 | + // Split. | |
| 329 | + $url = explode( '/', $url ); | |
| 323 | 330 | |
| 324 | - $save_result = $this->uwp_save_user_extra_fields($user_id, $result, 'register'); | |
| 331 | + // Clean. | |
| 332 | + $url = array_diff( $url, array( '..', '.' ) ); | |
| 325 | 333 | |
| 326 | - $save_result = apply_filters('uwp_after_extra_fields_save', $save_result, $result, 'register', $user_id); | |
| 334 | + // Rejoin and return. | |
| 335 | + return implode( '/', $url ); | |
| 336 | + } | |
| 327 | 337 | |
| 328 | - if (is_wp_error($save_result)) { | |
| 329 | - return $save_result; | |
| 330 | - } | |
| 338 | + /** | |
| 339 | + * Processes avatar and banner image reset. | |
| 340 | + * | |
| 341 | + * @param string $type Image type. Default 'avatar'. | |
| 342 | + * | |
| 343 | + * @return bool|WP_Error|string Profile url. | |
| 344 | + * @package userswp | |
| 345 | + * | |
| 346 | + */ | |
| 347 | + public function process_image_reset( $type ) { | |
| 348 | + if ( ! is_user_logged_in() ) { | |
| 349 | + return false; | |
| 350 | + } | |
| 331 | 351 | |
| 332 | - if (!$save_result) { | |
| 333 | - $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp')); | |
| 334 | - } | |
| 352 | + if ( empty( $_POST['uwp_reset_nonce'] ) || ! wp_verify_nonce( $_POST['uwp_reset_nonce'], 'uwp_reset_nonce_' . $type ) ) { | |
| 353 | + return; | |
| 354 | + } | |
| 335 | 355 | |
| 336 | - $error_code = $errors->get_error_code(); | |
| 337 | - if (!empty($error_code)) { | |
| 338 | - return $errors; | |
| 339 | - } | |
| 356 | + if ( is_admin() && defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) { | |
| 357 | + $user_id = get_current_user_id(); | |
| 358 | + // If is another user's profile page | |
| 359 | + } elseif ( is_admin() && ! empty( $_GET['user_id'] ) && is_numeric( $_GET['user_id'] ) ) { | |
| 360 | + $user_id = absint( $_GET['user_id'] ); | |
| 361 | + // Otherwise something is wrong. | |
| 362 | + } else { | |
| 363 | + $user_id = get_current_user_id(); | |
| 364 | + } | |
| 340 | 365 | |
| 341 | - do_action('uwp_after_custom_fields_save', 'register', $data, $result, $user_id); | |
| 366 | + $errors = new WP_Error(); | |
| 367 | + if ( empty( $user_id ) ) { | |
| 368 | + $errors->add( 'something_wrong', __( 'Something went wrong. Please try again.', 'userswp' ) ); | |
| 369 | + } | |
| 342 | 370 | |
| 343 | - $reg_action = uwp_get_option('uwp_registration_action', false); | |
| 371 | + $error_code = $errors->get_error_code(); | |
| 372 | + if ( ! empty( $error_code ) ) { | |
| 373 | + return $errors; | |
| 374 | + } | |
| 344 | 375 | |
| 345 | - if ($reg_action == 'require_email_activation' && !$generated_password) { | |
| 376 | + if ( $type == 'avatar' ) { | |
| 377 | + uwp_update_usermeta( $user_id, 'avatar_thumb', '' ); | |
| 378 | + } elseif ( $type == 'banner' ) { | |
| 379 | + uwp_update_usermeta( $user_id, 'banner_thumb', '' ); | |
| 380 | + } else { | |
| 381 | + // Do nothing | |
| 382 | + } | |
| 346 | 383 | |
| 347 | - $email = new UsersWP_Mails(); | |
| 348 | - $send_result = $email->send( 'activate', $user_id ); | |
| 384 | + if ( is_admin() ) { | |
| 385 | + if ( $user_id == get_current_user_id() ) { | |
| 386 | + $redirect_url = admin_url( 'profile.php' ); | |
| 387 | + } else { | |
| 388 | + $redirect_url = admin_url( 'user-edit.php?user_id=' . $user_id ); | |
| 389 | + } | |
| 390 | + } elseif ( uwp_current_page_url() ) { | |
| 391 | + $redirect_url = uwp_current_page_url(); | |
| 392 | + } else { | |
| 393 | + $redirect_url = uwp_build_profile_tab_url( $user_id ); | |
| 394 | + } | |
| 349 | 395 | |
| 350 | - if (!$send_result) { | |
| 351 | - $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong when sending email. Please contact site admin.', 'userswp')); | |
| 352 | - } | |
| 353 | - } else { | |
| 354 | - $email = new UsersWP_Mails(); | |
| 355 | - $send_result = $email->send( 'register', $user_id ); | |
| 396 | + return $redirect_url; | |
| 397 | + } | |
| 356 | 398 | |
| 357 | - if (!$send_result) { | |
| 358 | - $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong when sending email. Please contact site admin.', 'userswp')); | |
| 359 | - } | |
| 360 | - } | |
| 399 | + /** | |
| 400 | + * Displays links in a dropdown | |
| 401 | + * | |
| 402 | + * @param $options | |
| 403 | + * | |
| 404 | + * @package userswp | |
| 405 | + * | |
| 406 | + * @since 1.0.0 | |
| 407 | + */ | |
| 408 | + public function output_dashboard_links( $options ) { | |
| 409 | + if ( ! empty( $options ) ) { | |
| 410 | + $class = uwp_get_option( 'design_style', 'bootstrap' ) == 'bootstrap' ? 'form-control' : 'aui-select2'; | |
| 411 | + echo '<select class="' . esc_attr( $class ) . '" onchange="window.location = jQuery(this).val();">'; | |
| 412 | + $this->output_options( $options ); | |
| 413 | + echo '</select>'; | |
| 414 | + } | |
| 415 | + } | |
| 361 | 416 | |
| 362 | - if ($reg_action != 'require_admin_review') { | |
| 363 | - $register_admin_notify = uwp_get_option('register_admin_notify', ''); | |
| 364 | - if ($register_admin_notify == '1') { | |
| 365 | - $admin_register_send_result = $email->send_admin_email('register_admin', $user_id); | |
| 366 | - if (is_wp_error($admin_register_send_result)) { | |
| 367 | - return $admin_register_send_result; | |
| 368 | - } | |
| 369 | - } | |
| 417 | + /** | |
| 418 | + * Displays options for the dashboard links | |
| 419 | + * | |
| 420 | + * @param $options | |
| 421 | + * | |
| 422 | + * @package userswp | |
| 423 | + * | |
| 424 | + * @since 1.0.0 | |
| 425 | + */ | |
| 426 | + public function output_options( $options ) { | |
| 427 | + if ( ! empty( $options ) ) { | |
| 428 | + foreach ( $options as $key => $link ) { | |
| 370 | 429 | |
| 371 | - } | |
| 430 | + if ( ! isset( $link['text'] ) && isset( $link[0] ) && is_array( $link[0] ) ) { | |
| 431 | + $this->output_options( $link ); | |
| 432 | + } elseif ( ! empty( $link['optgroup'] ) && $link['optgroup'] == 'open' ) { | |
| 433 | + echo "<optgroup label='" . esc_attr( $link['text'] ) . "'>"; | |
| 434 | + } elseif ( ! empty( $link['optgroup'] ) && $link['optgroup'] == 'close' ) { | |
| 435 | + echo '</optgroup>'; | |
| 436 | + } elseif ( ! empty( $link['text'] ) ) { | |
| 437 | + echo '<option value="' . ( ! empty( $link['url'] ) ? esc_url( $link['url'] ) : '' ) . '"' . selected( ! empty( $link['selected'] ), true, false ) . ( ! empty( $link['disabled'] ) ? ' disabled' : '' ) . '' . ( ! empty( $link['display_none'] ) ? ' style="display:none;"' : '' ) . '>'; | |
| 438 | + echo esc_attr__( $link['text'], 'userswp' ); | |
| 439 | + echo '</option>'; | |
| 440 | + } | |
| 441 | + } | |
| 442 | + } | |
| 443 | + } | |
| 372 | 444 | |
| 445 | + /** | |
| 446 | + * Displays UsersWP notices in forms. | |
| 447 | + * | |
| 448 | + * @param string $type Form type | |
| 449 | + * | |
| 450 | + * @return void | |
| 451 | + * @since 1.0.0 | |
| 452 | + * @package userswp | |
| 453 | + * | |
| 454 | + */ | |
| 455 | + public function display_notices( $type ) { | |
| 456 | + global $uwp_notices; | |
| 373 | 457 | |
| 374 | - $error_code = $errors->get_error_code(); | |
| 375 | - if (!empty($error_code)) { | |
| 376 | - return $errors; | |
| 377 | - } | |
| 458 | + if ( is_array( $uwp_notices ) ) { | |
| 459 | + foreach ( $uwp_notices as $notice ) { | |
| 378 | 460 | |
| 379 | - if ($reg_action == 'auto_approve_login') { | |
| 380 | - $res = wp_signon( | |
| 461 | + // If the notification is type specific then only output on that type | |
| 462 | + if ( is_array( $notice ) ) { | |
| 463 | + foreach ( $notice as $key => $val ) { | |
| 464 | + if ( $key == $type ) { | |
| 465 | + echo wp_kses_post( $val ); | |
| 466 | + } | |
| 467 | + } | |
| 468 | + } elseif ( ! empty( $notice ) ) { | |
| 469 | + echo wp_kses_post( $notice ); | |
| 470 | + } | |
| 471 | +} | |
| 472 | +} | |
| 473 | + | |
| 474 | + if ( $type == 'change' ) { | |
| 475 | + $user_id = get_current_user_id(); | |
| 476 | + $password_nag = get_user_option( 'default_password_nag', $user_id ); | |
| 477 | + | |
| 478 | + if ( $password_nag ) { | |
| 479 | + $change_page = uwp_get_page_id( 'change_page', false ); | |
| 480 | + $remove_nag_url = add_query_arg( 'uwp_remove_nag', 'yes', get_permalink( $change_page ) ); | |
| 481 | + | |
| 482 | + if ( isset( $_GET['uwp_remove_nag'] ) && $_GET['uwp_remove_nag'] == 'yes' ) { | |
| 483 | + delete_user_meta( $user_id, 'default_password_nag' ); | |
| 484 | + $message = sprintf( __( 'We have removed the system generated password warning for you. From this point forward you can continue to access our site as usual. To go to home page, <a href="%s">click here</a>.', 'userswp' ), home_url( '/' ) ); | |
| 485 | + echo aui()->alert( | |
| 486 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 487 | + 'class' => 'text-center', | |
| 488 | + 'type' => 'success', | |
| 489 | + 'content' => wp_kses_post( $message ), | |
| 490 | + ) | |
| 491 | + ); | |
| 492 | + } else { | |
| 493 | + $message = sprintf( __( '<strong>Warning</strong>: It seems like you are using a system generated password. Please change the password in this page. If this is not a problem for you, you can remove this warning by <a href="%s">clicking here</a>.', 'userswp' ), $remove_nag_url ); | |
| 494 | + echo aui()->alert( | |
| 495 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 496 | + 'class' => 'text-center', | |
| 497 | + 'type' => 'warning', | |
| 498 | + 'content' => wp_kses_post( $message ), | |
| 499 | + ) | |
| 500 | + ); | |
| 501 | + } | |
| 502 | + } | |
| 503 | + } | |
| 504 | + } | |
| 505 | + | |
| 506 | + /** | |
| 507 | + * Processes register form submission. | |
| 508 | + * | |
| 509 | + * @since 1.0.0 | |
| 510 | + * @package userswp | |
| 511 | + * | |
| 512 | + */ | |
| 513 | + public function process_register() { | |
| 514 | + | |
| 515 | + $data = $_POST; | |
| 516 | + | |
| 517 | + if ( ! isset( $data['uwp_register_nonce'] ) ) { | |
| 518 | + return; | |
| 519 | + } | |
| 520 | + | |
| 521 | + global $uwp_notices; | |
| 522 | + | |
| 523 | + if ( isset( $data['uwp_register_hp'] ) && '' != $data['uwp_register_hp'] ) { | |
| 524 | + wp_die( esc_html__( 'No spam please!', 'userswp' ) ); | |
| 525 | + } | |
| 526 | + | |
| 527 | + if ( ! isset( $data['uwp_register_nonce'] ) || ! wp_verify_nonce( $data['uwp_register_nonce'], 'uwp-register-nonce' ) ) { | |
| 528 | + $message = aui()->alert( | |
| 381 | 529 | array( |
| 382 | - 'user_login' => $result['uwp_account_username'], | |
| 383 | - 'user_password' => $password, | |
| 384 | - 'remember' => false | |
| 530 | + 'type' => 'error', | |
| 531 | + 'content' => __( 'Security verification failed. Try again.', 'userswp' ), | |
| 385 | 532 | ) |
| 386 | - ); | |
| 533 | + ); | |
| 534 | + if ( wp_doing_ajax() ) { | |
| 535 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 536 | + } else { | |
| 537 | + $uwp_notices[] = array( 'register' => $message ); | |
| 387 | 538 | |
| 388 | - if (is_wp_error($res)) { | |
| 389 | - $errors->add('invalid_userorpass', __('<strong>Error</strong>: Invalid username or Password.', 'userswp')); | |
| 390 | - return $errors; | |
| 391 | - } else { | |
| 392 | - $reg_redirect_page_id = uwp_get_option('register_redirect_to', ''); | |
| 393 | - if(isset( $_REQUEST['redirect_to'] )) { | |
| 394 | - $reg_redirect_to = esc_url($_REQUEST['redirect_to']); | |
| 395 | - } elseif (empty($reg_redirect_page_id)) { | |
| 396 | - $reg_redirect_to = home_url('/'); | |
| 397 | - } else { | |
| 398 | - $reg_redirect_to = get_permalink($reg_redirect_page_id); | |
| 539 | + return; | |
| 540 | + } | |
| 541 | + } | |
| 542 | + | |
| 543 | + $hash = substr( hash( 'SHA256', AUTH_KEY . site_url() ), 0, 25 ); | |
| 544 | + if ( empty( $data['uwp_register_hash'] ) || $hash != $data['uwp_register_hash'] ) { | |
| 545 | + $message = aui()->alert( | |
| 546 | + array( | |
| 547 | + 'type' => 'error', | |
| 548 | + 'content' => __( 'Security hash failed. Try again.', 'userswp' ), | |
| 549 | + ) | |
| 550 | + ); | |
| 551 | + if ( wp_doing_ajax() ) { | |
| 552 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 553 | + } else { | |
| 554 | + $uwp_notices[] = array( 'register' => $message ); | |
| 555 | + | |
| 556 | + return; | |
| 557 | + } | |
| 558 | + } | |
| 559 | + | |
| 560 | + if ( ! get_option( 'users_can_register' ) ) { | |
| 561 | + $message = aui()->alert( | |
| 562 | + array( | |
| 563 | + 'type' => 'error', | |
| 564 | + 'content' => __( 'User registration is currently not allowed. Please check settings of your site.', 'userswp' ), | |
| 565 | + ) | |
| 566 | + ); | |
| 567 | + if ( wp_doing_ajax() ) { | |
| 568 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 569 | + } else { | |
| 570 | + $uwp_notices[] = array( 'register' => $message ); | |
| 571 | + | |
| 572 | + return; | |
| 573 | + } | |
| 574 | + } | |
| 575 | + | |
| 576 | + $files = $_FILES; | |
| 577 | + $errors = new WP_Error(); | |
| 578 | + $file_obj = new UsersWP_Files(); | |
| 579 | + | |
| 580 | + do_action( 'uwp_before_validate', 'register' ); | |
| 581 | + | |
| 582 | + $result = uwp_validate_fields( $data, 'register' ); | |
| 583 | + | |
| 584 | + $result = apply_filters( 'uwp_validate_result', $result, 'register', $data ); | |
| 585 | + | |
| 586 | + if ( is_wp_error( $result ) ) { | |
| 587 | + $message = aui()->alert( | |
| 588 | + array( | |
| 589 | + 'type' => 'error', | |
| 590 | + 'content' => $result->get_error_message(), | |
| 591 | + ) | |
| 592 | + ); | |
| 593 | + if ( wp_doing_ajax() ) { | |
| 594 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 595 | + } else { | |
| 596 | + $uwp_notices[] = array( 'register' => $message ); | |
| 597 | + | |
| 598 | + return; | |
| 599 | + } | |
| 600 | + } | |
| 601 | + | |
| 602 | + $uploads_result = $file_obj->validate_uploads( $files, 'register' ); | |
| 603 | + | |
| 604 | + if ( is_wp_error( $uploads_result ) ) { | |
| 605 | + $message = aui()->alert( | |
| 606 | + array( | |
| 607 | + 'type' => 'error', | |
| 608 | + 'content' => $uploads_result->get_error_message(), | |
| 609 | + ) | |
| 610 | + ); | |
| 611 | + if ( wp_doing_ajax() ) { | |
| 612 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 613 | + } else { | |
| 614 | + $uwp_notices[] = array( 'register' => $message ); | |
| 615 | + | |
| 616 | + return; | |
| 617 | + } | |
| 618 | + } | |
| 619 | + | |
| 620 | + do_action( 'uwp_after_validate', $result, 'register', $data ); | |
| 621 | + | |
| 622 | + $result = array_merge( $result, $uploads_result ); | |
| 623 | + | |
| 624 | + if ( isset( $result['password'] ) && ! empty( $result['password'] ) ) { | |
| 625 | + $password = $result['password']; | |
| 626 | + $generated_password = false; | |
| 627 | + } else { | |
| 628 | + $password = wp_generate_password(); | |
| 629 | + $this->generated_password = $password; | |
| 630 | + $generated_password = true; | |
| 631 | + } | |
| 632 | + | |
| 633 | + $first_name = ''; | |
| 634 | + if ( isset( $result['first_name'] ) && ! empty( $result['first_name'] ) ) { | |
| 635 | + $first_name = $result['first_name']; | |
| 636 | + } | |
| 637 | + | |
| 638 | + $last_name = ''; | |
| 639 | + if ( isset( $result['last_name'] ) && ! empty( $result['last_name'] ) ) { | |
| 640 | + $last_name = $result['last_name']; | |
| 641 | + } | |
| 642 | + | |
| 643 | + if ( isset( $result['display_name'] ) && ! empty( $result['display_name'] ) ) { | |
| 644 | + $display_name = $result['display_name']; | |
| 645 | + } elseif ( ! empty( $first_name ) || ! empty( $last_name ) ) { | |
| 646 | + $display_name = $first_name . ' ' . $last_name; | |
| 647 | + } else { | |
| 648 | + $display_name = ! empty( $result['username'] ) ? $result['username'] : ''; | |
| 649 | + } | |
| 650 | + | |
| 651 | + $user_url = ''; | |
| 652 | + if ( isset( $result['user_url'] ) && ! empty( $result['user_url'] ) ) { | |
| 653 | + $user_url = esc_url_raw( $result['user_url'] ); | |
| 654 | + } | |
| 655 | + | |
| 656 | + $user_login = ! empty( $result['username'] ) ? $result['username'] : ''; | |
| 657 | + $email = ! empty( $result['email'] ) ? sanitize_email( $result['email'] ) : ''; | |
| 658 | + | |
| 659 | + if ( empty( $user_login ) ) { | |
| 660 | + $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true ); | |
| 661 | + if ( ! ( validate_username( $user_login ) && ! username_exists( $user_login ) ) ) { | |
| 662 | + $new_user_login = strstr( $email, '@', true ); | |
| 663 | + if ( validate_username( $user_login ) && username_exists( $user_login ) ) { | |
| 664 | + $user_login = sanitize_user( $new_user_login, true ); | |
| 665 | + } | |
| 666 | + if ( validate_username( $user_login ) && username_exists( $user_login ) ) { | |
| 667 | + $user_append_text = rand( 10, 1000 ); | |
| 668 | + $user_login = sanitize_user( $new_user_login . $user_append_text, true ); | |
| 669 | + } | |
| 670 | + | |
| 671 | + if ( ! ( validate_username( $user_login ) && ! username_exists( $user_login ) ) ) { | |
| 672 | + $user_login = $email; | |
| 673 | + } | |
| 674 | + } | |
| 675 | + } elseif ( ! validate_username( $user_login ) ) { | |
| 676 | + $message = aui()->alert( | |
| 677 | + array( | |
| 678 | + 'type' => 'error', | |
| 679 | + 'content' => __( 'Sorry, that username is not allowed.', 'userswp' ), | |
| 680 | + ) | |
| 681 | + ); | |
| 682 | + if ( wp_doing_ajax() ) { | |
| 683 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 684 | + } else { | |
| 685 | + $uwp_notices[] = array( 'register' => $message ); | |
| 686 | + | |
| 687 | + return; | |
| 688 | + } | |
| 689 | + } | |
| 690 | + | |
| 691 | + $args = array( | |
| 692 | + 'user_login' => sanitize_user( $user_login ), | |
| 693 | + 'user_email' => sanitize_email( $email ), | |
| 694 | + 'user_pass' => $password, | |
| 695 | + 'display_name' => sanitize_text_field( $display_name ), | |
| 696 | + 'first_name' => esc_attr( $first_name ), | |
| 697 | + 'last_name' => esc_attr( $last_name ), | |
| 698 | + 'user_url' => esc_url_raw( $user_url ), | |
| 699 | + ); | |
| 700 | + | |
| 701 | + $user_id = wp_insert_user( $args ); | |
| 702 | + | |
| 703 | + if ( is_wp_error( $user_id ) ) { | |
| 704 | + $message = aui()->alert( | |
| 705 | + array( | |
| 706 | + 'type' => 'error', | |
| 707 | + 'content' => $user_id->get_error_message(), | |
| 708 | + ) | |
| 709 | + ); | |
| 710 | + if ( wp_doing_ajax() ) { | |
| 711 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 712 | + } else { | |
| 713 | + $uwp_notices[] = array( 'register' => $message ); | |
| 714 | + | |
| 715 | + return; | |
| 716 | + } | |
| 717 | + } | |
| 718 | + | |
| 719 | + $result = apply_filters( 'uwp_before_extra_fields_save', $result, 'register', $user_id ); | |
| 720 | + | |
| 721 | + $form_id = 1; | |
| 722 | + | |
| 723 | + if ( isset( $data['uwp_register_form_id'] ) && ! empty( $data['uwp_register_form_id'] ) ) { | |
| 724 | + update_user_meta( $user_id, '_uwp_register_form_id', (int) $data['uwp_register_form_id'] ); | |
| 725 | + $form_id = (int) $data['uwp_register_form_id']; | |
| 726 | + } | |
| 727 | + | |
| 728 | + $user_role = uwp_get_register_form_by( $form_id, 'user_role' ); | |
| 729 | + | |
| 730 | + if ( isset( $user_role ) && ! empty( $user_role ) ) { | |
| 731 | + $user_roles = uwp_get_user_roles(); | |
| 732 | + $chosen_role = strtolower( $user_role ); | |
| 733 | + if ( ! empty( $user_roles ) ) { | |
| 734 | + $wp_roles = wp_roles(); | |
| 735 | + if ( $wp_roles->is_role( $chosen_role ) && in_array( $chosen_role, array_keys( $user_roles ) ) ) { | |
| 736 | + $new_user = get_userdata( $user_id ); | |
| 737 | + if ( $new_user ) { | |
| 738 | + $new_user->set_role( $chosen_role ); | |
| 739 | + } | |
| 740 | + } | |
| 741 | + } | |
| 742 | + } | |
| 743 | + | |
| 744 | + $save_result = $this->save_user_extra_fields( $user_id, $result, 'register' ); | |
| 745 | + | |
| 746 | + $save_result = apply_filters( 'uwp_after_extra_fields_save', $save_result, $result, 'register', $user_id ); | |
| 747 | + | |
| 748 | + if ( is_wp_error( $save_result ) ) { | |
| 749 | + $message = aui()->alert( | |
| 750 | + array( | |
| 751 | + 'type' => 'error', | |
| 752 | + 'content' => $save_result->get_error_message(), | |
| 753 | + ) | |
| 754 | + ); | |
| 755 | + if ( wp_doing_ajax() ) { | |
| 756 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 757 | + } else { | |
| 758 | + $uwp_notices[] = array( 'register' => $message ); | |
| 759 | + | |
| 760 | + return; | |
| 761 | + } | |
| 762 | + } | |
| 763 | + | |
| 764 | + if ( ! $save_result ) { | |
| 765 | + $message = aui()->alert( | |
| 766 | + array( | |
| 767 | + 'type' => 'error', | |
| 768 | + 'content' => __( 'Something went wrong. Please contact site admin.', 'userswp' ), | |
| 769 | + ) | |
| 770 | + ); | |
| 771 | + if ( wp_doing_ajax() ) { | |
| 772 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 773 | + } else { | |
| 774 | + $uwp_notices[] = array( 'register' => $message ); | |
| 775 | + | |
| 776 | + return; | |
| 777 | + } | |
| 778 | + } | |
| 779 | + | |
| 780 | + //updating bio field after saving extra fields to reflect the points in mycred add on. | |
| 781 | + if ( isset( $result['bio'] ) && ! empty( $result['bio'] ) ) { | |
| 782 | + $args = array( | |
| 783 | + 'ID' => $user_id, | |
| 784 | + 'description' => $result['bio'], | |
| 785 | + ); | |
| 786 | + wp_update_user( $args ); | |
| 787 | + } | |
| 788 | + | |
| 789 | + do_action( 'uwp_after_custom_fields_save', 'register', $data, $result, $user_id ); | |
| 790 | + | |
| 791 | + // Unset post data to empty the form on submit | |
| 792 | + $excluded_post_data = apply_filters( 'uwp_register_excluded_post_reset_fields', array( 'uwp_register_nonce' ) ); | |
| 793 | + foreach ( $data as $key => $value ) { | |
| 794 | + if ( isset( $key ) && ! in_array( $key, $excluded_post_data ) ) { | |
| 795 | + unset( $_POST[ $key ] ); | |
| 796 | + } | |
| 797 | + } | |
| 798 | + | |
| 799 | + $reg_action = uwp_get_register_form_by( $form_id, 'reg_action' ); | |
| 800 | + if ( ! $reg_action ) { | |
| 801 | + $reg_action = uwp_get_option( 'uwp_registration_action', false ); | |
| 802 | + } | |
| 803 | + | |
| 804 | + $form_fields = apply_filters( 'uwp_send_mail_form_fields', '', 'register', $user_id ); | |
| 805 | + | |
| 806 | + if ( $reg_action == 'require_email_activation' && ! $generated_password ) { | |
| 807 | + | |
| 808 | + $user_data = get_userdata( $user_id ); | |
| 809 | + $activation_link = uwp_get_activation_link( $user_id ); | |
| 810 | + | |
| 811 | + $message = __( 'To activate your account, visit the following address:', 'userswp' ) . "\r\n\r\n"; | |
| 812 | + | |
| 813 | + $message .= "<a href='" . esc_url_raw( $activation_link ) . "' target='_blank'>" . esc_url_raw( $activation_link ) . '</a>' . "\r\n"; | |
| 814 | + | |
| 815 | + $activate_message = '<p><b>' . __( 'Please activate your account :', 'userswp' ) . '</b></p><p>' . $message . '</p>'; | |
| 816 | + | |
| 817 | + $activate_message = apply_filters( 'uwp_activation_mail_message', $activate_message, $user_id ); | |
| 818 | + | |
| 819 | + $email_vars = array( | |
| 820 | + 'user_id' => $user_id, | |
| 821 | + 'login_details' => $activate_message, | |
| 822 | + 'activation_link' => $activation_link, | |
| 823 | + ); | |
| 824 | + | |
| 825 | + UsersWP_Mails::send( $user_data->user_email, 'registration_activate', $email_vars ); | |
| 826 | + | |
| 827 | + } elseif ( $reg_action != 'require_admin_review' ) { | |
| 828 | + | |
| 829 | + $user_data = get_userdata( $user_id ); | |
| 830 | + | |
| 831 | + if ( isset( $this->generated_password ) && ! empty( $this->generated_password ) ) { | |
| 832 | + if ( ! uwp_get_option( 'change_disable_password_nag' ) ) { | |
| 833 | + update_user_meta( $user_id, 'default_password_nag', true ); //Set up the Password change nag. | |
| 834 | + } | |
| 835 | + $message_pass = $this->generated_password; | |
| 836 | + $this->generated_password = false; | |
| 837 | + } else { | |
| 838 | + $message_pass = __( 'Password you entered during registration.', 'userswp' ); | |
| 839 | + } | |
| 840 | + | |
| 841 | + $message = '<p><b>' . __( 'Your login Information :', 'userswp' ) . '</b></p> | |
| 842 | + <p>' . __( 'Username:', 'userswp' ) . ' ' . $user_data->user_login . '</p> | |
| 843 | + <p>' . __( 'Password:', 'userswp' ) . ' ' . $message_pass . '</p>'; | |
| 844 | + | |
| 845 | + $message = apply_filters( 'uwp_register_mail_message', $message, $user_id, $this->generated_password ); | |
| 846 | + | |
| 847 | + $email_vars = array( | |
| 848 | + 'user_id' => $user_id, | |
| 849 | + 'login_details' => $message, | |
| 850 | + 'form_fields' => $form_fields, | |
| 851 | + ); | |
| 852 | + | |
| 853 | + UsersWP_Mails::send( $user_data->user_email, 'registration_success', $email_vars ); | |
| 854 | + } | |
| 855 | + | |
| 856 | + $error_code = $errors->get_error_code(); | |
| 857 | + if ( ! empty( $error_code ) ) { | |
| 858 | + $message = aui()->alert( | |
| 859 | + array( | |
| 860 | + 'type' => 'error', | |
| 861 | + 'content' => $result->get_error_message(), | |
| 862 | + ) | |
| 863 | + ); | |
| 864 | + if ( wp_doing_ajax() ) { | |
| 865 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 866 | + } else { | |
| 867 | + $uwp_notices[] = array( 'register' => $message ); | |
| 868 | + return; | |
| 869 | + } | |
| 870 | + } | |
| 871 | + | |
| 872 | + if ( $reg_action != 'require_admin_review' ) { | |
| 873 | + | |
| 874 | + $user_data = get_userdata( $user_id ); | |
| 875 | + $extras = '<p><b>' . __( 'User Information :', 'userswp' ) . '</b></p> | |
| 876 | + <p>' . __( 'First Name:', 'userswp' ) . ' ' . $user_data->first_name . '</p> | |
| 877 | + <p>' . __( 'Last Name:', 'userswp' ) . ' ' . $user_data->last_name . '</p> | |
| 878 | + <p>' . __( 'Username:', 'userswp' ) . ' ' . $user_data->user_login . '</p> | |
| 879 | + <p>' . __( 'Email:', 'userswp' ) . ' ' . $user_data->user_email . '</p>'; | |
| 880 | + | |
| 881 | + $extras = apply_filters( 'uwp_admin_mail_extras', $extras, 'register_admin', $user_id ); | |
| 882 | + | |
| 883 | + $email_vars = array( | |
| 884 | + 'user_id' => $user_id, | |
| 885 | + 'extras' => $extras, | |
| 886 | + 'form_fields' => $form_fields, | |
| 887 | + ); | |
| 888 | + | |
| 889 | + UsersWP_Mails::send( get_option( 'admin_email' ), 'registration_success', $email_vars, true ); | |
| 890 | + | |
| 891 | + } | |
| 892 | + | |
| 893 | + if ( $reg_action == 'auto_approve_login' ) { | |
| 894 | + $res = wp_signon( | |
| 895 | + array( | |
| 896 | + 'user_login' => $user_login, | |
| 897 | + 'user_password' => $password, | |
| 898 | + 'remember' => false, | |
| 899 | + ) | |
| 900 | + ); | |
| 901 | + | |
| 902 | + if ( is_wp_error( $res ) ) { | |
| 903 | + $message = aui()->alert( | |
| 904 | + array( | |
| 905 | + 'type' => 'error', | |
| 906 | + 'content' => $res->get_error_message(), | |
| 907 | + ) | |
| 908 | + ); | |
| 909 | + | |
| 910 | + if ( wp_doing_ajax() ) { | |
| 911 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 912 | + } else { | |
| 913 | + $uwp_notices[] = array( 'register' => $message ); | |
| 914 | + } | |
| 915 | + } else { | |
| 916 | + $redirect_to = $this->get_register_redirect_url( $data, $user_id ); | |
| 917 | + do_action( 'uwp_after_process_register', $result, $user_id ); | |
| 918 | + | |
| 919 | + if ( wp_doing_ajax() ) { | |
| 920 | + $message = aui()->alert( | |
| 921 | + array( | |
| 922 | + 'type' => 'success', | |
| 923 | + 'content' => __( 'Account registered successfully. Redirecting...', 'userswp' ), | |
| 924 | + ) | |
| 925 | + ); | |
| 926 | + $response = array( | |
| 927 | + 'message' => $message, | |
| 928 | + 'redirect' => $redirect_to, | |
| 929 | + ); | |
| 930 | + wp_send_json_success( $response ); | |
| 931 | + } else { | |
| 932 | + wp_safe_redirect( $redirect_to ); | |
| 933 | + } | |
| 934 | + exit(); | |
| 935 | + } | |
| 936 | + } else { | |
| 937 | + if ( $reg_action == 'require_email_activation' ) { | |
| 938 | + $resend_link = uwp_get_register_page_url(); | |
| 939 | + $resend_link = add_query_arg( | |
| 940 | + array( | |
| 941 | + 'user_id' => $user_id, | |
| 942 | + 'action' => 'uwp_resend', | |
| 943 | + '_nonce' => wp_create_nonce( 'uwp_resend' ), | |
| 944 | + ), | |
| 945 | + $resend_link | |
| 946 | + ); | |
| 947 | + | |
| 948 | + $message = aui()->alert( | |
| 949 | + array( | |
| 950 | + 'type' => 'success', | |
| 951 | + 'content' => sprintf( __( 'An email has been sent to your registered email address. Please click the activation link to proceed. <a href="%s">Resend</a>.', 'userswp' ), $resend_link ), | |
| 952 | + ) | |
| 953 | + ); | |
| 954 | + | |
| 955 | + } elseif ( $reg_action == 'require_admin_review' && defined( 'UWP_MOD_VERSION' ) ) { | |
| 956 | + | |
| 957 | + update_user_meta( $user_id, 'uwp_mod', '1' ); | |
| 958 | + | |
| 959 | + do_action( 'uwp_require_admin_review', $user_id, $result ); | |
| 960 | + | |
| 961 | + $message = aui()->alert( | |
| 962 | + array( | |
| 963 | + 'type' => 'success', | |
| 964 | + 'content' => __( 'Your account is under moderation. We will email you once its approved.', 'userswp' ), | |
| 965 | + ) | |
| 966 | + ); | |
| 967 | + } else { | |
| 968 | + | |
| 969 | + $login_page_url = wp_login_url(); | |
| 970 | + | |
| 971 | + if ( $generated_password ) { | |
| 972 | + $msg = sprintf( __( 'Account registered successfully. A password has been generated and mailed to your registered Email ID. Please login %1$shere%2$s.', 'userswp' ), '<a href="' . $login_page_url . '">', '</a>' ); | |
| 973 | + } else { | |
| 974 | + $msg = sprintf( __( 'Account registered successfully. Please login %1$shere%2$s', 'userswp' ), '<a href="' . $login_page_url . '">', '</a>' ); | |
| 975 | + } | |
| 976 | + | |
| 977 | + $message = aui()->alert( | |
| 978 | + array( | |
| 979 | + 'type' => 'success', | |
| 980 | + 'content' => $msg, | |
| 981 | + ) | |
| 982 | + ); | |
| 983 | + } | |
| 984 | + | |
| 985 | + do_action( 'uwp_after_process_register', $result, $user_id ); | |
| 986 | + | |
| 987 | + if ( wp_doing_ajax() ) { | |
| 988 | + wp_send_json_success( array( 'message' => $message ) ); | |
| 989 | + } else { | |
| 990 | + $uwp_notices[] = array( 'register' => $message ); | |
| 991 | + } | |
| 992 | + } | |
| 993 | + | |
| 994 | + if ( wp_doing_ajax() ) { | |
| 995 | + wp_send_json_error(); | |
| 996 | + } // if we got this far there is a problem | |
| 997 | + } | |
| 998 | + | |
| 999 | + /** | |
| 1000 | + * Saves UsersWP related user custom fields. | |
| 1001 | + * | |
| 1002 | + * @param int $user_id User ID. | |
| 1003 | + * @param array $data Result array. | |
| 1004 | + * @param string $type Form type. | |
| 1005 | + * | |
| 1006 | + * @return bool True when success. False when failure. | |
| 1007 | + * @since 1.0.0 | |
| 1008 | + * @package userswp | |
| 1009 | + * | |
| 1010 | + */ | |
| 1011 | + public function save_user_extra_fields( $user_id, $data, $type ) { | |
| 1012 | + | |
| 1013 | + if ( empty( $user_id ) || empty( $data ) || empty( $type ) ) { | |
| 1014 | + return false; | |
| 1015 | + } | |
| 1016 | + | |
| 1017 | + // custom user fields not applicable for login and forgot | |
| 1018 | + if ( $type == 'login' || $type == 'forgot' ) { | |
| 1019 | + return true; | |
| 1020 | + } | |
| 1021 | + | |
| 1022 | + if ( $type == 'account' || $type == 'register' ) { | |
| 1023 | + if ( isset( $data['password'] ) ) { | |
| 1024 | + unset( $data['password'] ); | |
| 1025 | + } | |
| 1026 | + } | |
| 1027 | + | |
| 1028 | + if ( $type == 'register' ) { | |
| 1029 | + if ( isset( $data['username'] ) ) { | |
| 1030 | + unset( $data['username'] ); | |
| 1031 | + } | |
| 1032 | + if ( isset( $data['email'] ) ) { | |
| 1033 | + unset( $data['email'] ); | |
| 1034 | + } | |
| 1035 | + } | |
| 1036 | + | |
| 1037 | + if ( empty( $data ) ) { | |
| 1038 | + // no extra fields. so just return | |
| 1039 | + return true; | |
| 1040 | + } else { | |
| 1041 | + foreach ( $data as $key => $value ) { | |
| 1042 | + if ( 'uwp_language' == $key ) { | |
| 1043 | + update_user_meta( $user_id, 'locale', $value ); | |
| 1044 | + } | |
| 1045 | + uwp_update_usermeta( $user_id, $key, $value ); | |
| 1046 | + } | |
| 1047 | + | |
| 1048 | + return true; | |
| 1049 | + } | |
| 1050 | + } | |
| 1051 | + | |
| 1052 | + public function get_register_redirect_url( $data, $user ) { | |
| 1053 | + if ( is_int( $user ) ) { | |
| 1054 | + $user = get_userdata( $user ); | |
| 1055 | + } | |
| 1056 | + | |
| 1057 | + $redirect_page_id = $custom_url = ''; | |
| 1058 | + if ( isset( $data['uwp_register_form_id'] ) && ! empty( $data['uwp_register_form_id'] ) ) { | |
| 1059 | + $form_id = (int) $data['uwp_register_form_id']; | |
| 1060 | + $redirect_page_id = uwp_get_register_form_by( $form_id, 'redirect_to' ); | |
| 1061 | + $custom_url = uwp_get_register_form_by( $form_id, 'custom_url' ); | |
| 1062 | + } | |
| 1063 | + | |
| 1064 | + if ( ! $redirect_page_id ) { | |
| 1065 | + $redirect_page_id = uwp_get_option( 'register_redirect_to', '' ); | |
| 1066 | + $custom_url = uwp_get_option( 'register_redirect_custom_url' ); | |
| 1067 | + } | |
| 1068 | + | |
| 1069 | + if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) { | |
| 1070 | + $redirect_to = esc_url_raw( $_REQUEST['redirect_to'] ); | |
| 1071 | + } elseif ( isset( $data['redirect_to'] ) && ! empty( $data['redirect_to'] ) ) { | |
| 1072 | + $redirect_to = esc_url_raw( $data['redirect_to'] ); | |
| 1073 | + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) { | |
| 1074 | + if ( uwp_is_wpml() ) { | |
| 1075 | + $wpml_page_id = uwp_wpml_object_id( $redirect_page_id, 'page', true, ICL_LANGUAGE_CODE ); | |
| 1076 | + if ( ! empty( $wpml_page_id ) ) { | |
| 1077 | + $redirect_page_id = $wpml_page_id; | |
| 1078 | + } | |
| 1079 | + } | |
| 1080 | + $redirect_to = get_permalink( $redirect_page_id ); | |
| 1081 | + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 1 && wp_get_referer() ) { | |
| 1082 | + $redirect_to = esc_url( wp_get_referer() ); | |
| 1083 | + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 2 && $custom_url ) { | |
| 1084 | + $redirect_to = $custom_url; | |
| 1085 | + } else { | |
| 1086 | + if ( $user && $user->has_cap( 'manage_options' ) ) { | |
| 1087 | + $redirect_to = admin_url(); | |
| 1088 | + } else { | |
| 1089 | + $redirect_to = home_url( '/' ); | |
| 1090 | + } | |
| 1091 | + | |
| 1092 | + $redirect_to = apply_filters( 'registration_redirect', $redirect_to ); | |
| 1093 | + } | |
| 1094 | + | |
| 1095 | + return apply_filters( 'uwp_register_redirect', $redirect_to, $redirect_page_id, $data ); | |
| 1096 | + } | |
| 1097 | + | |
| 1098 | + /** | |
| 1099 | + * Processes login form submission. | |
| 1100 | + * | |
| 1101 | + * @since 1.0.0 | |
| 1102 | + * @package userswp | |
| 1103 | + * | |
| 1104 | + */ | |
| 1105 | + public function process_login() { | |
| 1106 | + | |
| 1107 | + $data = $_POST; | |
| 1108 | + | |
| 1109 | + if ( ! isset( $data['uwp_login_nonce'] ) ) { | |
| 1110 | + return; | |
| 1111 | + } | |
| 1112 | + | |
| 1113 | + if ( ! isset( $data['uwp_login_nonce'] ) || ! wp_verify_nonce( $data['uwp_login_nonce'], 'uwp-login-nonce' ) ) { | |
| 1114 | + $message = aui()->alert( | |
| 1115 | + array( | |
| 1116 | + 'type' => 'error', | |
| 1117 | + 'content' => __( 'Security verification failed. Try again.', 'userswp' ), | |
| 1118 | + ) | |
| 1119 | + ); | |
| 1120 | + if ( wp_doing_ajax() ) { | |
| 1121 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 1122 | + } else { | |
| 1123 | + return; | |
| 1124 | + } | |
| 1125 | + } | |
| 1126 | + | |
| 1127 | + global $uwp_notices; | |
| 1128 | + | |
| 1129 | + do_action( 'uwp_before_validate', 'login' ); | |
| 1130 | + | |
| 1131 | + $result = uwp_validate_fields( $data, 'login' ); | |
| 1132 | + | |
| 1133 | + $result = apply_filters( 'uwp_validate_result', $result, 'login', $data ); | |
| 1134 | + | |
| 1135 | + if ( is_wp_error( $result ) ) { | |
| 1136 | + $message = aui()->alert( | |
| 1137 | + array( | |
| 1138 | + 'type' => 'error', | |
| 1139 | + 'content' => $result->get_error_message(), | |
| 1140 | + ) | |
| 1141 | + ); | |
| 1142 | + if ( wp_doing_ajax() ) { | |
| 1143 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 1144 | + } else { | |
| 1145 | + $uwp_notices[] = array( 'login' => $message ); | |
| 1146 | + | |
| 1147 | + return; | |
| 1148 | + } | |
| 1149 | + } | |
| 1150 | + | |
| 1151 | + do_action( 'uwp_after_validate', $result, 'login', $data ); | |
| 1152 | + | |
| 1153 | + if ( isset( $data['remember_me'] ) && $data['remember_me'] == 'forever' ) { | |
| 1154 | + $remember_me = true; | |
| 1155 | + } else { | |
| 1156 | + $remember_me = false; | |
| 1157 | + } | |
| 1158 | + | |
| 1159 | + remove_action( 'authenticate', 'gglcptch_login_check', 21 ); | |
| 1160 | + | |
| 1161 | + global $wp2fa; | |
| 1162 | + if ( wp_doing_ajax() && isset( $wp2fa ) && ! empty( $wp2fa ) ) { | |
| 1163 | + remove_action( 'wp_login', array( $wp2fa->login, 'wp_login' ), 20 ); | |
| 1164 | + } | |
| 1165 | + | |
| 1166 | + $user = wp_signon( | |
| 1167 | + array( | |
| 1168 | + 'user_login' => $result['username'], | |
| 1169 | + 'user_password' => $result['password'], | |
| 1170 | + 'remember' => $remember_me, | |
| 1171 | + ) | |
| 1172 | + ); | |
| 1173 | + | |
| 1174 | + add_action( 'authenticate', 'gglcptch_login_check', 21, 1 ); | |
| 1175 | + | |
| 1176 | + if ( wp_doing_ajax() && ! is_wp_error( $user ) && isset( $wp2fa ) && ! empty( $wp2fa ) ) { | |
| 1177 | + | |
| 1178 | + $two_fa = $this->check_2fa( $user ); | |
| 1179 | + if ( isset( $two_fa ) && ! empty( $two_fa ) ) { | |
| 1180 | + if ( is_wp_error( $two_fa ) ) { | |
| 1181 | + $message = aui()->alert( | |
| 1182 | + array( | |
| 1183 | + 'type' => 'error', | |
| 1184 | + 'content' => $two_fa->get_error_message(), | |
| 1185 | + ) | |
| 1186 | + ); | |
| 1187 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 1188 | + } else { | |
| 1189 | + wp_send_json_success( | |
| 1190 | + array( | |
| 1191 | + 'html' => $two_fa, | |
| 1192 | + 'is_2fa' => true, | |
| 1193 | + ) | |
| 1194 | + ); | |
| 1195 | + } | |
| 1196 | + } | |
| 1197 | + } | |
| 1198 | + | |
| 1199 | + if ( is_wp_error( $user ) ) { | |
| 1200 | + $message = aui()->alert( | |
| 1201 | + array( | |
| 1202 | + 'type' => 'error', | |
| 1203 | + 'content' => $user->get_error_message(), | |
| 1204 | + ) | |
| 1205 | + ); | |
| 1206 | + if ( wp_doing_ajax() ) { | |
| 1207 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 1208 | + } else { | |
| 1209 | + $uwp_notices[] = array( 'login' => $message ); | |
| 1210 | + | |
| 1211 | + return; | |
| 1212 | + } | |
| 1213 | + } else { | |
| 1214 | + do_action( 'uwp_after_process_login', $data ); | |
| 1215 | + $message = aui()->alert( | |
| 1216 | + array( | |
| 1217 | + 'type' => 'success', | |
| 1218 | + 'content' => __( 'Login successful. Redirecting...', 'userswp' ), | |
| 1219 | + ) | |
| 1220 | + ); | |
| 1221 | + if ( wp_doing_ajax() ) { | |
| 1222 | + $redirect_to = ''; | |
| 1223 | + if ( 1 == uwp_get_option( 'login_modal_enable_redirect' ) ) { | |
| 1224 | + $redirect_to = $this->get_login_redirect_url( $data, $user ); | |
| 399 | 1225 | } |
| 400 | - $redirect = apply_filters('uwp_register_redirect', $reg_redirect_to); | |
| 401 | - wp_redirect($redirect); | |
| 402 | - exit(); | |
| 403 | - } | |
| 404 | - } else { | |
| 405 | - if ($reg_action == 'require_email_activation') { | |
| 406 | - global $wp; | |
| 407 | - $resend_link = uwp_current_page_url(); | |
| 408 | - $resend_link = add_query_arg( | |
| 1226 | + wp_send_json_success( | |
| 409 | 1227 | array( |
| 410 | - 'user_id' => $user_id, | |
| 411 | - 'action' => 'uwp_resend', | |
| 412 | - '_nonce' => wp_create_nonce('uwp_resend'), | |
| 413 | - ), | |
| 414 | - $resend_link | |
| 1228 | + 'message' => $message, | |
| 1229 | + 'redirect' => $redirect_to, | |
| 1230 | + ) | |
| 415 | 1231 | ); |
| 416 | - return sprintf(__('An email has been sent to your registered email address. Please click the activation link to proceed. <a href="%s">Resend</a>.', 'userswp'), $resend_link); | |
| 417 | - } elseif ($reg_action == 'require_admin_review' && defined('UWP_MOD_VERSION')) { | |
| 418 | - update_user_meta( $user_id, 'uwp_mod', '1' ); | |
| 1232 | + } else { | |
| 1233 | + $redirect_to = $this->get_login_redirect_url( $data, $user ); | |
| 1234 | + wp_safe_redirect( $redirect_to ); | |
| 1235 | + exit(); | |
| 1236 | + } | |
| 1237 | +} | |
| 1238 | + } | |
| 419 | 1239 | |
| 420 | - $email = new UsersWP_Mails(); | |
| 421 | - $send_result = $email->send( 'mod_pending', $user_id ); | |
| 422 | - $user_data = get_user_by('id', $user_id); | |
| 423 | - $send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors); | |
| 424 | - if (is_wp_error($send_result)) { | |
| 425 | - return $send_result; | |
| 426 | - } | |
| 1240 | + public function check_2fa( $user ) { | |
| 1241 | + if ( 1 == uwp_get_option( 'disable_wp_2fa' ) ) { | |
| 1242 | + return; | |
| 1243 | + } | |
| 427 | 1244 | |
| 428 | - $admin_send_result = $email->send_admin_email('mod_admin', $user_id); | |
| 429 | - if (is_wp_error($admin_send_result)) { | |
| 430 | - return $admin_send_result; | |
| 431 | - } | |
| 1245 | + if ( ! $user ) { | |
| 1246 | + $user = wp_get_current_user(); | |
| 1247 | + } | |
| 432 | 1248 | |
| 433 | - return __('Your account is under moderation. We will email you once its approved.', 'userswp'); | |
| 434 | - } else { | |
| 1249 | + global $wp2fa; | |
| 1250 | + $errors = new WP_Error(); | |
| 435 | 1251 | |
| 436 | - $login_page_url = wp_login_url(); | |
| 1252 | + if ( ! \WP2FA\Admin\Helpers\User_Helper::is_user_using_two_factor( $user->ID ) ) { | |
| 1253 | + return; | |
| 1254 | + } | |
| 1255 | + // Invalidate the current login session to prevent from being re-used. | |
| 1256 | + \WP2FA\Authenticator\Login::destroy_current_session_for_user( $user ); | |
| 437 | 1257 | |
| 438 | - if ($generated_password) { | |
| 439 | - return sprintf(__('Account registered successfully. A password has been generated and mailed to your registered Email ID. Please login <a href="%s">here</a>.', 'userswp'), $login_page_url); | |
| 440 | - } else { | |
| 441 | - return sprintf(__('Account registered successfully. Please login <a href="%s">here</a>', 'userswp'), $login_page_url); | |
| 442 | - } | |
| 443 | - } | |
| 444 | - } | |
| 1258 | + // Also clear the cookies which are no longer valid. | |
| 1259 | + wp_clear_auth_cookie(); | |
| 445 | 1260 | |
| 1261 | + $login_nonce = \WP2FA\Authenticator\Login::create_login_nonce( $user->ID ); | |
| 1262 | + if ( ! $login_nonce ) { | |
| 1263 | + $errors->add( 'failed_login_nonce', __( 'Failed to create a login nonce.', 'userswp' ) ); | |
| 446 | 1264 | |
| 447 | - } | |
| 1265 | + return $errors; | |
| 1266 | + } | |
| 448 | 1267 | |
| 449 | - /** | |
| 450 | - * Processes login form submission. | |
| 451 | - * | |
| 452 | - * @since 1.0.0 | |
| 453 | - * @package userswp | |
| 454 | - * | |
| 455 | - * @param array $data Submitted $_POST data | |
| 456 | - * | |
| 457 | - * @return bool|WP_Error|string | |
| 458 | - */ | |
| 459 | - public function process_login($data) { | |
| 1268 | + $provider = \WP2FA\Authenticator\Login::get_available_providers_for_user( $user ); | |
| 460 | 1269 | |
| 461 | - $errors = new WP_Error(); | |
| 1270 | + ob_start(); | |
| 1271 | + ?> | |
| 462 | 1272 | |
| 463 | - if( ! isset( $data['uwp_login_nonce'] ) || ! wp_verify_nonce( $data['uwp_login_nonce'], 'uwp-login-nonce' ) ) { | |
| 464 | - return false; | |
| 465 | - } | |
| 1273 | + <div class="uwp-2fa-methods-wrap"> | |
| 1274 | + <form name="validate_2fa_form" id="validate_2fa_form" class="validate_2fa_form" action="" method="post" | |
| 1275 | + autocomplete="off"> | |
| 1276 | + <input type="hidden" name="provider" id="provider" value="<?php echo esc_attr( $provider ); ?>"/> | |
| 1277 | + <input type="hidden" name="uwp-auth-id" id="uwp-auth-id" value="<?php echo esc_attr( $user->ID ); ?>"/> | |
| 1278 | + <input type="hidden" name="wp-auth-nonce" id="wp-auth-nonce" | |
| 1279 | + value="<?php echo esc_attr( $login_nonce['key'] ); ?>"/> | |
| 1280 | + <?php | |
| 466 | 1281 | |
| 467 | - do_action('uwp_before_validate', 'login'); | |
| 1282 | + // Check to see what provider is set and give the relevant authentication page. | |
| 1283 | + if ( 'totp' === $provider ) { | |
| 1284 | + ?> | |
| 1285 | + <p><?php esc_html_e( 'Please enter the authentication code from your 2FA authentication app below to login:', 'userswp' ); ?></p> | |
| 1286 | + <?php | |
| 468 | 1287 | |
| 469 | - $result = uwp_validate_fields($data, 'login'); | |
| 1288 | + echo aui()->input( | |
| 1289 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1290 | + 'type' => 'tel', | |
| 1291 | + 'id' => 'authcode', | |
| 1292 | + 'name' => 'authcode', | |
| 1293 | + 'placeholder' => esc_attr__( 'Authentication Code', 'userswp' ), | |
| 1294 | + 'value' => '', | |
| 1295 | + 'label' => esc_html__( 'Authentication Code', 'userswp' ), | |
| 1296 | + ) | |
| 1297 | + ); | |
| 470 | 1298 | |
| 471 | - $result = apply_filters('uwp_validate_result', $result, 'login', $data); | |
| 1299 | + echo aui()->button( | |
| 1300 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1301 | + 'type' => 'submit', | |
| 1302 | + 'class' => 'btn btn-primary btn-block text-uppercase uwp-2fa-submit', | |
| 1303 | + 'name' => 'submit', | |
| 1304 | + 'icon' => '', | |
| 1305 | + 'content' => esc_html__( 'Log In', 'userswp' ), | |
| 1306 | + ) | |
| 1307 | + ); | |
| 472 | 1308 | |
| 473 | - if (is_wp_error($result)) { | |
| 474 | - return $result; | |
| 475 | - } | |
| 1309 | + } elseif ( 'email' === $provider ) { | |
| 1310 | + $has_token = \WP2FA\Authenticator\Authentication::user_has_token( $user->ID ); | |
| 1311 | + if ( empty( $has_token ) || ! $has_token ) { | |
| 1312 | + \WP2FA\Admin\Setup_Wizard::send_authentication_setup_email( $user->ID ); | |
| 1313 | + } | |
| 1314 | + ?> | |
| 1315 | + <p><?php esc_html_e( 'Please enter the 2FA verification code sent to your email address to login:', 'userswp' ); ?></p> | |
| 1316 | + <?php | |
| 1317 | + echo aui()->input( | |
| 1318 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1319 | + 'type' => 'tel', | |
| 1320 | + 'id' => 'authcode', | |
| 1321 | + 'name' => 'wp-2fa-email-code', | |
| 1322 | + 'placeholder' => esc_attr__( 'Verification Code', 'userswp' ), | |
| 1323 | + 'value' => '', | |
| 1324 | + 'label' => esc_html__( 'Verification Code', 'userswp' ), | |
| 1325 | + 'extra_attributes' => array( | |
| 1326 | + 'size' => 20, | |
| 1327 | + 'pattern' => '[0-9]*', | |
| 1328 | + ), | |
| 1329 | + ) | |
| 1330 | + ); | |
| 476 | 1331 | |
| 477 | - do_action('uwp_after_validate', 'login'); | |
| 1332 | + echo aui()->button( | |
| 1333 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1334 | + 'type' => 'submit', | |
| 1335 | + 'class' => 'btn btn-primary text-uppercase uwp-2fa-submit', | |
| 1336 | + 'name' => 'submit', | |
| 1337 | + 'icon' => '', | |
| 1338 | + 'content' => esc_html__( 'Log In', 'userswp' ), | |
| 1339 | + ) | |
| 1340 | + ); | |
| 478 | 1341 | |
| 479 | - if (isset($data['remember_me']) && $data['remember_me'] == 'forever') { | |
| 480 | - $remember_me = true; | |
| 481 | - } else { | |
| 482 | - $remember_me = false; | |
| 483 | - } | |
| 1342 | + echo aui()->button( | |
| 1343 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1344 | + 'type' => 'button', | |
| 1345 | + 'class' => 'btn btn-secondary text-uppercase uwp-2fa-email-resend', | |
| 1346 | + 'name' => 'wp-2fa-email-code-resend', | |
| 1347 | + 'icon' => '', | |
| 1348 | + 'content' => esc_html__( 'Resend Code', 'userswp' ), | |
| 1349 | + ) | |
| 1350 | + ); | |
| 484 | 1351 | |
| 485 | - remove_action( 'authenticate', 'gglcptch_login_check', 21, 1 ); | |
| 1352 | + } | |
| 1353 | + ?> | |
| 1354 | + </form> | |
| 1355 | + </div> | |
| 486 | 1356 | |
| 487 | - $res = wp_signon( | |
| 1357 | + <?php | |
| 1358 | + $codes_remaining = \WP2FA\Authenticator\Backup_Codes::codes_remaining_for_user( $user ); | |
| 1359 | + if ( isset( $codes_remaining ) && $codes_remaining > 0 ) { | |
| 1360 | + ?> | |
| 1361 | + <div class="uwp-2fa-methods-wrap" style="display:none;"> | |
| 1362 | + <form name="validate_2fa_backup_codes_form" id="validate_2fa_backup_codes_form" | |
| 1363 | + class="validate_2fa_backup_codes_form" action="" method="post" autocomplete="off"> | |
| 1364 | + <input type="hidden" name="provider" id="provider" value="backup_codes"/> | |
| 1365 | + <input type="hidden" name="uwp-auth-id" id="uwp-auth-id" | |
| 1366 | + value="<?php echo esc_attr( $user->ID ); ?>"/> | |
| 1367 | + <input type="hidden" name="wp-auth-nonce" id="wp-auth-nonce" | |
| 1368 | + value="<?php echo esc_attr( $login_nonce['key'] ); ?>"/> | |
| 1369 | + <div class="uwp-backup-fields"> | |
| 1370 | + <?php | |
| 1371 | + echo aui()->input( | |
| 1372 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1373 | + 'type' => 'tel', | |
| 1374 | + 'id' => 'authcode', | |
| 1375 | + 'name' => 'wp-2fa-backup-code', | |
| 1376 | + 'placeholder' => esc_attr__( 'Enter backup code', 'userswp' ), | |
| 1377 | + 'value' => '', | |
| 1378 | + 'label' => esc_html__( 'Backup Code', 'userswp' ), | |
| 1379 | + 'extra_attributes' => array( | |
| 1380 | + 'size' => 20, | |
| 1381 | + 'pattern' => '[0-9]*', | |
| 1382 | + ), | |
| 1383 | + ) | |
| 1384 | + ); | |
| 1385 | + | |
| 1386 | + echo aui()->button( | |
| 1387 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1388 | + 'type' => 'submit', | |
| 1389 | + 'class' => 'btn btn-primary btn-block text-uppercase uwp-2fa-submit', | |
| 1390 | + 'name' => 'submit', | |
| 1391 | + 'icon' => '', | |
| 1392 | + 'content' => esc_html__( 'Log In', 'userswp' ), | |
| 1393 | + ) | |
| 1394 | + ); | |
| 1395 | + ?> | |
| 1396 | + </div> | |
| 1397 | + </form> | |
| 1398 | + </div> | |
| 1399 | + <a href="#" class="uwp-switch-2fa-methods text-center d-block"><?php esc_html_e( 'Or, use a backup code.', 'userswp' ); ?></a> | |
| 1400 | + <script type="text/javascript"> | |
| 1401 | + jQuery('.uwp-switch-2fa-methods').on('click', | |
| 1402 | + function (e) { | |
| 1403 | + e.preventDefault(); | |
| 1404 | + jQuery('.uwp-auth-modal .modal-content .modal-error').html(''); | |
| 1405 | + jQuery('.uwp-2fa-methods-wrap').toggle(); | |
| 1406 | + return false; | |
| 1407 | + } | |
| 1408 | + ); | |
| 1409 | + </script> | |
| 1410 | + <?php | |
| 1411 | + } | |
| 1412 | + | |
| 1413 | + return ob_get_clean(); | |
| 1414 | + } | |
| 1415 | + | |
| 1416 | + public function process_login_2fa() { | |
| 1417 | + if ( ! isset( $_POST['uwp-auth-id'], $_POST['wp-auth-nonce'] ) ) { | |
| 1418 | + return; | |
| 1419 | + } | |
| 1420 | + | |
| 1421 | + $auth_id = (int) $_POST['uwp-auth-id']; | |
| 1422 | + $user = get_userdata( $auth_id ); | |
| 1423 | + if ( ! $user ) { | |
| 1424 | + $message = aui()->alert( | |
| 1425 | + array( | |
| 1426 | + 'type' => 'error', | |
| 1427 | + 'content' => __( 'Invalid user data. Please try again.', 'userswp' ), | |
| 1428 | + ) | |
| 1429 | + ); | |
| 1430 | + | |
| 1431 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 1432 | + } | |
| 1433 | + | |
| 1434 | + global $wp2fa; | |
| 1435 | + | |
| 1436 | + $nonce = ( isset( $_POST['wp-auth-nonce'] ) ) ? sanitize_textarea_field( wp_unslash( $_POST['wp-auth-nonce'] ) ) : ''; | |
| 1437 | + if ( true !== \WP2FA\Authenticator\Login::verify_login_nonce( $user->ID, $nonce ) ) { | |
| 1438 | + | |
| 1439 | + $message = aui()->alert( | |
| 1440 | + array( | |
| 1441 | + 'type' => 'error', | |
| 1442 | + 'content' => __( 'Invalid request! Please try again.', 'userswp' ), | |
| 1443 | + ) | |
| 1444 | + ); | |
| 1445 | + | |
| 1446 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 1447 | + } | |
| 1448 | + | |
| 1449 | + if ( isset( $_POST['provider'] ) ) { | |
| 1450 | + $provider = sanitize_textarea_field( wp_unslash( $_POST['provider'] ) ); | |
| 1451 | + $providers = \WP2FA\Authenticator\Login::get_available_providers_for_user( $user ); | |
| 1452 | + if ( isset( $providers[ $provider ] ) ) { | |
| 1453 | + $provider = $providers[ $provider ]; | |
| 1454 | + } elseif ( isset( $provider ) ) { | |
| 1455 | + $provider = $provider; | |
| 1456 | + } else { | |
| 1457 | + $provider = $provider; | |
| 1458 | + } | |
| 1459 | + } | |
| 1460 | + | |
| 1461 | + // If this is an email login, or if the user failed validation previously, lets send the code to the user. | |
| 1462 | + if ( 'email' === $provider && true !== \WP2FA\Authenticator\Login::pre_process_email_authentication( $user ) ) { | |
| 1463 | + | |
| 1464 | + } | |
| 1465 | + | |
| 1466 | + // Validate TOTP. | |
| 1467 | + if ( 'totp' === $provider && true !== \WP2FA\Authenticator\Login::validate_totp_authentication( $user ) ) { | |
| 1468 | + | |
| 1469 | + do_action( 'wp_login_failed', $user->user_login ); | |
| 1470 | + | |
| 1471 | + $message = aui()->alert( | |
| 1472 | + array( | |
| 1473 | + 'type' => 'error', | |
| 1474 | + 'content' => __( 'Invalid verification code.', 'userswp' ), | |
| 1475 | + ) | |
| 1476 | + ); | |
| 1477 | + | |
| 1478 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 1479 | + } | |
| 1480 | + | |
| 1481 | + // Validate Email. | |
| 1482 | + if ( 'email' === $provider && true !== \WP2FA\Authenticator\Login::validate_email_authentication( $user ) ) { | |
| 1483 | + | |
| 1484 | + do_action( 'wp_login_failed', $user->user_login ); | |
| 1485 | + | |
| 1486 | + if ( isset( $_REQUEST['wp-2fa-email-code-resend'] ) && 1 == $_REQUEST['wp-2fa-email-code-resend'] ) { | |
| 1487 | + $message = aui()->alert( | |
| 1488 | + array( | |
| 1489 | + 'type' => 'info', | |
| 1490 | + 'content' => __( 'A new code has been sent.', 'userswp' ), | |
| 1491 | + ) | |
| 1492 | + ); | |
| 1493 | + | |
| 1494 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 1495 | + } else { | |
| 1496 | + $message = aui()->alert( | |
| 1497 | + array( | |
| 1498 | + 'type' => 'error', | |
| 1499 | + 'content' => __( 'Invalid verification code.', 'userswp' ), | |
| 1500 | + ) | |
| 1501 | + ); | |
| 1502 | + | |
| 1503 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 1504 | + } | |
| 1505 | + } | |
| 1506 | + | |
| 1507 | + // Backup Codes. | |
| 1508 | + if ( 'backup_codes' === $provider && true !== \WP2FA\Authenticator\Login::validate_backup_codes( $user ) ) { | |
| 1509 | + | |
| 1510 | + do_action( 'wp_login_failed', $user->user_login ); | |
| 1511 | + | |
| 1512 | + $message = aui()->alert( | |
| 1513 | + array( | |
| 1514 | + 'type' => 'error', | |
| 1515 | + 'content' => __( 'Invalid backup code.', 'userswp' ), | |
| 1516 | + ) | |
| 1517 | + ); | |
| 1518 | + | |
| 1519 | + wp_send_json_error( array( 'message' => $message ) ); | |
| 1520 | + } | |
| 1521 | + | |
| 1522 | + \WP2FA\Authenticator\Login::delete_login_nonce( $user->ID ); | |
| 1523 | + | |
| 1524 | + $rememberme = false; | |
| 1525 | + $remember = ( isset( $_REQUEST['rememberme'] ) ) ? filter_var( $_REQUEST['rememberme'], FILTER_VALIDATE_BOOLEAN ) : ''; | |
| 1526 | + if ( ! empty( $remember ) ) { | |
| 1527 | + $rememberme = true; | |
| 1528 | + } | |
| 1529 | + | |
| 1530 | + wp_set_auth_cookie( $user->ID, $rememberme ); | |
| 1531 | + | |
| 1532 | + do_action( 'two_factor_user_authenticated', $user ); | |
| 1533 | + | |
| 1534 | + $message = aui()->alert( | |
| 488 | 1535 | array( |
| 489 | - 'user_login' => $result['uwp_login_username'], | |
| 490 | - 'user_password' => $result['password'], | |
| 491 | - 'remember' => $remember_me | |
| 1536 | + 'type' => 'success', | |
| 1537 | + 'content' => __( 'Validation successful. Redirecting...', 'userswp' ), | |
| 492 | 1538 | ) |
| 493 | - ); | |
| 1539 | + ); | |
| 494 | 1540 | |
| 495 | - add_action( 'authenticate', 'gglcptch_login_check', 21, 1 ); | |
| 1541 | + wp_send_json_success( array( 'message' => $message ) ); | |
| 1542 | + } | |
| 496 | 1543 | |
| 497 | - if (is_wp_error($res)) { | |
| 498 | - $errors->add('invalid_userorpass', __('<strong>Error</strong>: Invalid username or Password.', 'userswp')); | |
| 499 | - return $errors; | |
| 500 | - } else { | |
| 501 | - $redirect_page_id = uwp_get_option('login_redirect_to', -1); | |
| 502 | - if (isset($_REQUEST['redirect_to']) && !empty($_REQUEST['redirect_to'])) { | |
| 503 | - $redirect_to = esc_url($_REQUEST['redirect_to']); | |
| 504 | - } elseif (isset($data['redirect_to']) && !empty($data['redirect_to'])) { | |
| 505 | - $redirect_to = esc_url($data['redirect_to']); | |
| 506 | - } elseif (isset($redirect_page_id) && (int)$redirect_page_id > 0) { | |
| 507 | - $redirect_to = get_permalink($redirect_page_id); | |
| 508 | - } else { | |
| 509 | - if ( current_user_can('manage_options') ) { | |
| 510 | - $redirect_to = admin_url(); | |
| 511 | - } else { | |
| 512 | - $redirect_to = home_url('/'); | |
| 513 | - } | |
| 514 | - } | |
| 1544 | + public function get_login_redirect_url( $data, $user ) { | |
| 1545 | + if ( is_int( $user ) ) { | |
| 1546 | + $user = get_userdata( $user ); | |
| 1547 | + } | |
| 515 | 1548 | |
| 516 | - $redirect_to = apply_filters('uwp_login_redirect', $redirect_to); | |
| 517 | - wp_redirect($redirect_to); | |
| 518 | - exit(); | |
| 519 | - } | |
| 520 | - } | |
| 1549 | + $redirect_page_id = uwp_get_option( 'login_redirect_to', - 1 ); | |
| 1550 | + $custom_url = uwp_get_option( 'login_redirect_custom_url' ); | |
| 521 | 1551 | |
| 522 | - /** | |
| 523 | - * Processes forgot password form submission. | |
| 524 | - * | |
| 525 | - * @since 1.0.0 | |
| 526 | - * @package userswp | |
| 527 | - * | |
| 528 | - * @param array $data Submitted $_POST data | |
| 529 | - * | |
| 530 | - * @return bool|WP_Error|string | |
| 531 | - */ | |
| 532 | - public function process_forgot($data) { | |
| 1552 | + if ( $user && isset( $user->roles[0] ) ) { | |
| 1553 | + $user_role = $user->roles[0]; | |
| 1554 | + $redirect_page_id = uwp_get_option( 'login_redirect_to_' . $user_role, $redirect_page_id ); | |
| 1555 | + $custom_url = uwp_get_option( 'login_redirect_custom_url_' . $user_role ); | |
| 1556 | + } | |
| 533 | 1557 | |
| 534 | - $errors = new WP_Error(); | |
| 1558 | + if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) { | |
| 1559 | + $redirect_to = esc_url_raw( $_REQUEST['redirect_to'] ); | |
| 1560 | + } elseif ( isset( $data['redirect_to'] ) && ! empty( $data['redirect_to'] ) ) { | |
| 1561 | + $redirect_to = esc_url_raw( $data['redirect_to'] ); | |
| 1562 | + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) { | |
| 1563 | + if ( uwp_is_wpml() ) { | |
| 1564 | + $wpml_page_id = uwp_wpml_object_id( $redirect_page_id, 'page', true, ICL_LANGUAGE_CODE ); | |
| 1565 | + if ( ! empty( $wpml_page_id ) ) { | |
| 1566 | + $redirect_page_id = $wpml_page_id; | |
| 1567 | + } | |
| 1568 | + } | |
| 1569 | + $redirect_to = get_permalink( $redirect_page_id ); | |
| 1570 | + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 1 && wp_get_referer() ) { | |
| 1571 | + $redirect_to = esc_url( wp_get_referer() ); | |
| 1572 | + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 2 && ! empty( $custom_url ) ) { | |
| 1573 | + $redirect_to = $custom_url; | |
| 1574 | + } else { | |
| 1575 | + $redirect_to = home_url( '/' ); | |
| 1576 | + $redirect_to = apply_filters( 'login_redirect', $redirect_to, '', $user ); | |
| 1577 | + } | |
| 535 | 1578 | |
| 536 | - if( ! isset( $data['uwp_forgot_nonce'] ) || ! wp_verify_nonce( $data['uwp_forgot_nonce'], 'uwp-forgot-nonce' ) ) { | |
| 537 | - return false; | |
| 538 | - } | |
| 1579 | + return apply_filters( 'uwp_login_redirect', $redirect_to, $redirect_page_id, $data, $user ); | |
| 1580 | + } | |
| 539 | 1581 | |
| 540 | - do_action('uwp_before_validate', 'forgot'); | |
| 1582 | + /** | |
| 1583 | + * Processes forgot password form submission. | |
| 1584 | + * | |
| 1585 | + * @since 1.0.0 | |
| 1586 | + * @package userswp | |
| 1587 | + * | |
| 1588 | + */ | |
| 1589 | + public function process_forgot() { | |
| 541 | 1590 | |
| 542 | - $result = uwp_validate_fields($data, 'forgot'); | |
| 1591 | + $data = $_POST; | |
| 543 | 1592 | |
| 544 | - $result = apply_filters('uwp_validate_result', $result, 'forgot', $data); | |
| 1593 | + if ( ! isset( $data['uwp_forgot_nonce'] ) ) { | |
| 1594 | + return; | |
| 1595 | + } | |
| 545 | 1596 | |
| 546 | - if (is_wp_error($result)) { | |
| 547 | - return $result; | |
| 548 | - } | |
| 1597 | + if ( ! isset( $data['uwp_forgot_nonce'] ) || ! wp_verify_nonce( $data['uwp_forgot_nonce'], 'uwp-forgot-nonce' ) ) { | |
| 1598 | + $message = aui()->alert( | |
| 1599 | + array( | |
| 1600 | + 'type' => 'error', | |
| 1601 | + 'content' => __( 'Security verification failed. Try again.', 'userswp' ), | |
| 1602 | + ) | |
| 1603 | + ); | |
| 1604 | + if ( wp_doing_ajax() ) { | |
| 1605 | + wp_send_json_error( $message ); | |
| 1606 | + } else { | |
| 1607 | + return; | |
| 1608 | + } | |
| 1609 | + } | |
| 549 | 1610 | |
| 550 | - do_action('uwp_after_validate', 'forgot'); | |
| 1611 | + global $uwp_notices; | |
| 551 | 1612 | |
| 1613 | + do_action( 'uwp_before_validate', 'forgot' ); | |
| 552 | 1614 | |
| 553 | - $user_data = get_user_by('email', $data['uwp_forgot_email']); | |
| 1615 | + $result = uwp_validate_fields( $data, 'forgot' ); | |
| 554 | 1616 | |
| 555 | - // make sure user account is active before account reset | |
| 556 | - $mod_value = get_user_meta( $user_data->ID, 'uwp_mod', true ); | |
| 557 | - if ($mod_value == 'email_unconfirmed') { | |
| 558 | - $errors->add('activate_account', __('<strong>Error</strong>: Your account is not activated yet. Please activate your account first.', 'userswp')); | |
| 559 | - } | |
| 1617 | + $result = apply_filters( 'uwp_validate_result', $result, 'forgot', $data ); | |
| 560 | 1618 | |
| 561 | - $error_code = $errors->get_error_code(); | |
| 562 | - if (!empty($error_code)) { | |
| 563 | - return $errors; | |
| 564 | - } | |
| 565 | - | |
| 566 | - $email = new UsersWP_Mails(); | |
| 567 | - $send_result = $email->send( 'forgot', $user_data->ID ); | |
| 568 | - | |
| 569 | - $send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors); | |
| 570 | - if (is_wp_error($send_result)) { | |
| 571 | - return $send_result; | |
| 572 | - } | |
| 1619 | + if ( is_wp_error( $result ) ) { | |
| 1620 | + $message = aui()->alert( | |
| 1621 | + array( | |
| 1622 | + 'type' => 'error', | |
| 1623 | + 'content' => $result->get_error_message(), | |
| 1624 | + ) | |
| 1625 | + ); | |
| 1626 | + if ( wp_doing_ajax() ) { | |
| 1627 | + wp_send_json_error( $message ); | |
| 1628 | + } else { | |
| 1629 | + $uwp_notices[] = array( 'forgot' => $message ); | |
| 573 | 1630 | |
| 574 | - return true; | |
| 575 | - } | |
| 1631 | + return; | |
| 1632 | + } | |
| 1633 | + } | |
| 576 | 1634 | |
| 577 | - /** | |
| 578 | - * Processes change password form submission. | |
| 579 | - * | |
| 580 | - * @since 1.0.0 | |
| 581 | - * @package userswp | |
| 582 | - * | |
| 583 | - * @param array $data Submitted $_POST data | |
| 584 | - * | |
| 585 | - * @return bool|WP_Error|string | |
| 586 | - */ | |
| 587 | - public function process_change($data) { | |
| 1635 | + do_action( 'uwp_after_validate', $result, 'forgot', $data ); | |
| 588 | 1636 | |
| 589 | - $errors = new WP_Error(); | |
| 1637 | + $user_data = get_user_by( 'email', $data['email'] ); | |
| 590 | 1638 | |
| 591 | - if( ! isset( $data['uwp_change_nonce'] ) || ! wp_verify_nonce( $data['uwp_change_nonce'], 'uwp-change-nonce' ) ) { | |
| 592 | - return false; | |
| 593 | - } | |
| 1639 | + // if no user we fake it and bail | |
| 1640 | + if ( ! $user_data ) { | |
| 1641 | + $args = apply_filters( | |
| 1642 | + 'uwp_forgot_error_message', | |
| 1643 | + array( | |
| 1644 | + 'type' => 'error', | |
| 1645 | + 'content' => __( 'Invalid email or user doesn\'t exists.', 'userswp' ), | |
| 1646 | + ) | |
| 1647 | + ); | |
| 594 | 1648 | |
| 595 | - do_action('uwp_before_validate', 'change'); | |
| 1649 | + $message = aui()->alert( $args ); | |
| 1650 | + if ( wp_doing_ajax() ) { | |
| 1651 | + wp_send_json_success( $message ); | |
| 1652 | + } else { | |
| 1653 | + $uwp_notices[] = array( 'forgot' => $message ); | |
| 596 | 1654 | |
| 597 | - $result = uwp_validate_fields($data, 'change'); | |
| 1655 | + return; | |
| 1656 | + } | |
| 1657 | + } | |
| 598 | 1658 | |
| 599 | - $result = apply_filters('uwp_validate_result', $result, 'change', $data); | |
| 1659 | + // make sure user account is active before account reset | |
| 1660 | + $mod_value = get_user_meta( $user_data->ID, 'uwp_mod', true ); | |
| 1661 | + if ( $mod_value == 'email_unconfirmed' ) { | |
| 1662 | + $message = aui()->alert( | |
| 1663 | + array( | |
| 1664 | + 'type' => 'error', | |
| 1665 | + 'content' => __( 'Your account is not activated yet. Please activate your account first.', 'userswp' ), | |
| 1666 | + ) | |
| 1667 | + ); | |
| 1668 | + if ( wp_doing_ajax() ) { | |
| 1669 | + wp_send_json_error( $message ); | |
| 1670 | + } else { | |
| 1671 | + $uwp_notices[] = array( 'forgot' => $message ); | |
| 600 | 1672 | |
| 601 | - if (is_wp_error($result)) { | |
| 602 | - return $result; | |
| 603 | - } | |
| 1673 | + return; | |
| 1674 | + } | |
| 1675 | + } | |
| 604 | 1676 | |
| 605 | - do_action('uwp_after_validate', 'change'); | |
| 1677 | + $user_data = get_userdata( $user_data->ID ); | |
| 606 | 1678 | |
| 607 | - $user_data = get_user_by('id', get_current_user_id()); | |
| 1679 | + $allow = apply_filters( 'allow_password_reset', true, $user_data->ID ); | |
| 608 | 1680 | |
| 609 | - if (is_wp_error($user_data)) { | |
| 610 | - return $user_data; | |
| 611 | - } | |
| 1681 | + if ( ! $allow ) { | |
| 1682 | + return false; | |
| 1683 | + } elseif ( is_wp_error( $allow ) ) { | |
| 1684 | + return false; | |
| 1685 | + } | |
| 612 | 1686 | |
| 613 | - $email = new UsersWP_Mails(); | |
| 614 | - $send_result = $email->send( 'change', $user_data->ID ); | |
| 1687 | + $as_password = apply_filters( 'uwp_forgot_message_as_password', false ); | |
| 615 | 1688 | |
| 616 | - $send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors); | |
| 617 | - if (is_wp_error($send_result)) { | |
| 618 | - return $send_result; | |
| 619 | - } | |
| 1689 | + global $wpdb, $wp_hasher; | |
| 1690 | + $reset_link = ''; | |
| 620 | 1691 | |
| 621 | - wp_set_password( $data['uwp_change_password'], $user_data->ID ); | |
| 622 | - wp_set_auth_cookie( $user_data->ID, false); | |
| 1692 | + if ( $as_password ) { | |
| 1693 | + $new_pass = wp_generate_password( 12, false ); | |
| 1694 | + wp_set_password( $new_pass, $user_data->ID ); | |
| 1695 | + if ( ! uwp_get_option( 'change_disable_password_nag' ) ) { | |
| 1696 | + update_user_meta( $user_data->ID, 'default_password_nag', true ); //Set up the Password change nag. | |
| 1697 | + } | |
| 1698 | + $message = '<p><b>' . __( 'Your login Information :', 'userswp' ) . '</b></p>'; | |
| 1699 | + $message .= '<p>' . sprintf( __( 'Username: %s', 'userswp' ), $user_data->user_login ) . '</p>'; | |
| 1700 | + $message .= '<p>' . sprintf( __( 'Password: %s', 'userswp' ), $new_pass ) . '</p>'; | |
| 623 | 1701 | |
| 624 | - return true; | |
| 625 | - } | |
| 1702 | + } else { | |
| 1703 | + $key = wp_generate_password( 20, false ); | |
| 1704 | + do_action( 'retrieve_password_key', $user_data->user_login, $key ); | |
| 626 | 1705 | |
| 627 | - /** | |
| 628 | - * Processes reset password form submission. | |
| 629 | - * | |
| 630 | - * @since 1.0.0 | |
| 631 | - * @package userswp | |
| 632 | - * | |
| 633 | - * @param array $data Submitted $_POST data | |
| 634 | - * | |
| 635 | - * @return bool|WP_Error|string | |
| 636 | - */ | |
| 637 | - public function process_reset($data) { | |
| 1706 | + if ( empty( $wp_hasher ) ) { | |
| 1707 | + require_once ABSPATH . 'wp-includes/class-phpass.php'; | |
| 1708 | + $wp_hasher = new PasswordHash( 8, true ); | |
| 1709 | + } | |
| 1710 | + $hashed = $wp_hasher->HashPassword( $key ); | |
| 1711 | + $wpdb->update( $wpdb->users, array( 'user_activation_key' => time() . ':' . $hashed ), array( 'user_login' => $user_data->user_login ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 1712 | + $message = '<p>' . __( 'You have requested to reset your password for the following account:', 'userswp' ) . '</p>'; | |
| 1713 | + $message .= home_url( '/' ) . '</p>'; | |
| 1714 | + $message .= '<p>' . sprintf( __( 'Username: %s', 'userswp' ), $user_data->user_login ) . '</p>'; | |
| 1715 | + $message .= '<p>' . __( 'If this was by mistake, just ignore this email and nothing will happen.', 'userswp' ) . '</p>'; | |
| 1716 | + $message .= '<p>' . __( 'To reset your password, click the following link and follow the instructions.', 'userswp' ) . '</p>'; | |
| 1717 | + $reset_page = uwp_get_page_id( 'reset_page', false ); | |
| 1718 | + if ( $reset_page ) { | |
| 1719 | + $reset_link = add_query_arg( | |
| 1720 | + array( | |
| 1721 | + 'key' => $key, | |
| 1722 | + 'login' => rawurlencode( $user_data->user_login ), | |
| 1723 | + ), | |
| 1724 | + get_permalink( $reset_page ) | |
| 1725 | + ); | |
| 1726 | + $message .= "<a href='" . $reset_link . "' target='_blank'>" . $reset_link . '</a>' . "\r\n"; | |
| 1727 | + } else { | |
| 1728 | + $reset_link = home_url( "reset?key=$key&login=" . rawurlencode( $user_data->user_login ), 'login' ); | |
| 1729 | + $message .= "<a href='" . $reset_link . "' target='_blank'>" . $reset_link . '</a>' . "\r\n"; | |
| 1730 | + } | |
| 1731 | + $message = apply_filters( 'uwp_forgot_password_message', $message, $user_data, $reset_link ); | |
| 1732 | + } | |
| 638 | 1733 | |
| 639 | - $errors = new WP_Error(); | |
| 1734 | + $message = apply_filters( 'uwp_forgot_mail_message', $message, $user_data->ID ); | |
| 640 | 1735 | |
| 641 | - if( ! isset( $data['uwp_reset_nonce'] ) || ! wp_verify_nonce( $data['uwp_reset_nonce'], 'uwp-reset-nonce' ) ) { | |
| 642 | - return false; | |
| 643 | - } | |
| 1736 | + $email_vars = array( | |
| 1737 | + 'user_id' => $user_data->ID, | |
| 1738 | + 'login_details' => $message, | |
| 1739 | + 'reset_link' => $reset_link, | |
| 1740 | + ); | |
| 644 | 1741 | |
| 645 | - do_action('uwp_before_validate', 'reset'); | |
| 1742 | + UsersWP_Mails::send( $user_data->user_email, 'forgot_password', $email_vars ); | |
| 646 | 1743 | |
| 647 | - $result = uwp_validate_fields($data, 'reset'); | |
| 1744 | + do_action( 'uwp_after_process_forgot', $data ); | |
| 648 | 1745 | |
| 649 | - $result = apply_filters('uwp_validate_result', $result, 'reset', $data); | |
| 1746 | + $message = aui()->alert( | |
| 1747 | + array( | |
| 1748 | + 'type' => 'success', | |
| 1749 | + 'content' => apply_filters( 'uwp_change_password_success_message', __( 'Please check your email.', 'userswp' ), $data ), | |
| 1750 | + ) | |
| 1751 | + ); | |
| 1752 | + if ( wp_doing_ajax() ) { | |
| 1753 | + wp_send_json_success( $message ); | |
| 1754 | + } else { | |
| 1755 | + $uwp_notices[] = array( 'forgot' => $message ); | |
| 1756 | + } | |
| 1757 | + } | |
| 650 | 1758 | |
| 651 | - if (is_wp_error($result)) { | |
| 652 | - return $result; | |
| 653 | - } | |
| 1759 | + /** | |
| 1760 | + * Processes change password form submission. | |
| 1761 | + * | |
| 1762 | + * @since 1.0.0 | |
| 1763 | + * @package userswp | |
| 1764 | + * | |
| 1765 | + */ | |
| 1766 | + public function process_change() { | |
| 654 | 1767 | |
| 655 | - do_action('uwp_after_validate', 'reset'); | |
| 1768 | + $data = $_POST; | |
| 656 | 1769 | |
| 657 | - $login = $data['uwp_reset_username']; | |
| 658 | - $key = $data['uwp_reset_key']; | |
| 659 | - $user_data = check_password_reset_key( $key, $login ); | |
| 1770 | + if ( ! isset( $data['uwp_change_nonce'] ) || ! wp_verify_nonce( $data['uwp_change_nonce'], 'uwp-change-nonce' ) ) { | |
| 1771 | + return; | |
| 1772 | + } | |
| 660 | 1773 | |
| 661 | - if (is_wp_error($user_data)) { | |
| 662 | - return $user_data; | |
| 663 | - } | |
| 1774 | + global $uwp_notices; | |
| 664 | 1775 | |
| 665 | - $email = new UsersWP_Mails(); | |
| 666 | - $send_result = $email->send( 'reset', $user_data->ID ); | |
| 1776 | + if ( is_uwp_account_page() ) { | |
| 1777 | + $notice_type = 'account'; | |
| 1778 | + } else { | |
| 1779 | + $notice_type = 'change'; | |
| 1780 | + } | |
| 667 | 1781 | |
| 668 | - $send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors); | |
| 669 | - if (is_wp_error($send_result)) { | |
| 670 | - return $send_result; | |
| 671 | - } | |
| 1782 | + do_action( 'uwp_before_validate', 'change' ); | |
| 672 | 1783 | |
| 673 | - wp_set_password( $data['uwp_reset_password'], $user_data->ID ); | |
| 1784 | + $result = uwp_validate_fields( $data, 'change' ); | |
| 674 | 1785 | |
| 675 | - return true; | |
| 676 | - } | |
| 1786 | + $result = apply_filters( 'uwp_validate_result', $result, 'change', $data ); | |
| 677 | 1787 | |
| 678 | - | |
| 679 | - /** | |
| 680 | - * Modifies the mail subject based on the admin notification type. | |
| 681 | - * | |
| 682 | - * @since 1.0.0 | |
| 683 | - * @package userswp | |
| 684 | - * @subpackage userswp/includes | |
| 685 | - * @param string $subject Unmodified mail subject. | |
| 686 | - * @param string $type Notification type. | |
| 687 | - * @return string Modified mail subject. | |
| 688 | - */ | |
| 689 | - public function init_mail_subject($subject, $type) { | |
| 690 | - switch ($type) { | |
| 691 | - case "register": | |
| 692 | - $subject = uwp_get_option('registration_success_email_subject', ''); | |
| 693 | - break; | |
| 694 | - case "activate": | |
| 695 | - $subject = uwp_get_option('registration_activate_email_subject', ''); | |
| 696 | - break; | |
| 697 | - case "forgot": | |
| 698 | - $subject = uwp_get_option('forgot_password_email_subject', ''); | |
| 699 | - break; | |
| 700 | - case "reset": | |
| 701 | - $subject = uwp_get_option('reset_password_email_subject', ''); | |
| 702 | - break; | |
| 703 | - case "change": | |
| 704 | - $subject = uwp_get_option('change_password_email_subject', ''); | |
| 705 | - break; | |
| 706 | - case "account": | |
| 707 | - $subject = uwp_get_option('account_update_email_subject', ''); | |
| 708 | - break; | |
| 709 | - } | |
| 710 | - return $subject; | |
| 711 | - } | |
| 1788 | + if ( is_wp_error( $result ) ) { | |
| 1789 | + $message = aui()->alert( | |
| 1790 | + array( | |
| 1791 | + 'type' => 'error', | |
| 1792 | + 'content' => $result->get_error_message(), | |
| 1793 | + ) | |
| 1794 | + ); | |
| 1795 | + $uwp_notices[] = array( $notice_type => $message ); | |
| 712 | 1796 | |
| 713 | - /** | |
| 714 | - * Modifies the mail content based on the admin notification type. | |
| 715 | - * | |
| 716 | - * @since 1.0.0 | |
| 717 | - * @package userswp | |
| 718 | - * @subpackage userswp/includes | |
| 719 | - * @param string $content Unmodified mail content. | |
| 720 | - * @param string $type Notification type. | |
| 721 | - * @return string Modified mail content. | |
| 722 | - */ | |
| 723 | - public function init_mail_content($content, $type) { | |
| 724 | - switch ($type) { | |
| 725 | - case "register": | |
| 726 | - $content = uwp_get_option('registration_success_email_content', ''); | |
| 727 | - break; | |
| 728 | - case "activate": | |
| 729 | - $content = uwp_get_option('registration_activate_email_content', ''); | |
| 730 | - break; | |
| 731 | - case "forgot": | |
| 732 | - $content = uwp_get_option('forgot_password_email_content', ''); | |
| 733 | - break; | |
| 734 | - case "reset": | |
| 735 | - $content = uwp_get_option('reset_password_email_content', ''); | |
| 736 | - break; | |
| 737 | - case "change": | |
| 738 | - $content = uwp_get_option('change_password_email_content', ''); | |
| 739 | - break; | |
| 740 | - case "account": | |
| 741 | - $content = uwp_get_option('account_update_email_content', ''); | |
| 742 | - break; | |
| 743 | - } | |
| 744 | - return $content; | |
| 745 | - } | |
| 1797 | + return; | |
| 1798 | + } | |
| 746 | 1799 | |
| 747 | - /** | |
| 748 | - * Modifies the mail extras based on the notification type. | |
| 749 | - * | |
| 750 | - * @since 1.0.0 | |
| 751 | - * @package userswp | |
| 752 | - * @subpackage userswp/includes | |
| 753 | - * @param string $extras Unmodified mail extras. | |
| 754 | - * @param string $type Notification type. | |
| 755 | - * @return string Modified mail extras. | |
| 756 | - */ | |
| 757 | - public function init_mail_extras($extras, $type, $user_id) { | |
| 758 | - switch ($type) { | |
| 759 | - case "activate": | |
| 760 | - $extras = $this->generate_activate_message($user_id); | |
| 761 | - break; | |
| 762 | - case "register": | |
| 763 | - $extras = $this->generate_register_message($user_id); | |
| 764 | - break; | |
| 765 | - case "forgot": | |
| 766 | - $extras = $this->generate_forgot_message($user_id); | |
| 767 | - } | |
| 768 | - return $extras; | |
| 769 | - } | |
| 770 | - | |
| 771 | - /** | |
| 772 | - * Modifies the admin mail subject based on the admin notification type. | |
| 773 | - * | |
| 774 | - * @since 1.0.0 | |
| 775 | - * @package userswp | |
| 776 | - * @subpackage userswp/includes | |
| 777 | - * @param string $subject Unmodified admin mail subject. | |
| 778 | - * @param string $type Admin notification type. | |
| 779 | - * @return string Modified admin mail subject. | |
| 780 | - */ | |
| 781 | - public function init_admin_mail_subject($subject, $type) { | |
| 782 | - switch ($type) { | |
| 783 | - case "register_admin": | |
| 784 | - $subject = uwp_get_option('registration_success_email_subject_admin', ''); | |
| 785 | - break; | |
| 786 | - } | |
| 787 | - return $subject; | |
| 788 | - } | |
| 1800 | + do_action( 'uwp_after_validate', $result, 'change', $data ); | |
| 789 | 1801 | |
| 790 | - /** | |
| 791 | - * Modifies the admin mail content based on the admin notification type. | |
| 792 | - * | |
| 793 | - * @since 1.0.0 | |
| 794 | - * @package userswp | |
| 795 | - * @subpackage userswp/includes | |
| 796 | - * @param string $content Unmodified admin mail content. | |
| 797 | - * @param string $type Admin notification type. | |
| 798 | - * @return string Modified admin mail content. | |
| 799 | - */ | |
| 800 | - public function init_admin_mail_content($content, $type) { | |
| 801 | - switch ($type) { | |
| 802 | - case "register_admin": | |
| 803 | - $content = uwp_get_option('registration_success_email_content_admin', ''); | |
| 804 | - break; | |
| 805 | - } | |
| 806 | - return $content; | |
| 807 | - } | |
| 1802 | + $user_data = get_user_by( 'id', get_current_user_id() ); | |
| 808 | 1803 | |
| 809 | - /** | |
| 810 | - * Modifies the admin mail extras based on the notification type. | |
| 811 | - * | |
| 812 | - * @since 1.0.0 | |
| 813 | - * @package userswp | |
| 814 | - * @subpackage userswp/includes | |
| 815 | - * @param string $extras Unmodified mail extras. | |
| 816 | - * @param string $type Notification type. | |
| 817 | - * @return string Modified mail extras. | |
| 818 | - */ | |
| 819 | - public function init_admin_mail_extras($extras, $type, $user_id) { | |
| 820 | - switch ($type) { | |
| 821 | - case "register_admin": | |
| 822 | - $user_data = get_userdata($user_id); | |
| 823 | - $extras = __('<p><b>' . __('User Information :', 'userswp') . '</b></p> | |
| 824 | - <p>' . __('First Name:', 'userswp') . ' ' . $user_data->first_name . '</p> | |
| 825 | - <p>' . __('Last Name:', 'userswp') . ' ' . $user_data->last_name . '</p> | |
| 826 | - <p>' . __('Username:', 'userswp') . ' ' . $user_data->user_login . '</p> | |
| 827 | - <p>' . __('Email:', 'userswp') . ' ' . $user_data->user_email . '</p>'); | |
| 828 | - break; | |
| 829 | - } | |
| 830 | - return $extras; | |
| 831 | - } | |
| 1804 | + if ( ! $user_data ) { | |
| 1805 | + $message = aui()->alert( | |
| 1806 | + array( | |
| 1807 | + 'type' => 'error', | |
| 1808 | + 'content' => $user_data->get_error_message(), | |
| 1809 | + ) | |
| 1810 | + ); | |
| 1811 | + $uwp_notices[] = array( $notice_type => $message ); | |
| 832 | 1812 | |
| 833 | - /** | |
| 834 | - * Generates activate email message. | |
| 835 | - * | |
| 836 | - * @since 1.0.0 | |
| 837 | - * @package userswp | |
| 838 | - * | |
| 839 | - * @param int $user_id User ID. | |
| 840 | - * | |
| 841 | - * @return bool|string Message. | |
| 842 | - */ | |
| 843 | - public function generate_activate_message($user_id) { | |
| 1813 | + return; | |
| 1814 | + } | |
| 844 | 1815 | |
| 845 | - $user_data = get_userdata($user_id); | |
| 846 | - global $wpdb; | |
| 847 | - $key = wp_generate_password( 20, false ); | |
| 848 | - do_action( 'uwp_activation_key', $user_data->user_login, $key ); | |
| 1816 | + $email_vars = array( | |
| 1817 | + 'user_id' => $user_data->ID, | |
| 1818 | + ); | |
| 849 | 1819 | |
| 850 | - global $wp_hasher; | |
| 851 | - if ( empty( $wp_hasher ) ) { | |
| 852 | - require_once ABSPATH . 'wp-includes/class-phpass.php'; | |
| 853 | - $wp_hasher = new PasswordHash( 8, true ); | |
| 854 | - } | |
| 855 | - $hashed = $wp_hasher->HashPassword( $key ); | |
| 856 | - $wpdb->update( $wpdb->users, array( 'user_activation_key' => time().":".$hashed ), array( 'user_login' => $user_data->user_login ) ); | |
| 857 | - update_user_meta( $user_id, 'uwp_mod', 'email_unconfirmed' ); | |
| 858 | - $message = __('To activate your account, visit the following address:', 'userswp') . "\r\n\r\n"; | |
| 859 | - $act_url = add_query_arg( | |
| 1820 | + UsersWP_Mails::send( $user_data->user_email, 'change_password', $email_vars ); | |
| 1821 | + | |
| 1822 | + wp_set_password( $result['password'], $user_data->ID ); | |
| 1823 | + | |
| 1824 | + $password_nag = get_user_option( 'default_password_nag', $user_data->ID ); | |
| 1825 | + if ( $password_nag ) { | |
| 1826 | + delete_user_meta( $user_data->ID, 'default_password_nag' ); | |
| 1827 | + } | |
| 1828 | + | |
| 1829 | + delete_user_meta( $user_data->ID, 'is_uwp_social_login_no_password' ); | |
| 1830 | + | |
| 1831 | + $message = aui()->alert( | |
| 860 | 1832 | array( |
| 861 | - 'uwp_activate' => 'yes', | |
| 862 | - 'key' => $key, | |
| 863 | - 'login' => $user_data->user_login | |
| 864 | - ), | |
| 865 | - site_url() | |
| 866 | - ); | |
| 1833 | + 'type' => 'success', | |
| 1834 | + 'content' => apply_filters( 'uwp_change_password_success_message', __( 'Password changed successfully.', 'userswp' ), $data ), | |
| 1835 | + ) | |
| 1836 | + ); | |
| 867 | 1837 | |
| 868 | - $message .= "<a href='".$act_url."' target='_blank'>".$act_url."</a>" . "\r\n"; | |
| 1838 | + $uwp_notices[] = array( $notice_type => $message ); | |
| 869 | 1839 | |
| 870 | - $activate_message = __('<p><b>' . __('Please activate your account :', 'userswp') . '</b></p> | |
| 871 | - <p>' . $message . '</p>'); | |
| 1840 | + do_action( 'uwp_after_process_change', $data ); | |
| 872 | 1841 | |
| 873 | - return $activate_message; | |
| 1842 | + wp_logout(); | |
| 1843 | + exit(); | |
| 1844 | + } | |
| 874 | 1845 | |
| 875 | - } | |
| 1846 | + /** | |
| 1847 | + * Processes reset password form submission. | |
| 1848 | + * | |
| 1849 | + * @since 1.0.0 | |
| 1850 | + * @package userswp | |
| 1851 | + * | |
| 1852 | + */ | |
| 1853 | + public function process_reset() { | |
| 876 | 1854 | |
| 877 | - /** | |
| 878 | - * Generates register email message. | |
| 879 | - * | |
| 880 | - * @since 1.0.0 | |
| 881 | - * @package userswp | |
| 882 | - * | |
| 883 | - * @param int $user_id User ID. | |
| 884 | - * | |
| 885 | - * @return bool|string Message. | |
| 886 | - */ | |
| 887 | - public function generate_register_message($user_id) { | |
| 1855 | + $data = $_POST; | |
| 888 | 1856 | |
| 889 | - $user_data = get_userdata($user_id); | |
| 890 | - if(isset($this->generated_password) && !empty($this->generated_password)) { | |
| 891 | - if(!uwp_get_option('change_disable_password_nag')) { | |
| 892 | - update_user_meta($user_id, 'default_password_nag', true); //Set up the Password change nag. | |
| 893 | - } | |
| 894 | - $message_pass = $this->generated_password; | |
| 895 | - $this->generated_password = false; | |
| 896 | - } else { | |
| 897 | - $message_pass = __("Password you entered", 'userswp'); | |
| 898 | - } | |
| 899 | - $message = __('<p><b>' . __('Your login Information :', 'userswp') . '</b></p> | |
| 900 | - <p>' . __('Username:', 'userswp') . ' ' . $user_data->user_login . '</p> | |
| 901 | - <p>' . __('Password:', 'userswp') . ' ' . $message_pass . '</p>'); | |
| 1857 | + if ( isset( $data['uwp_reset_hp'] ) && '' != $data['uwp_reset_hp'] ) { | |
| 1858 | + wp_die( esc_html__( 'No spam please!', 'userswp' ) ); | |
| 1859 | + } | |
| 902 | 1860 | |
| 903 | - return $message; | |
| 1861 | + if ( ! isset( $data['uwp_reset_nonce'] ) || ! wp_verify_nonce( $data['uwp_reset_nonce'], 'uwp-reset-nonce' ) ) { | |
| 1862 | + return; | |
| 1863 | + } | |
| 904 | 1864 | |
| 905 | - } | |
| 906 | - | |
| 907 | - /** | |
| 908 | - * Generates forgot password email message. | |
| 909 | - * | |
| 910 | - * @since 1.0.0 | |
| 911 | - * @package userswp | |
| 912 | - * | |
| 913 | - * @param int $user_id User ID. | |
| 914 | - * | |
| 915 | - * @return bool|string Message. | |
| 916 | - */ | |
| 917 | - public function generate_forgot_message($user_id) { | |
| 1865 | + global $uwp_notices; | |
| 918 | 1866 | |
| 919 | - $user_data = get_userdata($user_id); | |
| 920 | - global $wpdb, $wp_hasher; | |
| 1867 | + do_action( 'uwp_before_validate', 'reset' ); | |
| 921 | 1868 | |
| 922 | - $allow = apply_filters('allow_password_reset', true, $user_data->ID); | |
| 923 | - if ( ! $allow ) | |
| 924 | - return false; | |
| 925 | - else if ( is_wp_error($allow) ) | |
| 926 | - return false; | |
| 1869 | + $result = uwp_validate_fields( $data, 'reset' ); | |
| 927 | 1870 | |
| 928 | - $as_password = apply_filters('uwp_forgot_message_as_password', false); | |
| 1871 | + $result = apply_filters( 'uwp_validate_result', $result, 'reset', $data ); | |
| 929 | 1872 | |
| 930 | - if ($as_password) { | |
| 931 | - $new_pass = wp_generate_password(12, false); | |
| 932 | - wp_set_password($new_pass, $user_data->ID); | |
| 933 | - if(!uwp_get_option('change_disable_password_nag')) { | |
| 934 | - update_user_meta($user_data->ID, 'default_password_nag', true); //Set up the Password change nag. | |
| 935 | - } | |
| 936 | - $message = '<p><b>' . __('Your login Information :', 'userswp') . '</b></p>'; | |
| 937 | - $message .= '<p>' . sprintf(__('Username: %s', 'userswp'), $user_data->user_login) . "</p>"; | |
| 938 | - $message .= '<p>' . sprintf(__('Password: %s', 'userswp'), $new_pass) . "</p>"; | |
| 1873 | + if ( is_wp_error( $result ) ) { | |
| 1874 | + $message = aui()->alert( | |
| 1875 | + array( | |
| 1876 | + 'type' => 'error', | |
| 1877 | + 'content' => $result->get_error_message(), | |
| 1878 | + ) | |
| 1879 | + ); | |
| 1880 | + $uwp_notices[] = array( 'reset' => $message ); | |
| 939 | 1881 | |
| 940 | - } else { | |
| 941 | - $key = wp_generate_password( 20, false ); | |
| 942 | - do_action( 'retrieve_password_key', $user_data->user_login, $key ); | |
| 1882 | + return; | |
| 1883 | + } | |
| 943 | 1884 | |
| 944 | - if ( empty( $wp_hasher ) ) { | |
| 945 | - require_once ABSPATH . 'wp-includes/class-phpass.php'; | |
| 946 | - $wp_hasher = new PasswordHash( 8, true ); | |
| 947 | - } | |
| 948 | - $hashed = $wp_hasher->HashPassword( $key ); | |
| 949 | - $wpdb->update( $wpdb->users, array( 'user_activation_key' => time().":".$hashed ), array( 'user_login' => $user_data->user_login ) ); | |
| 950 | - $message = '<p>' .__('You have requested to reset your password for the following account:', 'userswp') . "</p>"; | |
| 951 | - $message .= home_url( '/' ) . "</p>"; | |
| 952 | - $message .= '<p>' .sprintf(__('Username: %s', 'userswp'), $user_data->user_login) . "</p>"; | |
| 953 | - $message .= '<p>' .__('If this was by mistake, just ignore this email and nothing will happen.', 'userswp') . "</p>"; | |
| 954 | - $message .= '<p>' .__('To reset your password, click the following link and follow the instructions.', 'userswp') . "</p>"; | |
| 955 | - $message = apply_filters('uwp_forgot_password_message', $message, $user_data); | |
| 956 | - $reset_page = uwp_get_page_id('reset_page', false); | |
| 957 | - if ($reset_page) { | |
| 958 | - $reset_link = add_query_arg( array( | |
| 959 | - 'key' => $key, | |
| 960 | - 'login' => rawurlencode($user_data->user_login), | |
| 961 | - ), get_permalink($reset_page) ); | |
| 962 | - $message .= "<a href='".$reset_link."' target='_blank'>".$reset_link."</a>" . "\r\n"; | |
| 963 | - } else { | |
| 964 | - $message .= site_url("reset?key=$key&login=" . rawurlencode($user_data->user_login), 'login') . "\r\n"; | |
| 965 | - } | |
| 966 | - } | |
| 1885 | + do_action( 'uwp_after_validate', $result, 'reset', $data ); | |
| 967 | 1886 | |
| 1887 | + $login = sanitize_text_field( $data['uwp_reset_username'] ); | |
| 1888 | + $key = sanitize_text_field( $data['uwp_reset_key'] ); | |
| 968 | 1889 | |
| 969 | - return $message; | |
| 1890 | + $user = get_user_by( 'login', $login ); | |
| 1891 | + if ( ! $user ) { | |
| 1892 | + $message = aui()->alert( | |
| 1893 | + array( | |
| 1894 | + 'type' => 'error', | |
| 1895 | + 'content' => __( 'Invalid username.', 'userswp' ), | |
| 1896 | + ) | |
| 1897 | + ); | |
| 1898 | + $uwp_notices[] = array( 'reset' => $message ); | |
| 970 | 1899 | |
| 971 | - } | |
| 1900 | + return; | |
| 1901 | + } | |
| 972 | 1902 | |
| 973 | - /** | |
| 974 | - * Processes account form submission. | |
| 975 | - * | |
| 976 | - * @since 1.0.0 | |
| 977 | - * @package userswp | |
| 978 | - * | |
| 979 | - * @param array $data Submitted $_POST data | |
| 980 | - * @param array $files Submitted $_FILES data | |
| 981 | - * | |
| 982 | - * @return bool|WP_Error|string | |
| 983 | - */ | |
| 984 | - public function process_account($data = array(), $files = array()) { | |
| 1903 | + clean_user_cache( $user ); | |
| 985 | 1904 | |
| 986 | - $file_obj = new UsersWP_Files(); | |
| 987 | - | |
| 988 | - $current_user_id = get_current_user_id(); | |
| 989 | - if (!$current_user_id) { | |
| 990 | - return false; | |
| 991 | - } | |
| 1905 | + $user_data = check_password_reset_key( $key, $login ); | |
| 992 | 1906 | |
| 993 | - $errors = new WP_Error(); | |
| 1907 | + if ( is_wp_error( $user_data ) ) { | |
| 1908 | + $error = apply_filters( 'uwp_reset_password_error_message', $user_data->get_error_message(), $user_data ); | |
| 1909 | + $message = aui()->alert( | |
| 1910 | + array( | |
| 1911 | + 'type' => 'error', | |
| 1912 | + 'content' => $error, | |
| 1913 | + ) | |
| 1914 | + ); | |
| 1915 | + $uwp_notices[] = array( 'reset' => $message ); | |
| 994 | 1916 | |
| 995 | - if( ! isset( $data['uwp_account_nonce'] ) || ! wp_verify_nonce( $data['uwp_account_nonce'], 'uwp-account-nonce' ) ) { | |
| 996 | - return false; | |
| 997 | - } | |
| 1917 | + return; | |
| 1918 | + } | |
| 998 | 1919 | |
| 999 | - do_action('uwp_before_validate', 'account'); | |
| 1920 | + $email_vars = array( | |
| 1921 | + 'user_id' => $user_data->ID, | |
| 1922 | + ); | |
| 1000 | 1923 | |
| 1001 | - $result = uwp_validate_fields($data, 'account'); | |
| 1924 | + UsersWP_Mails::send( $user_data->user_email, 'reset_password', $email_vars ); | |
| 1002 | 1925 | |
| 1003 | - $result = apply_filters('uwp_validate_result', $result, 'account', $data); | |
| 1926 | + wp_set_password( $data['password'], $user_data->ID ); | |
| 1004 | 1927 | |
| 1005 | - if (is_wp_error($result)) { | |
| 1006 | - return $result; | |
| 1007 | - } | |
| 1928 | + $login_page_url = uwp_get_login_page_url(); | |
| 1929 | + $message = sprintf( __( 'Password updated successfully. Please <a href="%s">login</a> with your new password.', 'userswp' ), $login_page_url ); | |
| 1930 | + $message = apply_filters( 'uwp_reset_password_success_message', $message, $data ); | |
| 1931 | + $message = aui()->alert( | |
| 1932 | + array( | |
| 1933 | + 'type' => 'success', | |
| 1934 | + 'content' => $message, | |
| 1935 | + ) | |
| 1936 | + ); | |
| 1937 | + $uwp_notices[] = array( 'reset' => $message ); | |
| 1008 | 1938 | |
| 1009 | - $uploads_result = $file_obj->uwp_validate_uploads($files, 'account'); | |
| 1939 | + do_action( 'uwp_after_process_reset', $data ); | |
| 1940 | + } | |
| 1010 | 1941 | |
| 1011 | - if (is_wp_error($uploads_result)) { | |
| 1012 | - return $uploads_result; | |
| 1013 | - } | |
| 1942 | + /** | |
| 1943 | + * Processes account form submission. | |
| 1944 | + * | |
| 1945 | + * @since 1.0.0 | |
| 1946 | + * @package userswp | |
| 1947 | + * | |
| 1948 | + */ | |
| 1949 | + public function process_account() { | |
| 1014 | 1950 | |
| 1015 | - do_action('uwp_after_validate', 'account'); | |
| 1951 | + $data = wp_unslash( $_POST ); | |
| 1952 | + $files = $_FILES; | |
| 1016 | 1953 | |
| 1017 | - //unset if value is empty for files | |
| 1018 | - foreach ($uploads_result as $upload_file_key => $upload_file_value) { | |
| 1019 | - if (empty($upload_file_value)) { | |
| 1020 | - unset($uploads_result[$upload_file_key]); | |
| 1021 | - } | |
| 1022 | - } | |
| 1954 | + if ( ! isset( $data['uwp_account_nonce'] ) || ! wp_verify_nonce( $data['uwp_account_nonce'], 'uwp-account-nonce' ) ) { | |
| 1955 | + return; | |
| 1956 | + } | |
| 1023 | 1957 | |
| 1024 | - $result = array_merge( $result, $uploads_result ); | |
| 1958 | + if ( ! is_user_logged_in() ) { | |
| 1959 | + return; | |
| 1960 | + } | |
| 1025 | 1961 | |
| 1962 | + global $uwp_notices; | |
| 1963 | + $file_obj = new UsersWP_Files(); | |
| 1026 | 1964 | |
| 1027 | - $args = array( | |
| 1028 | - 'ID' => $current_user_id | |
| 1029 | - ); | |
| 1965 | + do_action( 'uwp_before_validate', 'account' ); | |
| 1030 | 1966 | |
| 1031 | - if (isset($result['uwp_account_email'])) { | |
| 1032 | - $args['user_email'] = $result['uwp_account_email']; | |
| 1033 | - } | |
| 1967 | + $result = uwp_validate_fields( $data, 'account' ); | |
| 1034 | 1968 | |
| 1035 | - if (isset($result['uwp_account_first_name']) && isset($result['uwp_account_last_name'])) { | |
| 1036 | - $args['display_name'] = $result['uwp_account_first_name'] . ' ' . $result['uwp_account_last_name']; | |
| 1037 | - } | |
| 1969 | + $result = apply_filters( 'uwp_validate_result', $result, 'account', $data ); | |
| 1038 | 1970 | |
| 1039 | - if (isset($result['uwp_account_first_name'])) { | |
| 1040 | - $args['first_name'] = $result['uwp_account_first_name']; | |
| 1041 | - } | |
| 1971 | + if ( is_wp_error( $result ) ) { | |
| 1972 | + $message = aui()->alert( | |
| 1973 | + array( | |
| 1974 | + 'type' => 'error', | |
| 1975 | + 'content' => $result->get_error_message(), | |
| 1976 | + ) | |
| 1977 | + ); | |
| 1978 | + $uwp_notices[] = array( 'account' => $message ); | |
| 1042 | 1979 | |
| 1043 | - if (isset($result['uwp_account_last_name'])) { | |
| 1044 | - $args['last_name'] = $result['uwp_account_last_name']; | |
| 1045 | - } | |
| 1980 | + return; | |
| 1981 | + } | |
| 1046 | 1982 | |
| 1047 | - if (isset($result['uwp_account_bio'])) { | |
| 1048 | - $args['description'] = $result['uwp_account_bio']; | |
| 1049 | - } | |
| 1983 | + $uploads_result = $file_obj->validate_uploads( $files, 'account' ); | |
| 1050 | 1984 | |
| 1051 | - if (isset($result['uwp_account_display_name']) && !empty($result['uwp_account_display_name'])) { | |
| 1052 | - $args['display_name'] = $result['uwp_account_display_name']; | |
| 1053 | - } | |
| 1985 | + if ( is_wp_error( $uploads_result ) ) { | |
| 1986 | + $message = aui()->alert( | |
| 1987 | + array( | |
| 1988 | + 'type' => 'error', | |
| 1989 | + 'content' => $uploads_result->get_error_message(), | |
| 1990 | + ) | |
| 1991 | + ); | |
| 1992 | + $uwp_notices[] = array( 'account' => $message ); | |
| 1054 | 1993 | |
| 1055 | - if (isset($result['password'])) { | |
| 1056 | - $args['user_pass'] = $result['password']; | |
| 1057 | - } | |
| 1994 | + return; | |
| 1995 | + } | |
| 1058 | 1996 | |
| 1059 | - $user_id = wp_update_user( $args ); | |
| 1997 | + do_action( 'uwp_after_validate', $result, 'account', $data ); | |
| 1060 | 1998 | |
| 1061 | - if (!$user_id) { | |
| 1062 | - $errors->add('registerfail', sprintf(__('<strong>Error</strong>: Something went wrong.', 'userswp'), get_option('admin_email'))); | |
| 1063 | - return $errors; | |
| 1064 | - } | |
| 1999 | + //unset if value is empty for files | |
| 2000 | + foreach ( $uploads_result as $upload_file_key => $upload_file_value ) { | |
| 2001 | + if ( empty( $upload_file_value ) ) { | |
| 2002 | + unset( $uploads_result[ $upload_file_key ] ); | |
| 2003 | + } | |
| 2004 | + } | |
| 1065 | 2005 | |
| 1066 | - $res = $this->uwp_save_user_extra_fields($user_id, $result, 'account'); | |
| 2006 | + $result = array_merge( $result, $uploads_result ); | |
| 1067 | 2007 | |
| 1068 | - if (!$res) { | |
| 1069 | - $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp')); | |
| 1070 | - } | |
| 2008 | + $args = array( | |
| 2009 | + 'ID' => get_current_user_id(), | |
| 2010 | + ); | |
| 1071 | 2011 | |
| 1072 | - $error_code = $errors->get_error_code(); | |
| 1073 | - if (!empty($error_code)) { | |
| 1074 | - return $errors; | |
| 1075 | - } | |
| 2012 | + if ( isset( $result['first_name'] ) && isset( $result['last_name'] ) ) { | |
| 2013 | + $args['display_name'] = $result['first_name'] . ' ' . $result['last_name']; | |
| 2014 | + } | |
| 1076 | 2015 | |
| 2016 | + if ( isset( $result['first_name'] ) ) { | |
| 2017 | + $args['first_name'] = $result['first_name']; | |
| 2018 | + } | |
| 1077 | 2019 | |
| 1078 | - if (uwp_get_option('enable_account_update_notification') == '1') { | |
| 1079 | - $user_data = get_user_by('id', $user_id); | |
| 2020 | + if ( isset( $result['last_name'] ) ) { | |
| 2021 | + $args['last_name'] = $result['last_name']; | |
| 2022 | + } | |
| 1080 | 2023 | |
| 1081 | - $email = new UsersWP_Mails(); | |
| 1082 | - $send_result = $email->send( 'account', $user_data->ID ); | |
| 2024 | + if ( isset( $result['user_url'] ) ) { | |
| 2025 | + $args['user_url'] = $result['user_url']; | |
| 2026 | + } | |
| 1083 | 2027 | |
| 1084 | - $send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors); | |
| 1085 | - if (is_wp_error($send_result)) { | |
| 1086 | - return $send_result; | |
| 1087 | - } | |
| 1088 | - | |
| 1089 | - } | |
| 1090 | - | |
| 1091 | - return true; | |
| 2028 | + if ( isset( $result['display_name'] ) && ! empty( $result['display_name'] ) ) { | |
| 2029 | + $args['display_name'] = $result['display_name']; | |
| 2030 | + } | |
| 1092 | 2031 | |
| 1093 | - } | |
| 2032 | + if ( isset( $result['password'] ) ) { | |
| 2033 | + $args['user_pass'] = $result['password']; | |
| 2034 | + } | |
| 1094 | 2035 | |
| 1095 | - /** | |
| 1096 | - * Processes avatar and banner uploads form submission. | |
| 1097 | - * | |
| 1098 | - * @since 1.0.0 | |
| 1099 | - * @package userswp | |
| 1100 | - * | |
| 1101 | - * @param array $data Submitted $_POST data | |
| 1102 | - * @param array $files Submitted $_FILES data | |
| 1103 | - * | |
| 1104 | - * @return bool|WP_Error|string File url to crop. | |
| 1105 | - */ | |
| 1106 | - public function process_upload_submit($data = array(), $files = array(), $type = 'avatar') { | |
| 2036 | + $user_id = wp_update_user( $args ); | |
| 1107 | 2037 | |
| 1108 | - $file_obj = new UsersWP_Files(); | |
| 1109 | - | |
| 1110 | - $current_user_id = get_current_user_id(); | |
| 1111 | - if (!$current_user_id) { | |
| 1112 | - return false; | |
| 1113 | - } | |
| 2038 | + if ( is_wp_error( $user_id ) ) { | |
| 2039 | + $message = aui()->alert( | |
| 2040 | + array( | |
| 2041 | + 'type' => 'error', | |
| 2042 | + 'content' => sprintf( __( '%s', 'userswp' ), $user_id->get_error_message() ), | |
| 2043 | + ) | |
| 2044 | + ); | |
| 2045 | + $uwp_notices[] = array( 'account' => $message ); | |
| 1114 | 2046 | |
| 1115 | - if( ! isset( $data['uwp_upload_nonce'] ) || ! wp_verify_nonce( $data['uwp_upload_nonce'], 'uwp-upload-nonce' ) ) { | |
| 1116 | - return false; | |
| 1117 | - } | |
| 2047 | + return; | |
| 2048 | + } | |
| 1118 | 2049 | |
| 1119 | - do_action('uwp_before_validate', $type); | |
| 2050 | + $res = $this->save_user_extra_fields( $user_id, $result, 'account' ); | |
| 1120 | 2051 | |
| 1121 | - $result = $file_obj->uwp_validate_uploads($files, $type); | |
| 2052 | + if ( ! $res ) { | |
| 2053 | + $message = aui()->alert( | |
| 2054 | + array( | |
| 2055 | + 'type' => 'error', | |
| 2056 | + 'content' => __( 'Something went wrong. Please contact site admin.', 'userswp' ), | |
| 2057 | + ) | |
| 2058 | + ); | |
| 2059 | + $uwp_notices[] = array( 'account' => $message ); | |
| 1122 | 2060 | |
| 1123 | - $result = apply_filters('uwp_validate_result', $result, $type, $data); | |
| 2061 | + return; | |
| 2062 | + } | |
| 1124 | 2063 | |
| 1125 | - if (is_wp_error($result)) { | |
| 1126 | - return $result; | |
| 1127 | - } | |
| 2064 | + //updating bio field after saving extra fields to reflect the points in mycred add on. | |
| 2065 | + if ( isset( $result['bio'] ) && ! empty( $result['bio'] ) ) { | |
| 2066 | + $args = array( | |
| 2067 | + 'ID' => $user_id, | |
| 2068 | + 'description' => $result['bio'], | |
| 2069 | + ); | |
| 2070 | + wp_update_user( $args ); | |
| 2071 | + } | |
| 1128 | 2072 | |
| 1129 | - $profile_url = uwp_build_profile_tab_url($current_user_id); | |
| 2073 | + $user_data = get_userdata( $user_id ); | |
| 1130 | 2074 | |
| 1131 | - $url = add_query_arg( | |
| 1132 | - array( | |
| 1133 | - 'uwp_crop' => $result['uwp_'.$type.'_file'], | |
| 1134 | - 'type' => $type | |
| 1135 | - ), | |
| 1136 | - $profile_url); | |
| 2075 | + $form_fields = apply_filters( 'uwp_send_mail_form_fields', '', 'account', $user_id ); | |
| 1137 | 2076 | |
| 1138 | - return $url; | |
| 2077 | + if ( isset( $result['email'] ) && $user_data->user_email !== trim( $result['email'] ) ) { | |
| 1139 | 2078 | |
| 1140 | - } | |
| 2079 | + if ( email_exists( trim( $result['email'] ) ) ) { | |
| 2080 | + $message = aui()->alert( | |
| 2081 | + array( | |
| 2082 | + 'type' => 'error', | |
| 2083 | + 'content' => __( 'This email is already registered, please choose another one.', 'userswp' ), | |
| 2084 | + ) | |
| 2085 | + ); | |
| 1141 | 2086 | |
| 1142 | - /** | |
| 1143 | - * Processes avatar and banner uploads image crop. | |
| 1144 | - * | |
| 1145 | - * @since 1.0.0 | |
| 1146 | - * @since 1.0.12 New param $unlink_prev_img introduced. | |
| 1147 | - * @package userswp | |
| 1148 | - * | |
| 1149 | - * @param array $data Submitted $_POST data | |
| 1150 | - * @param string $type Image type. Default 'avatar'. | |
| 1151 | - * @param bool $unlink_prev_img True to remove previous image. Default false; | |
| 1152 | - * | |
| 1153 | - * @return bool|WP_Error|string Profile url. | |
| 1154 | - */ | |
| 1155 | - public function process_image_crop($data = array(), $type = 'avatar', $unlink_prev_img = false) { | |
| 1156 | - | |
| 1157 | - if (!is_user_logged_in()) { | |
| 1158 | - return false; | |
| 2087 | + $uwp_notices[] = array( 'account' => $message ); | |
| 2088 | + return; | |
| 2089 | + | |
| 2090 | + } | |
| 2091 | + | |
| 2092 | + $hash = md5( $result['email'] . time() . wp_rand() ); | |
| 2093 | + $new_admin_email = array( | |
| 2094 | + 'hash' => $hash, | |
| 2095 | + 'newemail' => $result['email'], | |
| 2096 | + ); | |
| 2097 | + | |
| 2098 | + update_user_meta( get_current_user_id(), 'uwp_update_email_hash', $new_admin_email ); | |
| 2099 | + | |
| 2100 | + $new_email_link = add_query_arg( | |
| 2101 | + array( | |
| 2102 | + 'uwp_new_email' => 'yes', | |
| 2103 | + 'key' => $hash, | |
| 2104 | + 'login' => $user_data->user_login, | |
| 2105 | + ), | |
| 2106 | + uwp_get_account_page_url() | |
| 2107 | + ); | |
| 2108 | + | |
| 2109 | + $email_vars = array( | |
| 2110 | + 'user_id' => $user_id, | |
| 2111 | + 'new_email' => $result['email'], | |
| 2112 | + 'new_email_link' => esc_url( $new_email_link ), | |
| 2113 | + ); | |
| 2114 | + | |
| 2115 | + UsersWP_Mails::send( $result['email'], 'account_new_email_activation', $email_vars ); | |
| 2116 | + | |
| 2117 | + $message = apply_filters( 'uwp_account_pending_new_email_activation_message', __( 'Account updated successfully. The new address will become active once you confirm via activation link sent to your new email.', 'userswp' ), $data ); | |
| 2118 | + $message = aui()->alert( | |
| 2119 | + array( | |
| 2120 | + 'type' => 'success', | |
| 2121 | + 'content' => $message, | |
| 2122 | + ) | |
| 2123 | + ); | |
| 2124 | + | |
| 2125 | + $uwp_notices[] = array( 'account' => $message ); | |
| 2126 | + | |
| 2127 | + } else { | |
| 2128 | + $email_vars = array( | |
| 2129 | + 'user_id' => $user_id, | |
| 2130 | + 'form_fields' => $form_fields, | |
| 2131 | + ); | |
| 2132 | + | |
| 2133 | + UsersWP_Mails::send( $user_data->user_email, 'account_update', $email_vars ); | |
| 2134 | + | |
| 2135 | + $message = apply_filters( 'uwp_account_update_success_message', __( 'Account updated successfully.', 'userswp' ), $data ); | |
| 2136 | + $message = aui()->alert( | |
| 2137 | + array( | |
| 2138 | + 'type' => 'success', | |
| 2139 | + 'content' => $message, | |
| 2140 | + ) | |
| 2141 | + ); | |
| 2142 | + | |
| 2143 | + $uwp_notices[] = array( 'account' => $message ); | |
| 1159 | 2144 | } |
| 1160 | 2145 | |
| 1161 | - // If is current user's profile (profile.php) | |
| 1162 | - if ( is_admin() && defined('IS_PROFILE_PAGE') && IS_PROFILE_PAGE ) { | |
| 1163 | - $user_id = get_current_user_id(); | |
| 1164 | - // If is another user's profile page | |
| 1165 | - } elseif (is_admin() && ! empty($_GET['user_id']) && is_numeric($_GET['user_id']) ) { | |
| 1166 | - $user_id = $_GET['user_id']; | |
| 1167 | - // Otherwise something is wrong. | |
| 1168 | - } else { | |
| 1169 | - $user_id = get_current_user_id(); | |
| 1170 | - } | |
| 1171 | - $image_url = $data['uwp_crop']; | |
| 1172 | - | |
| 1173 | - $errors = new WP_Error(); | |
| 1174 | - if (empty($image_url)) { | |
| 1175 | - $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp')); | |
| 1176 | - } | |
| 2146 | + do_action( 'uwp_after_process_account', $data, $user_id ); | |
| 2147 | + } | |
| 1177 | 2148 | |
| 1178 | - $error_code = $errors->get_error_code(); | |
| 1179 | - if (!empty($error_code)) { | |
| 1180 | - return $errors; | |
| 1181 | - } | |
| 1182 | - | |
| 1183 | - if ($image_url) { | |
| 1184 | - if ($type == 'avatar') { | |
| 1185 | - $full_width = apply_filters('uwp_avatar_image_width', 150); | |
| 1186 | - } else { | |
| 1187 | - $full_width = apply_filters('uwp_banner_image_width', uwp_get_option('profile_banner_width', 1000)); | |
| 1188 | - } | |
| 2149 | + /** | |
| 2150 | + * Modifies the forms field in email based on the form type. | |
| 2151 | + * | |
| 2152 | + * @param string $form_fields Form fields. | |
| 2153 | + * @param string $type Form type. | |
| 2154 | + * @param int $user_id User ID. | |
| 2155 | + * | |
| 2156 | + * @return string Modified mail field. | |
| 2157 | + * @package userswp | |
| 2158 | + * @subpackage userswp/includes | |
| 2159 | + * | |
| 2160 | + */ | |
| 2161 | + public function init_mail_form_fields( $form_fields, $type, $user_id ) { | |
| 2162 | + switch ( $type ) { | |
| 2163 | + case 'register': | |
| 2164 | + $form_id = get_user_meta( $user_id, '_uwp_register_form_id', true ); | |
| 2165 | + $fields = get_register_form_fields( $form_id ); | |
| 2166 | + $user_data = get_userdata( $user_id ); | |
| 2167 | + if ( ! empty( $fields ) && is_array( $fields ) ) { | |
| 2168 | + $form_fields = '<p><b>' . __( 'User Information:', 'userswp' ) . '</b></p>'; | |
| 2169 | + $excluded = uwp_get_excluded_fields(); | |
| 2170 | + foreach ( $fields as $key => $field ) { | |
| 2171 | + if ( $field->is_active != '1' || in_array( $field->htmlvar_name, $excluded ) ) { | |
| 2172 | + continue; | |
| 2173 | + } | |
| 2174 | + if ( $field->htmlvar_name == 'email' && isset( $user_data->user_email ) ) { | |
| 2175 | + $field_value = $user_data->user_email; | |
| 2176 | + } elseif ( $field->htmlvar_name == 'display_name' && isset( $user_data->user_login ) ) { | |
| 2177 | + $field_value = $user_data->user_login; | |
| 2178 | + } elseif ( $field->htmlvar_name == 'bio' ) { | |
| 2179 | + $field_value = get_user_meta( $user_id, 'description', true ); | |
| 2180 | + } else { | |
| 2181 | + $field_value = uwp_get_usermeta( $user_id, $field->htmlvar_name ); | |
| 2182 | + } | |
| 1189 | 2183 | |
| 1190 | - $image_url = esc_url($image_url); | |
| 1191 | - add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 ); | |
| 1192 | - $uploads = wp_upload_dir(); | |
| 1193 | - remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' ); | |
| 1194 | - $upload_url = $uploads['baseurl']; | |
| 1195 | - $upload_path = $uploads['basedir']; | |
| 1196 | - $image_url = str_replace($upload_url, $upload_path, $image_url); | |
| 1197 | - $ext = pathinfo($image_url, PATHINFO_EXTENSION); // to get extension | |
| 1198 | - $name =pathinfo($image_url, PATHINFO_FILENAME); //file name without extension | |
| 1199 | - $thumb_image_name = $name.'_uwp_'.$type.'_thumb'.'.'.$ext; | |
| 1200 | - $thumb_image_location = str_replace($name.'.'.$ext, $thumb_image_name, $image_url); | |
| 1201 | - //Get the new coordinates to crop the image. | |
| 1202 | - $x = $data["x"]; | |
| 1203 | - $y = $data["y"]; | |
| 1204 | - $w = $data["w"]; | |
| 1205 | - $h = $data["h"]; | |
| 1206 | - //Scale the image based on cropped width setting | |
| 1207 | - $scale = $full_width/$w; | |
| 1208 | - //$scale = 1; // no scaling | |
| 1209 | - $cropped = uwp_resizeThumbnailImage($thumb_image_location, $image_url,$x, $y, $w, $h,$scale); | |
| 1210 | - $cropped = str_replace($upload_path, $upload_url, $cropped); | |
| 2184 | + if ( is_array( $field_value ) && count( $field_value ) > 0 ) { | |
| 2185 | + $field_value = uwp_maybe_serialize( $field->htmlvar_name, $field_value ); | |
| 2186 | + } | |
| 1211 | 2187 | |
| 1212 | - // Remove previous avatar/banner | |
| 1213 | - $unlink_img = ''; | |
| 1214 | - if ($unlink_prev_img) { | |
| 1215 | - if ($type == 'avatar') { | |
| 1216 | - $previous_img = uwp_get_usermeta($user_id, 'uwp_account_avatar_thumb'); | |
| 1217 | - } else if ($type == 'banner') { | |
| 1218 | - $previous_img = uwp_get_usermeta($user_id, 'uwp_account_banner_thumb'); | |
| 1219 | - } else { | |
| 1220 | - $previous_img = ''; | |
| 2188 | + if ( isset( $field->site_title ) && ! empty( $field_value ) ) { | |
| 2189 | + $form_fields .= '<p><b>' . __( wp_unslash( $field->site_title ), 'userswp' ) . '</b>: ' . $field_value . '</p>'; | |
| 2190 | + } | |
| 2191 | + } | |
| 1221 | 2192 | } |
| 1222 | - | |
| 1223 | - if ($previous_img) { | |
| 1224 | - $unlink_img = untrailingslashit($upload_path) . '/' . ltrim($previous_img, '/'); | |
| 2193 | + break; | |
| 2194 | + case 'account': | |
| 2195 | + $fields = get_account_form_fields(); | |
| 2196 | + $user_data = get_userdata( $user_id ); | |
| 2197 | + if ( ! empty( $fields ) && is_array( $fields ) ) { | |
| 2198 | + $form_fields = '<p><b>' . __( 'User Information:', 'userswp' ) . '</b></p>'; | |
| 2199 | + foreach ( $fields as $key => $field ) { | |
| 2200 | + if ( $field->is_active != '1' ) { | |
| 2201 | + continue; | |
| 2202 | + } | |
| 2203 | + if ( $field->htmlvar_name == 'email' && isset( $user_data->user_email ) ) { | |
| 2204 | + $field_value = $user_data->user_email; | |
| 2205 | + } elseif ( $field->htmlvar_name == 'display_name' && isset( $user_data->user_login ) ) { | |
| 2206 | + $field_value = $user_data->user_login; | |
| 2207 | + } elseif ( $field->htmlvar_name == 'bio' ) { | |
| 2208 | + $field_value = get_user_meta( $user_id, 'description', true ); | |
| 2209 | + } else { | |
| 2210 | + $field_value = uwp_get_usermeta( $user_id, $field->htmlvar_name ); | |
| 2211 | + } | |
| 2212 | + | |
| 2213 | + if ( is_array( $field_value ) && count( $field_value ) > 0 ) { | |
| 2214 | + $field_value = uwp_maybe_serialize( $field->htmlvar_name, $field_value ); | |
| 2215 | + } | |
| 2216 | + | |
| 2217 | + if ( isset( $field->site_title ) && ! empty( $field_value ) ) { | |
| 2218 | + $form_fields .= '<p><b>' . __( wp_unslash( $field->site_title ), 'userswp' ) . '</b>: ' . $field_value . '</p>'; | |
| 2219 | + } | |
| 2220 | + } | |
| 1225 | 2221 | } |
| 2222 | + break; | |
| 2223 | + } | |
| 2224 | + | |
| 2225 | + return apply_filters( 'uwp_mail_form_fields', $form_fields, $type, $user_id ); | |
| 2226 | + } | |
| 2227 | + | |
| 2228 | + /** | |
| 2229 | + * | |
| 2230 | + * | |
| 2231 | + * @return void | |
| 2232 | + * @since 1.0.12 Unlink file. | |
| 2233 | + * @package userswp | |
| 2234 | + * @since 1.0.0 | |
| 2235 | + */ | |
| 2236 | + public function upload_file_remove() { | |
| 2237 | + check_ajax_referer( 'uwp_basic_nonce', 'security' ); | |
| 2238 | + | |
| 2239 | + $htmlvar = esc_sql( strip_tags( $_POST['htmlvar'] ) ); | |
| 2240 | + $user_id = ! empty( $_POST['uid'] ) ? absint( $_POST['uid'] ) : 0; | |
| 2241 | + | |
| 2242 | + if ( empty( $user_id ) ) { | |
| 2243 | + wp_die( -1 ); | |
| 2244 | + } | |
| 2245 | + | |
| 2246 | + if ( ! ( is_user_logged_in() && ( $user_id == (int) get_current_user_id() || current_user_can( 'manage_options' ) ) ) ) { | |
| 2247 | + wp_send_json_error( __( 'Invalid access!', 'userswp' ) ); | |
| 2248 | + } | |
| 2249 | + | |
| 2250 | + // Remove file | |
| 2251 | + if ( $htmlvar == 'banner_thumb' ) { | |
| 2252 | + $file = uwp_get_usermeta( $user_id, 'banner_thumb' ); | |
| 2253 | + $type = 'banner'; | |
| 2254 | + } elseif ( $htmlvar == 'avatar_thumb' ) { | |
| 2255 | + $file = uwp_get_usermeta( $user_id, 'avatar_thumb' ); | |
| 2256 | + $type = 'avatar'; | |
| 2257 | + } else { | |
| 2258 | + $file = ''; | |
| 2259 | + $type = ''; | |
| 2260 | + } | |
| 2261 | + | |
| 2262 | + uwp_update_usermeta( $user_id, $htmlvar, '' ); | |
| 2263 | + | |
| 2264 | + if ( $file ) { | |
| 2265 | + $uploads = wp_upload_dir(); | |
| 2266 | + $upload_path = $uploads['basedir']; | |
| 2267 | + $unlink_file = untrailingslashit( $upload_path ) . '/' . ltrim( $file, '/' ); | |
| 2268 | + | |
| 2269 | + if ( is_file( $unlink_file ) && file_exists( $unlink_file ) ) { | |
| 2270 | + @unlink( $unlink_file ); | |
| 2271 | + $unlink_ori_file = str_replace( '_uwp_' . $type . '_thumb' . '.', '.', $unlink_file ); | |
| 2272 | + | |
| 2273 | + if ( is_file( $unlink_ori_file ) && file_exists( $unlink_ori_file ) ) { | |
| 2274 | + @unlink( $unlink_ori_file ); | |
| 2275 | + } | |
| 1226 | 2276 | } |
| 2277 | + } | |
| 1227 | 2278 | |
| 1228 | - // remove the uploads path for easy migrations | |
| 1229 | - $cropped = str_replace($upload_url, '', $cropped); | |
| 1230 | - if ($type == 'avatar') { | |
| 1231 | - uwp_update_usermeta($user_id, 'uwp_account_avatar_thumb', $cropped); | |
| 1232 | - } else { | |
| 1233 | - uwp_update_usermeta($user_id, 'uwp_account_banner_thumb', $cropped); | |
| 1234 | - } | |
| 1235 | - | |
| 1236 | - if ($unlink_img && $unlink_img != $thumb_image_location && is_file($unlink_img) && file_exists($unlink_img)) { | |
| 1237 | - @unlink($unlink_img); | |
| 1238 | - $unlink_ori_img = str_replace('_uwp_'.$type.'_thumb'.'.', '.', $unlink_img); | |
| 1239 | - if (is_file($unlink_ori_img) && file_exists($unlink_ori_img)) { | |
| 1240 | - @unlink($unlink_ori_img); | |
| 2279 | + wp_send_json_success(); | |
| 2280 | + | |
| 2281 | + wp_die(); | |
| 2282 | + } | |
| 2283 | + | |
| 2284 | + /** | |
| 2285 | + * Form field template for datepicker field type. | |
| 2286 | + * | |
| 2287 | + * @param string $html Form field html | |
| 2288 | + * @param object $field Field info. | |
| 2289 | + * @param string $value Form field default value. | |
| 2290 | + * @param string $form_type Form type | |
| 2291 | + * | |
| 2292 | + * @return string Modified form field html. | |
| 2293 | + * @package userswp | |
| 2294 | + * | |
| 2295 | + * @since 1.0.0 | |
| 2296 | + */ | |
| 2297 | + public function form_input_datepicker( $html, $field, $value, $form_type ) { | |
| 2298 | + | |
| 2299 | + // Check if there is a field specific filter. | |
| 2300 | + if ( has_filter( "uwp_form_input_html_datepicker_{$field->htmlvar_name}" ) ) { | |
| 2301 | + $html = apply_filters( "uwp_form_input_html_datepicker_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 2302 | + } | |
| 2303 | + | |
| 2304 | + // If no html then we run the standard output. | |
| 2305 | + if ( empty( $html ) ) { | |
| 2306 | + | |
| 2307 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 2308 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 2309 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 2310 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 2311 | + $extra_attributes = array(); | |
| 2312 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 2313 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 2314 | + | |
| 2315 | + ob_start(); // Start buffering; | |
| 2316 | + | |
| 2317 | + $extra_fields = unserialize( $field->extra_fields ); | |
| 2318 | + | |
| 2319 | + if ( $extra_fields['date_format'] == '' ) { | |
| 2320 | + $extra_fields['date_format'] = 'yy-mm-dd'; | |
| 2321 | + } | |
| 2322 | + | |
| 2323 | + $date_format = $extra_fields['date_format']; | |
| 2324 | + $jquery_date_format = $date_format; | |
| 2325 | + | |
| 2326 | + // check if we need to change the format or not | |
| 2327 | + $date_format_len = strlen( str_replace( ' ', '', $date_format ) ); | |
| 2328 | + if ( $date_format_len > 5 ) {// if greater then 5 then it's the old style format. | |
| 2329 | + | |
| 2330 | + $search = array( 'dd', 'd', 'DD', 'mm', 'm', 'MM', 'yy' ); //jQuery UI datepicker format | |
| 2331 | + $replace = array( 'd', 'j', 'l', 'm', 'n', 'F', 'Y' );//PHP date format | |
| 2332 | + | |
| 2333 | + $date_format = str_replace( $search, $replace, $date_format ); | |
| 2334 | + } else { | |
| 2335 | + $jquery_date_format = uwp_date_format_php_to_jqueryui( $jquery_date_format ); | |
| 2336 | + } | |
| 2337 | + | |
| 2338 | + if ( ! empty( $value ) && ! is_string( $value ) ) { | |
| 2339 | + $value = date( 'Y-m-d', $value ); | |
| 2340 | + } | |
| 2341 | + | |
| 2342 | + if ( $value == '0000-00-00' ) { | |
| 2343 | + $value = ''; | |
| 2344 | + }//if date not set, then mark it empty | |
| 2345 | + $value = uwp_date( $value, 'Y-m-d', $date_format ); | |
| 2346 | + $site_title = uwp_get_form_label( $field ); | |
| 2347 | + | |
| 2348 | + // bootstrap | |
| 2349 | + if ( $design_style ) { | |
| 2350 | + // flatpickr attributes | |
| 2351 | + $extra_attributes['data-alt-input'] = 'true'; | |
| 2352 | + $extra_attributes['data-alt-format'] = $date_format; | |
| 2353 | + $extra_attributes['data-date-format'] = 'Y-m-d'; | |
| 2354 | + | |
| 2355 | + if ( 'dob' == $field->htmlvar_name ) { | |
| 2356 | + $extra_attributes['data-max-date'] = 'today'; | |
| 1241 | 2357 | } |
| 2358 | + | |
| 2359 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 2360 | + | |
| 2361 | + echo aui()->input( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2362 | + array( | |
| 2363 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 2364 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 2365 | + 'required' => ! empty( $field->is_required ) ? true : false, | |
| 2366 | + 'label' => wp_kses_post( $site_title . $required ), | |
| 2367 | + 'label_show' => true, | |
| 2368 | + 'label_type' => 'hidden', | |
| 2369 | + 'type' => 'datepicker', | |
| 2370 | + 'title' => esc_html( $site_title ), | |
| 2371 | + 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ), | |
| 2372 | + 'class' => '', | |
| 2373 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 2374 | + 'value' => esc_attr( $value ), | |
| 2375 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 2376 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 2377 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 2378 | + 'extra_attributes' => $extra_attributes, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2379 | + ) | |
| 2380 | + ); | |
| 2381 | + } else { | |
| 2382 | + ?> | |
| 2383 | + <script type="text/javascript"> | |
| 2384 | + | |
| 2385 | + jQuery(function () { | |
| 2386 | + jQuery("#<?php echo esc_attr( $field->htmlvar_name ); ?>").datepicker({ | |
| 2387 | + changeMonth: true, changeYear: true | |
| 2388 | + <?php | |
| 2389 | + if ( $field->htmlvar_name == 'dob' ) { | |
| 2390 | + echo ", yearRange: '1900:+0'"; | |
| 2391 | + } else { | |
| 2392 | + echo ", yearRange: '1900:2050'"; | |
| 2393 | + } | |
| 2394 | + ?> | |
| 2395 | + <?php echo apply_filters( "uwp_datepicker_extra_{$field->htmlvar_name}", '' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>}); | |
| 2396 | + | |
| 2397 | + jQuery("#<?php echo esc_attr( $field->htmlvar_name ); ?>").datepicker("option", "dateFormat", '<?php echo esc_attr( $jquery_date_format ); ?>'); | |
| 2398 | + | |
| 2399 | + <?php if ( ! empty( $value ) ) { ?> | |
| 2400 | + var parsedDate = jQuery.datepicker.parseDate('yy-mm-dd', '<?php echo esc_attr( $value ); ?>'); | |
| 2401 | + jQuery("#<?php echo esc_attr( $field->htmlvar_name ); ?>").datepicker("setDate", parsedDate); | |
| 2402 | + <?php } ?> | |
| 2403 | + | |
| 2404 | + }); | |
| 2405 | + | |
| 2406 | + </script> | |
| 2407 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 2408 | + class=" | |
| 2409 | + <?php | |
| 2410 | + if ( $field->is_required ) { | |
| 2411 | + echo 'required_field'; | |
| 2412 | + } | |
| 2413 | + ?> | |
| 2414 | + clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 2415 | + | |
| 2416 | + <?php | |
| 2417 | + | |
| 2418 | + if ( ! is_admin() ) { | |
| 2419 | + ?> | |
| 2420 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 2421 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 2422 | + <?php | |
| 2423 | + if ( $field->is_required ) { | |
| 2424 | + echo '<span>*</span>'; | |
| 2425 | + } | |
| 2426 | + ?> | |
| 2427 | + </label> | |
| 2428 | + <?php } ?> | |
| 2429 | + | |
| 2430 | + <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 2431 | + id="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 2432 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 2433 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 2434 | + type="text" | |
| 2435 | + <?php | |
| 2436 | + if ( $field->is_required == 1 ) { | |
| 2437 | + echo 'required="required"'; | |
| 2438 | + } | |
| 2439 | + ?> | |
| 2440 | + value="<?php echo esc_attr( $value ); ?>" | |
| 2441 | + class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"/> | |
| 2442 | + | |
| 2443 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 2444 | + <?php if ( $field->is_required ) { ?> | |
| 2445 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 2446 | + <?php } ?> | |
| 2447 | + </div> | |
| 2448 | + | |
| 2449 | + <?php | |
| 1242 | 2450 | } |
| 1243 | - } | |
| 1244 | 2451 | |
| 1245 | - if (is_admin()) { | |
| 1246 | - if ($user_id == get_current_user_id()) { | |
| 1247 | - $profile_url = admin_url( 'profile.php' ); | |
| 1248 | - } else { | |
| 1249 | - $profile_url = admin_url( 'user-edit.php?user_id='.$user_id ); | |
| 1250 | - } | |
| 1251 | - } else { | |
| 1252 | - $profile_url = uwp_build_profile_tab_url($user_id); | |
| 1253 | - } | |
| 1254 | - return $profile_url; | |
| 2452 | + $html = ob_get_clean(); | |
| 2453 | + } | |
| 1255 | 2454 | |
| 1256 | - } | |
| 2455 | + return $html; | |
| 2456 | + } | |
| 1257 | 2457 | |
| 1258 | - /** | |
| 1259 | - * Saves UsersWP related user custom fields. | |
| 1260 | - * | |
| 1261 | - * @since 1.0.0 | |
| 1262 | - * @package userswp | |
| 1263 | - * | |
| 1264 | - * @param int $user_id User ID. | |
| 1265 | - * @param array $data Result array. | |
| 1266 | - * @param string $type Form type. | |
| 1267 | - * | |
| 1268 | - * @return bool True when success. False when failure. | |
| 1269 | - */ | |
| 1270 | - public function uwp_save_user_extra_fields($user_id, $data, $type) { | |
| 2458 | + /** | |
| 2459 | + * Form field template for time field type. | |
| 2460 | + * | |
| 2461 | + * @param string $html Form field html | |
| 2462 | + * @param object $field Field info. | |
| 2463 | + * @param string $value Form field default value. | |
| 2464 | + * @param string $form_type Form type | |
| 2465 | + * | |
| 2466 | + * @return string Modified form field html. | |
| 2467 | + * @package userswp | |
| 2468 | + * | |
| 2469 | + * @since 1.0.0 | |
| 2470 | + */ | |
| 2471 | + public function form_input_time( $html, $field, $value, $form_type ) { | |
| 1271 | 2472 | |
| 1272 | - if (empty($user_id) || empty($data) || empty($type)) { | |
| 1273 | - return false; | |
| 1274 | - } | |
| 2473 | + if ( has_filter( "uwp_form_input_html_time_{$field->htmlvar_name}" ) ) { | |
| 1275 | 2474 | |
| 1276 | - // custom user fields not applicable for login and forgot | |
| 1277 | - if ($type == 'login' || $type == 'forgot') { | |
| 1278 | - return true; | |
| 1279 | - } | |
| 1280 | - | |
| 2475 | + $html = apply_filters( "uwp_form_input_html_time_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 2476 | + } | |
| 1281 | 2477 | |
| 1282 | - if ($type == 'account' || $type == 'register') { | |
| 1283 | - if (isset($data['password'])) { | |
| 1284 | - unset($data['password']); | |
| 1285 | - } | |
| 1286 | - } | |
| 2478 | + // If no html then we run the standard output. | |
| 2479 | + if ( empty( $html ) ) { | |
| 1287 | 2480 | |
| 1288 | - if ($type == 'register') { | |
| 1289 | - if (isset($data['uwp_account_username'])) { | |
| 1290 | - unset($data['uwp_account_username']); | |
| 1291 | - } | |
| 1292 | - if (isset($data['uwp_account_email'])) { | |
| 1293 | - unset($data['uwp_account_email']); | |
| 1294 | - } | |
| 1295 | - if (isset($data['uwp_account_display_name'])) { | |
| 1296 | - unset($data['uwp_account_display_name']); | |
| 1297 | - } | |
| 1298 | - if (isset($data['uwp_account_first_name'])) { | |
| 1299 | - unset($data['uwp_account_first_name']); | |
| 1300 | - } | |
| 1301 | - if (isset($data['uwp_account_last_name'])) { | |
| 1302 | - unset($data['uwp_account_last_name']); | |
| 1303 | - } | |
| 1304 | - if (isset($data['uwp_account_bio'])) { | |
| 1305 | - unset($data['uwp_account_bio']); | |
| 1306 | - } | |
| 1307 | - } | |
| 2481 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 2482 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 2483 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 2484 | + $bs_form_control = $design_style ? 'form-control bg-white' : ''; | |
| 2485 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 2486 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 1308 | 2487 | |
| 1309 | - if (empty($data)) { | |
| 1310 | - // no extra fields. so just return | |
| 1311 | - return true; | |
| 1312 | - } else { | |
| 1313 | - foreach($data as $key => $value) { | |
| 1314 | - uwp_update_usermeta($user_id, $key, $value); | |
| 1315 | - } | |
| 1316 | - return true; | |
| 1317 | - } | |
| 1318 | - } | |
| 2488 | + ob_start(); // Start buffering; | |
| 1319 | 2489 | |
| 1320 | - /** | |
| 1321 | - * Logs the error message. | |
| 1322 | - * | |
| 1323 | - * @since 1.0.0 | |
| 1324 | - * @package userswp | |
| 1325 | - * | |
| 1326 | - * @param array|object|string $log Error message. | |
| 1327 | - * | |
| 1328 | - * @return void | |
| 1329 | - */ | |
| 1330 | - public static function uwp_error_log($log){ | |
| 2490 | + if ( $value != '' ) { | |
| 2491 | + $value = date( 'H:i', strtotime( $value ) ); | |
| 2492 | + } | |
| 1331 | 2493 | |
| 1332 | - $should_log = apply_filters( 'uwp_log_errors', WP_DEBUG); | |
| 1333 | - if ( true === $should_log ) { | |
| 1334 | - if ( is_array( $log ) || is_object( $log ) ) { | |
| 1335 | - error_log( print_r( $log, true ) ); | |
| 1336 | - } else { | |
| 1337 | - error_log( $log ); | |
| 1338 | - } | |
| 1339 | - } | |
| 1340 | - } | |
| 2494 | + // flatpickr attributes | |
| 2495 | + $extra_attributes['data-enable-time'] = 'true'; | |
| 2496 | + $extra_attributes['data-no-calendar'] = 'true'; | |
| 2497 | + $extra_attributes['data-date-format'] = 'H:i'; | |
| 2498 | + $site_title = uwp_get_form_label( $field ); | |
| 2499 | + $label_type = is_admin() ? '' : 'top'; | |
| 1341 | 2500 | |
| 1342 | - /** | |
| 1343 | - * | |
| 1344 | - * | |
| 1345 | - * @since 1.0.0 | |
| 1346 | - * @since 1.0.12 Unlink file. | |
| 1347 | - * @package userswp | |
| 1348 | - * @return void | |
| 1349 | - */ | |
| 1350 | - public function uwp_upload_file_remove() { | |
| 2501 | + if ( $design_style ) { | |
| 2502 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 1351 | 2503 | |
| 1352 | - $htmlvar = strip_tags(esc_sql($_POST['htmlvar'])); | |
| 1353 | - $user_id = (int) strip_tags(esc_sql($_POST['uid'])); | |
| 1354 | - $permission = false; | |
| 1355 | - if ($user_id == get_current_user_id()) { | |
| 1356 | - $permission = true; | |
| 1357 | - } else { | |
| 1358 | - if (current_user_can('manage_options')) { | |
| 1359 | - $permission = true; | |
| 1360 | - } | |
| 1361 | - } | |
| 1362 | - if ($permission) { | |
| 1363 | - // Remove file | |
| 1364 | - if ($htmlvar == "uwp_account_banner_thumb") { | |
| 1365 | - $file = uwp_get_usermeta($user_id, 'uwp_account_banner_thumb'); | |
| 1366 | - $type = 'banner'; | |
| 1367 | - } elseif ($htmlvar == "uwp_account_avatar_thumb") { | |
| 1368 | - $file = uwp_get_usermeta($user_id, 'uwp_account_avatar_thumb'); | |
| 1369 | - $type = 'avatar'; | |
| 2504 | + echo aui()->input( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2505 | + array( | |
| 2506 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 2507 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 2508 | + 'required' => ! empty( $field->is_required ) ? true : false, | |
| 2509 | + 'label' => wp_kses_post( $site_title . $required ), | |
| 2510 | + 'label_show' => true, | |
| 2511 | + 'label_type' => esc_attr( $label_type ), | |
| 2512 | + 'type' => 'timepicker', | |
| 2513 | + 'title' => esc_html( $site_title ), | |
| 2514 | + 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ), | |
| 2515 | + 'class' => '', | |
| 2516 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 2517 | + 'value' => esc_attr( $value ), | |
| 2518 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 2519 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 2520 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 2521 | + 'extra_attributes' => $extra_attributes, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2522 | + 'input_group_right' => '<div class="input-group-text px-2 bg-transparent border-0x" onclick="jQuery(this).parent().parent().find(\'input\').val(\'\');"><i class="fas fa-times uwp-search-input-label-clear text-muted c-pointer" title="' . esc_attr__( 'Clear field', 'uwp-search' ) . '" ></i></div>', | |
| 2523 | + ) | |
| 2524 | + ); | |
| 1370 | 2525 | } else { |
| 1371 | - $file = ''; | |
| 1372 | - $type = ''; | |
| 2526 | + ?> | |
| 2527 | + <script type="text/javascript"> | |
| 2528 | + jQuery(document).ready(function () { | |
| 2529 | + jQuery('#<?php echo esc_attr( $field->htmlvar_name ); ?>').timepicker({ | |
| 2530 | + showPeriod: true, | |
| 2531 | + showLeadingZero: true | |
| 2532 | + }); | |
| 2533 | + }); | |
| 2534 | + </script> | |
| 2535 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 2536 | + class=" | |
| 2537 | + <?php | |
| 2538 | + if ( $field->is_required ) { | |
| 2539 | + echo 'required_field'; | |
| 2540 | + } | |
| 2541 | + ?> | |
| 2542 | + clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 2543 | + | |
| 2544 | + <?php | |
| 2545 | + $site_title = uwp_get_form_label( $field ); | |
| 2546 | + if ( ! is_admin() ) { | |
| 2547 | + ?> | |
| 2548 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 2549 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 2550 | + <?php | |
| 2551 | + if ( $field->is_required ) { | |
| 2552 | + echo '<span>*</span>'; | |
| 2553 | + } | |
| 2554 | + ?> | |
| 2555 | + </label> | |
| 2556 | + <?php } ?> | |
| 2557 | + | |
| 2558 | + <input readonly="readonly" name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 2559 | + id="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 2560 | + value="<?php echo esc_attr( $value ); ?>" | |
| 2561 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 2562 | + type="text" | |
| 2563 | + class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"/> | |
| 2564 | + | |
| 2565 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 2566 | + <?php if ( $field->is_required ) { ?> | |
| 2567 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 2568 | + <?php } ?> | |
| 2569 | + </div> | |
| 2570 | + <?php | |
| 1373 | 2571 | } |
| 2572 | + $html = ob_get_clean(); | |
| 2573 | + } | |
| 1374 | 2574 | |
| 1375 | - uwp_update_usermeta($user_id, $htmlvar, ''); | |
| 2575 | + return $html; | |
| 2576 | + } | |
| 1376 | 2577 | |
| 1377 | - if ($file) { | |
| 1378 | - $uploads = wp_upload_dir(); | |
| 1379 | - $upload_path = $uploads['basedir']; | |
| 1380 | - $unlink_file = untrailingslashit($upload_path) . '/' . ltrim($file, '/'); | |
| 2578 | + /** | |
| 2579 | + * Form field template for select field type. | |
| 2580 | + * | |
| 2581 | + * @param string $html Form field html | |
| 2582 | + * @param object $field Field info. | |
| 2583 | + * @param string $value Form field default value. | |
| 2584 | + * @param string $form_type Form type | |
| 2585 | + * | |
| 2586 | + * @return string Modified form field html. | |
| 2587 | + * @package userswp | |
| 2588 | + * | |
| 2589 | + * @since 1.0.0 | |
| 2590 | + */ | |
| 2591 | + public function form_input_select( $html, $field, $value, $form_type ) { | |
| 1381 | 2592 | |
| 1382 | - if (is_file($unlink_file) && file_exists($unlink_file)) { | |
| 1383 | - @unlink($unlink_file); | |
| 1384 | - $unlink_ori_file = str_replace('_uwp_'.$type.'_thumb'.'.', '.', $unlink_file); | |
| 1385 | - if (is_file($unlink_ori_file) && file_exists($unlink_ori_file)) { | |
| 1386 | - @unlink($unlink_ori_file); | |
| 2593 | + // Check if there is a field specific filter. | |
| 2594 | + if ( has_filter( "uwp_form_input_html_select_{$field->htmlvar_name}" ) ) { | |
| 2595 | + $html = apply_filters( "uwp_form_input_html_select_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 2596 | + } | |
| 2597 | + | |
| 2598 | + // Check if there is a field type specific filter. | |
| 2599 | + if ( has_filter( "uwp_form_input_html_select_{$field->field_type_key}" ) ) { | |
| 2600 | + $html = apply_filters( "uwp_form_input_html_select_{$field->field_type_key}", $html, $field, $value, $form_type ); | |
| 2601 | + } | |
| 2602 | + | |
| 2603 | + // If no html then we run the standard output. | |
| 2604 | + if ( empty( $html ) ) { | |
| 2605 | + | |
| 2606 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 2607 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 2608 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 2609 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 2610 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 2611 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 2612 | + | |
| 2613 | + ob_start(); // Start buffering; | |
| 2614 | + $option_values_arr = uwp_string_values_to_options( $field->option_values, true ); | |
| 2615 | + $site_title = uwp_get_form_label( $field ); | |
| 2616 | + | |
| 2617 | + // bootstrap | |
| 2618 | + if ( $design_style ) { | |
| 2619 | + | |
| 2620 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 2621 | + | |
| 2622 | + echo aui()->select( | |
| 2623 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2624 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 2625 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 2626 | + 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ), | |
| 2627 | + 'title' => esc_html( $site_title ), | |
| 2628 | + 'value' => esc_attr( $value ), | |
| 2629 | + 'required' => (bool) $field->is_required, | |
| 2630 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 2631 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 2632 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 2633 | + 'label' => wp_kses_post( $site_title . $required ), | |
| 2634 | + 'options' => $option_values_arr, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2635 | + 'select2' => true, | |
| 2636 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 2637 | + ) | |
| 2638 | + ); | |
| 2639 | + } else { | |
| 2640 | + ?> | |
| 2641 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 2642 | + class=" | |
| 2643 | + <?php | |
| 2644 | + if ( $field->is_required ) { | |
| 2645 | + echo 'required_field'; | |
| 1387 | 2646 | } |
| 1388 | - } | |
| 2647 | + ?> | |
| 2648 | + uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 2649 | + | |
| 2650 | + <?php | |
| 2651 | + if ( ! is_admin() ) { | |
| 2652 | + ?> | |
| 2653 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 2654 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 2655 | + <?php | |
| 2656 | + if ( $field->is_required ) { | |
| 2657 | + echo '<span>*</span>'; | |
| 2658 | + } | |
| 2659 | + ?> | |
| 2660 | + </label> | |
| 2661 | + <?php } ?> | |
| 2662 | + | |
| 2663 | + <?php | |
| 2664 | + | |
| 2665 | + $select_options = ''; | |
| 2666 | + if ( ! empty( $option_values_arr ) ) { | |
| 2667 | + foreach ( $option_values_arr as $option_row ) { | |
| 2668 | + if ( isset( $option_row['optgroup'] ) && ( $option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end' ) ) { | |
| 2669 | + $option_label = isset( $option_row['label'] ) ? $option_row['label'] : ''; | |
| 2670 | + | |
| 2671 | + $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; | |
| 2672 | + } else { | |
| 2673 | + $option_label = isset( $option_row['label'] ) ? $option_row['label'] : ''; | |
| 2674 | + $option_value = isset( $option_row['value'] ) ? $option_row['value'] : ''; | |
| 2675 | + $selected = $option_value == $value ? 'selected="selected"' : ''; | |
| 2676 | + | |
| 2677 | + $select_options .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . '>' . $option_label . '</option>'; | |
| 2678 | + } | |
| 2679 | + } | |
| 2680 | + } | |
| 2681 | + ?> | |
| 2682 | + <select name="<?php echo esc_attr( $field->htmlvar_name ); ?>" id="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 2683 | + class="uwp_textfield aui-select2 <?php echo esc_attr( $bs_form_control ); ?>" | |
| 2684 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 2685 | + data-placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 2686 | + ><?php echo $select_options; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> | |
| 2687 | + </select> | |
| 2688 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 2689 | + <?php if ( $field->is_required ) { ?> | |
| 2690 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 2691 | + <?php } ?> | |
| 2692 | + </div> | |
| 2693 | + | |
| 2694 | + <?php | |
| 1389 | 2695 | } |
| 1390 | - } | |
| 1391 | - die(); | |
| 1392 | - } | |
| 1393 | - | |
| 1394 | - | |
| 1395 | - /** | |
| 1396 | - * Form field template for datepicker field type. | |
| 1397 | - * | |
| 1398 | - * @since 1.0.0 | |
| 1399 | - * @package userswp | |
| 1400 | - * | |
| 1401 | - * @param string $html Form field html | |
| 1402 | - * @param object $field Field info. | |
| 1403 | - * @param string $value Form field default value. | |
| 1404 | - * @param string $form_type Form type | |
| 1405 | - * | |
| 1406 | - * @return string Modified form field html. | |
| 1407 | - */ | |
| 1408 | - public function uwp_form_input_datepicker($html, $field, $value, $form_type){ | |
| 2696 | + $html = ob_get_clean(); | |
| 2697 | + } | |
| 1409 | 2698 | |
| 1410 | - // Check if there is a field specific filter. | |
| 1411 | - if(has_filter("uwp_form_input_html_datepicker_{$field->htmlvar_name}")){ | |
| 1412 | - $html = apply_filters("uwp_form_input_html_datepicker_{$field->htmlvar_name}", $html, $field, $value, $form_type); | |
| 1413 | - } | |
| 2699 | + return $html; | |
| 2700 | + } | |
| 1414 | 2701 | |
| 1415 | - // If no html then we run the standard output. | |
| 1416 | - if(empty($html)) { | |
| 2702 | + /** | |
| 2703 | + * Form field template for multiselect field type. | |
| 2704 | + * | |
| 2705 | + * @param string $html Form field html | |
| 2706 | + * @param object $field Field info. | |
| 2707 | + * @param string $value Form field default value. | |
| 2708 | + * @param string $form_type Form type | |
| 2709 | + * | |
| 2710 | + * @return string Modified form field html. | |
| 2711 | + * @package userswp | |
| 2712 | + * | |
| 2713 | + * @since 1.0.0 | |
| 2714 | + */ | |
| 2715 | + public function form_input_multiselect( $html, $field, $value, $form_type ) { | |
| 1417 | 2716 | |
| 1418 | - ob_start(); // Start buffering; | |
| 2717 | + // Check if there is a field specific filter. | |
| 2718 | + if ( has_filter( "uwp_form_input_html_multiselect_{$field->htmlvar_name}" ) ) { | |
| 2719 | + $html = apply_filters( "uwp_form_input_html_multiselect_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 2720 | + } | |
| 1419 | 2721 | |
| 1420 | - $extra_fields = unserialize($field->extra_fields); | |
| 2722 | + if ( empty( $html ) ) { | |
| 1421 | 2723 | |
| 1422 | - if ($extra_fields['date_format'] == '') | |
| 1423 | - $extra_fields['date_format'] = 'yy-mm-dd'; | |
| 2724 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 2725 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 2726 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 2727 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 2728 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 2729 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 1424 | 2730 | |
| 1425 | - $date_format = $extra_fields['date_format']; | |
| 1426 | - $jquery_date_format = $date_format; | |
| 2731 | + ob_start(); // Start buffering; | |
| 1427 | 2732 | |
| 1428 | - if (!empty($value) && !is_string($value)) { | |
| 1429 | - $value = date('Y-m-d', $value); | |
| 1430 | - } | |
| 2733 | + $multi_display = 'select'; | |
| 2734 | + if ( ! empty( $field->extra_fields ) ) { | |
| 2735 | + $multi_display = unserialize( $field->extra_fields ); | |
| 2736 | + } | |
| 1431 | 2737 | |
| 2738 | + $option_values_arr = uwp_string_values_to_options( $field->option_values, true ); | |
| 2739 | + $site_title = uwp_get_form_label( $field ); | |
| 2740 | + $value = is_array( $value ) ? $value : esc_attr( $value ); | |
| 1432 | 2741 | |
| 1433 | - // check if we need to change the format or not | |
| 1434 | - $date_format_len = strlen(str_replace(' ', '', $date_format)); | |
| 1435 | - if($date_format_len>5){// if greater then 5 then it's the old style format. | |
| 2742 | + // bootstrap | |
| 2743 | + if ( $design_style ) { | |
| 1436 | 2744 | |
| 1437 | - $search = array('dd','d','DD','mm','m','MM','yy'); //jQuery UI datepicker format | |
| 1438 | - $replace = array('d','j','l','m','n','F','Y');//PHP date format | |
| 2745 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 1439 | 2746 | |
| 1440 | - $date_format = str_replace($search, $replace, $date_format); | |
| 1441 | - }else{ | |
| 1442 | - $jquery_date_format = uwp_date_format_php_to_jqueryui( $jquery_date_format ); | |
| 1443 | - } | |
| 1444 | - if($value=='0000-00-00'){$value='';}//if date not set, then mark it empty | |
| 1445 | - $value = uwp_date($value, 'Y-m-d', $date_format); | |
| 1446 | - ?> | |
| 1447 | - <script type="text/javascript"> | |
| 2747 | + echo aui()->select( | |
| 2748 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2749 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 2750 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 2751 | + 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ), | |
| 2752 | + 'title' => esc_html( $site_title ), | |
| 2753 | + 'value' => $value, | |
| 2754 | + 'required' => (bool) $field->is_required, | |
| 2755 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 2756 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 2757 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 2758 | + 'label' => wp_kses_post( $site_title . $required ), | |
| 2759 | + 'options' => $option_values_arr, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2760 | + 'select2' => true, | |
| 2761 | + 'multiple' => true, | |
| 2762 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 2763 | + ) | |
| 2764 | + ); | |
| 2765 | + } else { | |
| 2766 | + ?> | |
| 2767 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 2768 | + class=" | |
| 2769 | + <?php | |
| 2770 | + if ( $field->is_required ) { | |
| 2771 | + echo 'required_field'; | |
| 2772 | + } | |
| 2773 | + ?> | |
| 2774 | + uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 1448 | 2775 | |
| 1449 | - jQuery(function () { | |
| 2776 | + <?php | |
| 2777 | + if ( ! is_admin() ) { | |
| 2778 | + ?> | |
| 2779 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 2780 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 2781 | + <?php | |
| 2782 | + if ( $field->is_required ) { | |
| 2783 | + echo '<span>*</span>'; | |
| 2784 | + } | |
| 2785 | + ?> | |
| 2786 | + </label> | |
| 2787 | + <?php } ?> | |
| 1450 | 2788 | |
| 1451 | - jQuery("#<?php echo $field->htmlvar_name;?>").datepicker({changeMonth: true, changeYear: true | |
| 1452 | - <?php if($field->htmlvar_name == 'uwp_account_dob'){ echo ", yearRange: '1900:+0'"; } else { echo ", yearRange: '1900:2050'"; }?> | |
| 1453 | - <?php echo apply_filters("uwp_datepicker_extra_{$field->htmlvar_name}",'');?>}); | |
| 2789 | + <input type="hidden" name="<?php echo esc_attr( $field->htmlvar_name ); ?>" value=""/> | |
| 2790 | + <?php if ( $multi_display == 'select' ) { ?> | |
| 2791 | + <div class="uwp_multiselect_list"> | |
| 2792 | + <select name="<?php echo esc_attr( $field->htmlvar_name ); ?>[]" | |
| 2793 | + id="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 2794 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 2795 | + data-placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 2796 | + class="aui-select2 <?php echo esc_attr( $bs_form_control ); ?>" | |
| 2797 | + > | |
| 2798 | + <?php | |
| 2799 | + } else { | |
| 2800 | + ?> | |
| 2801 | + <ul class="uwp_multi_choice"> | |
| 2802 | + <?php | |
| 2803 | + } | |
| 1454 | 2804 | |
| 1455 | - jQuery("#<?php echo $field->htmlvar_name;?>").datepicker("option", "dateFormat", '<?php echo $jquery_date_format;?>'); | |
| 2805 | + $option_values_arr = uwp_string_values_to_options( $field->option_values, true ); | |
| 2806 | + $select_options = ''; | |
| 2807 | + if ( ! empty( $option_values_arr ) ) { | |
| 2808 | + foreach ( $option_values_arr as $option_row ) { | |
| 2809 | + if ( isset( $option_row['optgroup'] ) && ( $option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end' ) ) { | |
| 2810 | + $option_label = isset( $option_row['label'] ) ? $option_row['label'] : ''; | |
| 1456 | 2811 | |
| 1457 | - <?php if(!empty($value)){?> | |
| 1458 | - var parsedDate = jQuery.datepicker.parseDate('yy-mm-dd', '<?php echo $value;?>'); | |
| 1459 | - jQuery("#<?php echo $field->htmlvar_name;?>").datepicker("setDate", parsedDate); | |
| 1460 | - <?php } ?> | |
| 2812 | + if ( $multi_display == 'select' ) { | |
| 2813 | + $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; | |
| 2814 | + } else { | |
| 2815 | + $select_options .= $option_row['optgroup'] == 'start' ? '<li>' . $option_label . '</li>' : ''; | |
| 2816 | + } | |
| 2817 | + } else { | |
| 2818 | + $option_label = isset( $option_row['label'] ) ? $option_row['label'] : ''; | |
| 2819 | + $option_value = isset( $option_row['value'] ) ? $option_row['value'] : ''; | |
| 2820 | + $selected = $option_value == $value ? 'selected="selected"' : ''; | |
| 2821 | + $checked = ''; | |
| 1461 | 2822 | |
| 1462 | - }); | |
| 2823 | + if ( ( ! is_array( $value ) && trim( $value ) != '' ) || ( is_array( $value ) && ! empty( $value ) ) ) { | |
| 2824 | + if ( ! is_array( $value ) ) { | |
| 2825 | + $value_array = explode( ',', $value ); | |
| 2826 | + } else { | |
| 2827 | + $value_array = $value; | |
| 2828 | + } | |
| 1463 | 2829 | |
| 1464 | - </script> | |
| 1465 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 1466 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row clearfix uwp_clear uwp-fieldset-details"> | |
| 2830 | + if ( is_array( $value_array ) ) { | |
| 2831 | + if ( in_array( $option_value, $value_array ) ) { | |
| 2832 | + $selected = 'selected="selected"'; | |
| 2833 | + $checked = 'checked="checked"'; | |
| 2834 | + } | |
| 2835 | + } | |
| 2836 | + } | |
| 1467 | 2837 | |
| 2838 | + if ( $multi_display == 'select' ) { | |
| 2839 | + $select_options .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . '>' . $option_label . '</option>'; | |
| 2840 | + } else { | |
| 2841 | + $select_options .= '<li><input name="' . $field->name . '[]" ' . $checked . ' value="' . esc_attr( $option_value ) . '" class="uwp-' . $multi_display . '" type="' . $multi_display . '" /> ' . $option_label . ' </li>'; | |
| 2842 | + } | |
| 2843 | + } | |
| 2844 | + } | |
| 2845 | + } | |
| 2846 | + echo $select_options; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2847 | + | |
| 2848 | + if ( $multi_display == 'select' ) { | |
| 2849 | + | |
| 2850 | + ?> | |
| 2851 | + </select></div> | |
| 2852 | + <?php } else { ?> | |
| 2853 | + </ul> | |
| 2854 | + <?php } ?> | |
| 2855 | + <?php if ( $field->is_required ) { ?> | |
| 2856 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 2857 | + <?php } ?> | |
| 2858 | + </div> | |
| 2859 | + <?php | |
| 2860 | + } | |
| 2861 | + $html = ob_get_clean(); | |
| 2862 | + } | |
| 2863 | + | |
| 2864 | + return $html; | |
| 2865 | + } | |
| 2866 | + | |
| 2867 | + /** | |
| 2868 | + * Form field template for file field type. | |
| 2869 | + * | |
| 2870 | + * @param string $html Form field html | |
| 2871 | + * @param object $field Field info. | |
| 2872 | + * @param string $value Form field default value. | |
| 2873 | + * @param string $form_type Form type | |
| 2874 | + * | |
| 2875 | + * @return string Modified form field html. | |
| 2876 | + * @package userswp | |
| 2877 | + * | |
| 2878 | + * @since 1.0.0 | |
| 2879 | + */ | |
| 2880 | + public function form_input_file( $html, $field, $value, $form_type ) { | |
| 2881 | + | |
| 2882 | + $file_obj = new UsersWP_Files(); | |
| 2883 | + | |
| 2884 | + // Check if there is a field specific filter. | |
| 2885 | + if ( has_filter( "uwp_form_input_html_file_{$field->htmlvar_name}" ) ) { | |
| 2886 | + $html = apply_filters( "uwp_form_input_html_file_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 2887 | + } | |
| 2888 | + | |
| 2889 | + // If no html then we run the standard output. | |
| 2890 | + if ( empty( $html ) ) { | |
| 2891 | + | |
| 2892 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 2893 | + $wrap_class = isset( $field->css_class ) ? $field->css_class : ''; | |
| 2894 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 2895 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 2896 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 2897 | + | |
| 2898 | + ob_start(); // Start buffering; | |
| 2899 | + | |
| 2900 | + ?> | |
| 2901 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 2902 | + class=" | |
| 1468 | 2903 | <?php |
| 1469 | - $site_title = uwp_get_form_label($field); | |
| 1470 | - if (!is_admin()) { ?> | |
| 1471 | - <label> | |
| 1472 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 1473 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 1474 | - </label> | |
| 1475 | - <?php } ?> | |
| 2904 | + if ( $field->is_required ) { | |
| 2905 | + echo 'required_field'; | |
| 2906 | + } | |
| 2907 | + ?> | |
| 2908 | + uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group . $wrap_class ); ?>"> | |
| 1476 | 2909 | |
| 1477 | - <input name="<?php echo $field->htmlvar_name;?>" | |
| 1478 | - id="<?php echo $field->htmlvar_name;?>" | |
| 1479 | - placeholder="<?php echo $site_title; ?>" | |
| 1480 | - title="<?php echo $site_title; ?>" | |
| 1481 | - type="text" | |
| 1482 | - <?php if ($field->is_required == 1) { echo 'required="required"'; } ?> | |
| 1483 | - value="<?php echo esc_attr($value);?>" class="uwp_textfield"/> | |
| 2910 | + <?php | |
| 2911 | + $site_title = uwp_get_form_label( $field ); | |
| 2912 | + if ( ! is_admin() && ! wp_doing_ajax() ) { | |
| 2913 | + ?> | |
| 2914 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 2915 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 2916 | + <?php | |
| 2917 | + if ( $field->is_required ) { | |
| 2918 | + echo ' <span class="text-danger">*</span>'; | |
| 2919 | + } | |
| 2920 | + ?> | |
| 2921 | + </label> | |
| 2922 | + <?php } ?> | |
| 1484 | 2923 | |
| 1485 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 1486 | - <?php if ($field->is_required) { ?> | |
| 1487 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 1488 | - <?php } ?> | |
| 1489 | - </div> | |
| 2924 | + <?php echo $file_obj->file_upload_preview( $field, $value ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> | |
| 2925 | + <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 2926 | + class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>" | |
| 2927 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 2928 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 2929 | + <?php | |
| 2930 | + if ( $field->is_required == 1 ) { | |
| 2931 | + echo 'data-is-required="1"'; | |
| 2932 | + } | |
| 2933 | + if ( $field->is_required == 1 && ! $value ) { | |
| 2934 | + echo 'required="required"'; | |
| 2935 | + } | |
| 2936 | + ?> | |
| 2937 | + type="<?php echo esc_attr( $field->field_type ); ?>"> | |
| 2938 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 2939 | + <?php if ( $field->is_required ) { ?> | |
| 2940 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 2941 | + <?php } ?> | |
| 2942 | + </div> | |
| 1490 | 2943 | |
| 1491 | - <?php | |
| 1492 | - $html = ob_get_clean(); | |
| 1493 | - } | |
| 2944 | + <?php | |
| 2945 | + $html = ob_get_clean(); | |
| 2946 | + } | |
| 1494 | 2947 | |
| 1495 | - return $html; | |
| 1496 | - } | |
| 2948 | + return $html; | |
| 2949 | + } | |
| 1497 | 2950 | |
| 1498 | - /** | |
| 1499 | - * Form field template for time field type. | |
| 1500 | - * | |
| 1501 | - * @since 1.0.0 | |
| 1502 | - * @package userswp | |
| 1503 | - * | |
| 1504 | - * @param string $html Form field html | |
| 1505 | - * @param object $field Field info. | |
| 1506 | - * @param string $value Form field default value. | |
| 1507 | - * @param string $form_type Form type | |
| 1508 | - * | |
| 1509 | - * @return string Modified form field html. | |
| 1510 | - */ | |
| 1511 | - public function uwp_form_input_time($html, $field, $value, $form_type){ | |
| 2951 | + /** | |
| 2952 | + * Form field template for checkbox field type. | |
| 2953 | + * | |
| 2954 | + * @param string $html Form field html | |
| 2955 | + * @param object $field Field info. | |
| 2956 | + * @param string $value Form field default value. | |
| 2957 | + * @param string $form_type Form type | |
| 2958 | + * | |
| 2959 | + * @return string Modified form field html. | |
| 2960 | + * @package userswp | |
| 2961 | + * | |
| 2962 | + * @since 1.0.0 | |
| 2963 | + */ | |
| 2964 | + public function form_input_checkbox( $html, $field, $value, $form_type ) { | |
| 1512 | 2965 | |
| 1513 | - if(has_filter("uwp_form_input_html_time_{$field->htmlvar_name}")){ | |
| 2966 | + // Check if there is a field specific filter. | |
| 2967 | + if ( has_filter( "uwp_form_input_html_checkbox_{$field->htmlvar_name}" ) ) { | |
| 2968 | + $html = apply_filters( "uwp_form_input_html_checkbox_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 2969 | + } | |
| 1514 | 2970 | |
| 1515 | - $html = apply_filters("uwp_form_input_html_time_{$field->htmlvar_name}",$html, $field, $value, $form_type); | |
| 1516 | - } | |
| 2971 | + // If no html then we run the standard output. | |
| 2972 | + if ( empty( $html ) ) { | |
| 1517 | 2973 | |
| 1518 | - // If no html then we run the standard output. | |
| 1519 | - if(empty($html)) { | |
| 2974 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 2975 | + $bs_form_group = $design_style ? 'form-group mb-3 form-check' : ''; | |
| 2976 | + $bs_sr_only = $design_style ? 'form-check-label' : ''; | |
| 2977 | + $bs_form_control = $design_style ? 'form-check-input' : ''; | |
| 1520 | 2978 | |
| 1521 | - ob_start(); // Start buffering; | |
| 2979 | + ob_start(); // Start buffering; | |
| 2980 | + $site_title = uwp_get_form_label( $field ); | |
| 1522 | 2981 | |
| 1523 | - if ($value != '') | |
| 1524 | - $value = date('H:i', strtotime($value)); | |
| 1525 | - ?> | |
| 1526 | - <script type="text/javascript"> | |
| 1527 | - jQuery(document).ready(function () { | |
| 2982 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 2983 | + $id = wp_doing_ajax() ? $field->htmlvar_name . '_ajax' : $field->htmlvar_name; | |
| 1528 | 2984 | |
| 1529 | - jQuery('#<?php echo $field->htmlvar_name;?>').timepicker({ | |
| 1530 | - showPeriod: true, | |
| 1531 | - showLeadingZero: true | |
| 1532 | - }); | |
| 1533 | - }); | |
| 1534 | - </script> | |
| 1535 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 1536 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row clearfix uwp_clear uwp-fieldset-details"> | |
| 2985 | + $checked = $value == '1' ? true : false; | |
| 1537 | 2986 | |
| 1538 | - <?php | |
| 1539 | - $site_title = uwp_get_form_label($field); | |
| 1540 | - if (!is_admin()) { ?> | |
| 1541 | - <label> | |
| 1542 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 1543 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 1544 | - </label> | |
| 1545 | - <?php } ?> | |
| 2987 | + // bootstrap | |
| 2988 | + if ( $design_style ) { | |
| 2989 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 1546 | 2990 | |
| 1547 | - <input readonly="readonly" name="<?php echo $field->htmlvar_name;?>" | |
| 1548 | - id="<?php echo $field->htmlvar_name;?>" | |
| 1549 | - value="<?php echo esc_attr($value);?>" | |
| 1550 | - placeholder="<?php echo $site_title; ?>" | |
| 1551 | - type="text" | |
| 1552 | - class="uwp_textfield"/> | |
| 2991 | + echo '<input type="hidden" name="' . esc_attr( $field->htmlvar_name ) . '" id="checkbox_' . esc_attr( $id ) . '" value="0"/>'; | |
| 1553 | 2992 | |
| 1554 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 1555 | - <?php if ($field->is_required) { ?> | |
| 1556 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 1557 | - <?php } ?> | |
| 1558 | - </div> | |
| 1559 | - <?php | |
| 1560 | - $html = ob_get_clean(); | |
| 1561 | - } | |
| 2993 | + echo aui()->input( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2994 | + array( | |
| 2995 | + 'id' => esc_attr( $id ), | |
| 2996 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 2997 | + 'type' => 'checkbox', | |
| 2998 | + 'value' => '1', | |
| 2999 | + 'title' => esc_html( $site_title ), | |
| 3000 | + 'label' => wp_kses_post( $site_title . $required ), | |
| 3001 | + 'label_show' => true, | |
| 3002 | + 'required' => ! empty( $field->is_required ) ? true : false, | |
| 3003 | + 'checked' => (bool) $checked, | |
| 3004 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 3005 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 3006 | + 'validation_text' => ! empty( $field->is_required ) ? esc_attr__( stripslashes( $field->required_msg ), 'userswp' ) : '', | |
| 3007 | + ) | |
| 3008 | + ); | |
| 1562 | 3009 | |
| 1563 | - return $html; | |
| 1564 | - } | |
| 3010 | + } else { | |
| 3011 | + ?> | |
| 3012 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 3013 | + class=" | |
| 3014 | + <?php | |
| 3015 | + if ( $field->is_required ) { | |
| 3016 | + echo 'required_field'; | |
| 3017 | + } | |
| 3018 | + ?> | |
| 3019 | + uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 3020 | + <?php if ( ! empty( $design_style ) ) { ?> | |
| 3021 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 3022 | + <?php } ?> | |
| 3023 | + <input type="hidden" name="<?php echo esc_attr( $field->htmlvar_name ); ?>" value="0"/> | |
| 3024 | + <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3025 | + class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>" | |
| 3026 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 3027 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 3028 | + <?php | |
| 3029 | + if ( $field->is_required == 1 ) { | |
| 3030 | + echo 'required="required"'; | |
| 3031 | + } | |
| 3032 | + ?> | |
| 3033 | + <?php | |
| 3034 | + if ( $value == '1' ) { | |
| 3035 | + echo 'checked="checked"'; | |
| 3036 | + } | |
| 3037 | + ?> | |
| 3038 | + type="<?php echo esc_attr( $field->field_type ); ?>" | |
| 3039 | + value="1"> | |
| 3040 | + <?php | |
| 3041 | + echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; | |
| 3042 | + ?> | |
| 3043 | + <?php if ( ! empty( $design_style ) ) { ?> | |
| 3044 | + </label> | |
| 3045 | + <?php } ?> | |
| 3046 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 3047 | + <?php if ( $field->is_required ) { ?> | |
| 3048 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 3049 | + <?php } ?> | |
| 3050 | + </div> | |
| 1565 | 3051 | |
| 1566 | - /** | |
| 1567 | - * Form field template for select field type. | |
| 1568 | - * | |
| 1569 | - * @since 1.0.0 | |
| 1570 | - * @package userswp | |
| 1571 | - * | |
| 1572 | - * @param string $html Form field html | |
| 1573 | - * @param object $field Field info. | |
| 1574 | - * @param string $value Form field default value. | |
| 1575 | - * @param string $form_type Form type | |
| 1576 | - * | |
| 1577 | - * @return string Modified form field html. | |
| 1578 | - */ | |
| 1579 | - public function uwp_form_input_select($html, $field, $value, $form_type){ | |
| 3052 | + <?php | |
| 1580 | 3053 | |
| 1581 | - // Check if there is a field specific filter. | |
| 1582 | - if(has_filter("uwp_form_input_html_select_{$field->htmlvar_name}")){ | |
| 1583 | - $html = apply_filters("uwp_form_input_html_select_{$field->htmlvar_name}", $html, $field, $value, $form_type); | |
| 1584 | - } | |
| 3054 | + } | |
| 1585 | 3055 | |
| 1586 | - // Check if there is a field type specific filter. | |
| 1587 | - if(has_filter("uwp_form_input_html_select_{$field->field_type_key}")){ | |
| 1588 | - $html = apply_filters("uwp_form_input_html_select_{$field->field_type_key}", $html, $field, $value, $form_type); | |
| 1589 | - } | |
| 3056 | + $html = ob_get_clean(); | |
| 1590 | 3057 | |
| 1591 | - // If no html then we run the standard output. | |
| 1592 | - if(empty($html)) { | |
| 3058 | + } | |
| 1593 | 3059 | |
| 1594 | - ob_start(); // Start buffering; | |
| 3060 | + return $html; | |
| 3061 | + } | |
| 1595 | 3062 | |
| 1596 | - ?> | |
| 1597 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 1598 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row uwp_clear"> | |
| 3063 | + /** | |
| 3064 | + * Form field template for radio field type. | |
| 3065 | + * | |
| 3066 | + * @param string $html Form field html | |
| 3067 | + * @param object $field Field info. | |
| 3068 | + * @param string $value Form field default value. | |
| 3069 | + * @param string $form_type Form type | |
| 3070 | + * | |
| 3071 | + * @return string Modified form field html. | |
| 3072 | + * @package userswp | |
| 3073 | + * | |
| 3074 | + * @since 1.0.0 | |
| 3075 | + */ | |
| 3076 | + public function form_input_radio( $html, $field, $value, $form_type ) { | |
| 1599 | 3077 | |
| 1600 | - <?php | |
| 1601 | - $site_title = uwp_get_form_label($field); | |
| 1602 | - if (!is_admin()) { ?> | |
| 1603 | - <label> | |
| 1604 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 1605 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 1606 | - </label> | |
| 1607 | - <?php } ?> | |
| 3078 | + // Check if there is a field specific filter. | |
| 3079 | + if ( has_filter( "uwp_form_input_html_radio_{$field->htmlvar_name}" ) ) { | |
| 3080 | + $html = apply_filters( "uwp_form_input_html_radio_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 3081 | + } | |
| 1608 | 3082 | |
| 1609 | - <?php | |
| 1610 | - $option_values_arr = uwp_string_values_to_options($field->option_values, true); | |
| 1611 | - $select_options = ''; | |
| 1612 | - if (!empty($option_values_arr)) { | |
| 1613 | - foreach ($option_values_arr as $option_row) { | |
| 1614 | - if (isset($option_row['optgroup']) && ($option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end')) { | |
| 1615 | - $option_label = isset($option_row['label']) ? $option_row['label'] : ''; | |
| 3083 | + // If no html then we run the standard output. | |
| 3084 | + if ( empty( $html ) ) { | |
| 1616 | 3085 | |
| 1617 | - $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; | |
| 1618 | - } else { | |
| 1619 | - $option_label = isset($option_row['label']) ? $option_row['label'] : ''; | |
| 1620 | - $option_value = isset($option_row['value']) ? $option_row['value'] : ''; | |
| 1621 | - $selected = $option_value == $value ? 'selected="selected"' : ''; | |
| 3086 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 3087 | + $bs_form_group = $design_style ? 'form-group mb-3 form-check-inline' : ''; | |
| 3088 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 3089 | + $bs_label_class = $design_style ? 'form-check-label' : ''; | |
| 3090 | + $bs_form_control = $design_style ? 'form-check-input' : ''; | |
| 1622 | 3091 | |
| 1623 | - $select_options .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; | |
| 1624 | - } | |
| 3092 | + ob_start(); // Start buffering; | |
| 3093 | + | |
| 3094 | + if ( $design_style ) { | |
| 3095 | + | |
| 3096 | + $option_values_deep = uwp_string_values_to_options( $field->option_values, true ); | |
| 3097 | + $option_values = array(); | |
| 3098 | + if ( ! empty( $option_values_deep ) ) { | |
| 3099 | + foreach ( $option_values_deep as $option ) { | |
| 3100 | + $option_values[ $option['value'] ] = $option['label']; | |
| 3101 | + } | |
| 3102 | + } | |
| 3103 | + | |
| 3104 | + $site_title = uwp_get_form_label( $field ); | |
| 3105 | + | |
| 3106 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 3107 | + | |
| 3108 | + echo aui()->radio( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 3109 | + array( | |
| 3110 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 3111 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 3112 | + 'type' => 'radio', | |
| 3113 | + 'title' => esc_html( $site_title ), | |
| 3114 | + 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ), | |
| 3115 | + 'label_type' => 'top', | |
| 3116 | + 'class' => '', | |
| 3117 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 3118 | + 'value' => esc_attr( $value ), | |
| 3119 | + 'options' => $option_values, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 3120 | + ) | |
| 3121 | + ); | |
| 3122 | + | |
| 3123 | + } else { | |
| 3124 | + | |
| 3125 | + ?> | |
| 3126 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 3127 | + class=" | |
| 3128 | + <?php | |
| 3129 | + if ( $field->is_required ) { | |
| 3130 | + echo 'required_field'; | |
| 3131 | + } | |
| 3132 | + ?> | |
| 3133 | + uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 3134 | + | |
| 3135 | + <?php | |
| 3136 | + $site_title = uwp_get_form_label( $field ); | |
| 3137 | + if ( ! is_admin() ) { | |
| 3138 | + ?> | |
| 3139 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 3140 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 3141 | + <?php | |
| 3142 | + if ( $field->is_required ) { | |
| 3143 | + echo '<span>*</span>'; | |
| 3144 | + } | |
| 3145 | + ?> | |
| 3146 | + </label> | |
| 3147 | + <?php } ?> | |
| 3148 | + | |
| 3149 | + <?php | |
| 3150 | + if ( $field->option_values ) { | |
| 3151 | + $option_values = uwp_string_values_to_options( $field->option_values, true ); | |
| 3152 | + | |
| 3153 | + if ( ! empty( $option_values ) ) { | |
| 3154 | + $count = 0; | |
| 3155 | + foreach ( $option_values as $option_value ) { | |
| 3156 | + if ( empty( $option_value['optgroup'] ) ) { | |
| 3157 | + ++$count; | |
| 3158 | + if ( $count == 1 ) { | |
| 3159 | + $class = 'uwp-radio-first'; | |
| 3160 | + } else { | |
| 3161 | + $class = ''; | |
| 3162 | + } | |
| 3163 | + ?> | |
| 3164 | + <?php if ( ! empty( $design_style ) ) { ?> | |
| 3165 | + <label class="<?php echo esc_attr( $bs_label_class ); ?>"> | |
| 3166 | + <?php } else { ?> | |
| 3167 | + <span class="uwp-radios <?php echo esc_attr( $class ); ?>"> | |
| 3168 | + <?php } ?> | |
| 3169 | + <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3170 | + id="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3171 | + title="<?php echo esc_attr( $option_value['label'] ); ?>" | |
| 3172 | + <?php checked( $value, $option_value['value'] ); ?> | |
| 3173 | + <?php | |
| 3174 | + if ( $field->is_required == 1 ) { | |
| 3175 | + echo 'required="required"'; | |
| 3176 | + } | |
| 3177 | + ?> | |
| 3178 | + value="<?php echo esc_attr( $option_value['value'] ); ?>" | |
| 3179 | + class="uwp-radio <?php echo esc_attr( $bs_form_control ); ?>" type="radio"/> | |
| 3180 | + <?php echo esc_html( $option_value['label'] ); ?> | |
| 3181 | + <?php if ( ! empty( $design_style ) ) { ?> | |
| 3182 | + </label> | |
| 3183 | + <?php } else { ?> | |
| 3184 | + </span> | |
| 3185 | + <?php | |
| 3186 | + } | |
| 3187 | + } | |
| 3188 | + } | |
| 3189 | + } | |
| 3190 | + } | |
| 3191 | + ?> | |
| 3192 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 3193 | + <?php if ( $field->is_required ) { ?> | |
| 3194 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 3195 | + <?php } ?> | |
| 3196 | + </div> | |
| 3197 | + <?php | |
| 3198 | + } | |
| 3199 | + | |
| 3200 | + $html = ob_get_clean(); | |
| 3201 | + } | |
| 3202 | + | |
| 3203 | + return $html; | |
| 3204 | + } | |
| 3205 | + | |
| 3206 | + /** | |
| 3207 | + * Form field template for text field type. | |
| 3208 | + * | |
| 3209 | + * @param string $html Form field html | |
| 3210 | + * @param object $field Field info. | |
| 3211 | + * @param string $value Form field default value. | |
| 3212 | + * @param string $form_type Form type | |
| 3213 | + * | |
| 3214 | + * @return string Modified form field html. | |
| 3215 | + * @package userswp | |
| 3216 | + * | |
| 3217 | + * @since 1.0.0 | |
| 3218 | + */ | |
| 3219 | + public function form_input_text( $html, $field, $value, $form_type ) { | |
| 3220 | + | |
| 3221 | + // Check if there is a custom field specific filter. | |
| 3222 | + if ( has_filter( "uwp_form_input_text_{$field->htmlvar_name}" ) ) { | |
| 3223 | + $html = apply_filters( "uwp_form_input_text_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 3224 | + } | |
| 3225 | + | |
| 3226 | + // If no html then we run the standard output. | |
| 3227 | + if ( empty( $html ) ) { | |
| 3228 | + | |
| 3229 | + ob_start(); // Start buffering; | |
| 3230 | + | |
| 3231 | + $type = 'text'; | |
| 3232 | + $step = false; | |
| 3233 | + //number and float validation $validation_pattern | |
| 3234 | + if ( isset( $field->data_type ) && $field->data_type == 'INT' ) { | |
| 3235 | + $type = 'number'; | |
| 3236 | + } elseif ( isset( $field->data_type ) && $field->data_type == 'FLOAT' ) { | |
| 3237 | + $dp = $field->decimal_point; | |
| 3238 | + switch ( $dp ) { | |
| 3239 | + case '1': | |
| 3240 | + $step = '0.1'; | |
| 3241 | + break; | |
| 3242 | + case '2': | |
| 3243 | + $step = '0.01'; | |
| 3244 | + break; | |
| 3245 | + case '3': | |
| 3246 | + $step = '0.001'; | |
| 3247 | + break; | |
| 3248 | + case '4': | |
| 3249 | + $step = '0.0001'; | |
| 3250 | + break; | |
| 3251 | + case '5': | |
| 3252 | + $step = '0.00001'; | |
| 3253 | + break; | |
| 3254 | + case '6': | |
| 3255 | + $step = '0.000001'; | |
| 3256 | + break; | |
| 3257 | + case '7': | |
| 3258 | + $step = '0.0000001'; | |
| 3259 | + break; | |
| 3260 | + case '8': | |
| 3261 | + $step = '0.00000001'; | |
| 3262 | + break; | |
| 3263 | + case '9': | |
| 3264 | + $step = '0.000000001'; | |
| 3265 | + break; | |
| 3266 | + case '10': | |
| 3267 | + $step = '0.0000000001'; | |
| 3268 | + break; | |
| 3269 | + default: | |
| 3270 | + $step = '0.01'; | |
| 3271 | + break; | |
| 3272 | + } | |
| 3273 | + $type = 'number'; | |
| 3274 | + } | |
| 3275 | + | |
| 3276 | + $site_title = uwp_get_form_label( $field ); | |
| 3277 | + $placeholder = uwp_get_field_placeholder( $field ); | |
| 3278 | + $manual_label = apply_filters( 'uwp_login_username_label_manual', true ); | |
| 3279 | + if ( $manual_label | |
| 3280 | + && isset( $field->form_type ) | |
| 3281 | + && $field->form_type == 'login' | |
| 3282 | + && $field->htmlvar_name == 'username' ) { | |
| 3283 | + $site_title = __( 'Username or Email', 'userswp' ); | |
| 3284 | + $required = ! empty( $field->is_required ) ? ' *' : ''; | |
| 3285 | + $placeholder = $site_title . $required; | |
| 3286 | + $placeholder = apply_filters( 'uwp_get_field_placeholder', stripslashes( $placeholder ), $field ); | |
| 3287 | + } | |
| 3288 | + | |
| 3289 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 3290 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 3291 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 3292 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 3293 | + | |
| 3294 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 3295 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 3296 | + | |
| 3297 | + // bootstrap | |
| 3298 | + if ( $design_style ) { | |
| 3299 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 3300 | + | |
| 3301 | + echo aui()->input( | |
| 3302 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 3303 | + 'type' => esc_attr( $type ), | |
| 3304 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 3305 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 3306 | + 'placeholder' => esc_attr( $placeholder ), | |
| 3307 | + 'title' => esc_html( $site_title ), | |
| 3308 | + 'value' => esc_attr( wp_unslash( $value ) ), | |
| 3309 | + 'required' => (bool) $field->is_required, | |
| 3310 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 3311 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 3312 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 3313 | + 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ), | |
| 3314 | + 'step' => esc_attr( $step ), | |
| 3315 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 3316 | + ) | |
| 3317 | + ); | |
| 3318 | + } else { | |
| 3319 | + ?> | |
| 3320 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" class=" | |
| 3321 | + <?php | |
| 3322 | + if ( $field->is_required ) { | |
| 3323 | + echo 'required_field'; | |
| 3324 | + } | |
| 3325 | + ?> | |
| 3326 | + uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 3327 | + <?php | |
| 3328 | + | |
| 3329 | + if ( ! is_admin() ) { | |
| 3330 | + ?> | |
| 3331 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 3332 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 3333 | + <?php | |
| 3334 | + if ( $field->is_required ) { | |
| 3335 | + echo '<span>*</span>'; | |
| 3336 | + } | |
| 3337 | + ?> | |
| 3338 | + </label> | |
| 3339 | + <?php | |
| 1625 | 3340 | } |
| 1626 | - } | |
| 1627 | - ?> | |
| 1628 | - <select name="<?php echo $field->htmlvar_name;?>" id="<?php echo $field->htmlvar_name;?>" | |
| 1629 | - class="uwp_textfield" | |
| 1630 | - title="<?php echo $site_title; ?>" | |
| 1631 | - data-placeholder="<?php echo __('Choose', 'userswp') . ' ' . $site_title . '…';?>" | |
| 1632 | - ><?php echo $select_options;?> | |
| 1633 | - </select> | |
| 1634 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 1635 | - <?php if ($field->is_required) { ?> | |
| 1636 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 1637 | - <?php } ?> | |
| 1638 | - </div> | |
| 3341 | + ?> | |
| 1639 | 3342 | |
| 1640 | - <?php | |
| 1641 | - $html = ob_get_clean(); | |
| 1642 | - } | |
| 3343 | + <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3344 | + class="<?php echo esc_attr( $field->css_class ); ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>" | |
| 3345 | + id="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3346 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 3347 | + value="<?php echo esc_attr( stripslashes( $value ) ); ?>" | |
| 3348 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 3349 | + oninvalid="this.setCustomValidity('<?php esc_attr_e( stripslashes( $field->required_msg ), 'userswp' ); ?>')" | |
| 3350 | + oninput="setCustomValidity('')" | |
| 3351 | + <?php | |
| 3352 | + if ( $field->is_required == 1 ) { | |
| 3353 | + echo 'required="required"'; | |
| 3354 | + } | |
| 3355 | + ?> | |
| 3356 | + <?php | |
| 3357 | + if ( $field->for_admin_use == 1 ) { | |
| 3358 | + echo 'readonly="readonly"'; | |
| 3359 | + } | |
| 3360 | + ?> | |
| 3361 | + type="<?php echo esc_attr( $type ); ?>" | |
| 3362 | + <?php | |
| 3363 | + if ( $step ) { | |
| 3364 | + echo 'step="' . esc_attr( $step ) . '"'; | |
| 3365 | + } | |
| 3366 | + ?> | |
| 3367 | + /> | |
| 3368 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 3369 | + <?php if ( $field->is_required ) { ?> | |
| 3370 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 3371 | + <?php } ?> | |
| 3372 | + </div> | |
| 1643 | 3373 | |
| 1644 | - return $html; | |
| 1645 | - } | |
| 1646 | 3374 | |
| 1647 | - /** | |
| 1648 | - * Form field template for multiselect field type. | |
| 1649 | - * | |
| 1650 | - * @since 1.0.0 | |
| 1651 | - * @package userswp | |
| 1652 | - * | |
| 1653 | - * @param string $html Form field html | |
| 1654 | - * @param object $field Field info. | |
| 1655 | - * @param string $value Form field default value. | |
| 1656 | - * @param string $form_type Form type | |
| 1657 | - * | |
| 1658 | - * @return string Modified form field html. | |
| 1659 | - */ | |
| 1660 | - public function uwp_form_input_multiselect($html, $field, $value, $form_type){ | |
| 3375 | + <?php | |
| 3376 | + } | |
| 3377 | + $html = ob_get_clean(); | |
| 3378 | + } | |
| 1661 | 3379 | |
| 1662 | - // Check if there is a field specific filter. | |
| 1663 | - if(has_filter("uwp_form_input_html_multiselect_{$field->htmlvar_name}")){ | |
| 1664 | - $html = apply_filters("uwp_form_input_html_multiselect_{$field->htmlvar_name}", $html, $field, $value, $form_type); | |
| 1665 | - } | |
| 3380 | + return $html; | |
| 3381 | + } | |
| 1666 | 3382 | |
| 3383 | + /** | |
| 3384 | + * Form field template for textarea field type. | |
| 3385 | + * | |
| 3386 | + * @param string $html Form field html | |
| 3387 | + * @param object $field Field info. | |
| 3388 | + * @param string $value Form field default value. | |
| 3389 | + * @param string $form_type Form type | |
| 3390 | + * | |
| 3391 | + * @return string Modified form field html. | |
| 3392 | + * @package userswp | |
| 3393 | + * | |
| 3394 | + * @since 1.0.0 | |
| 3395 | + */ | |
| 3396 | + public function form_input_textarea( $html, $field, $value, $form_type ) { | |
| 1667 | 3397 | |
| 1668 | - if(empty($html)) { | |
| 3398 | + // Check if there is a field specific filter. | |
| 3399 | + if ( has_filter( "uwp_form_input_textarea_{$field->htmlvar_name}" ) ) { | |
| 3400 | + $html = apply_filters( "uwp_form_input_textarea_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 3401 | + } | |
| 1669 | 3402 | |
| 1670 | - ob_start(); // Start buffering; | |
| 3403 | + // If no html then we run the standard output. | |
| 3404 | + if ( empty( $html ) ) { | |
| 1671 | 3405 | |
| 1672 | - $multi_display = 'select'; | |
| 1673 | - if (!empty($field->extra_fields)) { | |
| 1674 | - $multi_display = unserialize($field->extra_fields); | |
| 1675 | - } | |
| 1676 | - ?> | |
| 1677 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 1678 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row uwp_clear"> | |
| 3406 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 3407 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 3408 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 3409 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 3410 | + $site_title = uwp_get_form_label( $field ); | |
| 1679 | 3411 | |
| 1680 | - <?php | |
| 1681 | - $site_title = uwp_get_form_label($field); | |
| 1682 | - if (!is_admin()) { ?> | |
| 1683 | - <label> | |
| 1684 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 1685 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 1686 | - </label> | |
| 1687 | - <?php } ?> | |
| 3412 | + ob_start(); // Start buffering; | |
| 1688 | 3413 | |
| 1689 | - <input type="hidden" name="<?php echo $field->htmlvar_name;?>" value=""/> | |
| 1690 | - <?php if ($multi_display == 'select') { ?> | |
| 1691 | - <div class="uwp_multiselect_list"> | |
| 1692 | - <select name="<?php echo $field->htmlvar_name;?>[]" | |
| 1693 | - id="<?php echo $field->htmlvar_name;?>" | |
| 1694 | - title="<?php echo $site_title; ?>" | |
| 1695 | - multiple="multiple" class="uwp_chosen_select" | |
| 1696 | - data-placeholder="<?php echo $site_title; ?>" | |
| 1697 | - > | |
| 1698 | - <?php | |
| 1699 | - } else { | |
| 3414 | + // bootstrap | |
| 3415 | + if ( $design_style ) { | |
| 3416 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 3417 | + | |
| 3418 | + echo aui()->textarea( | |
| 3419 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 3420 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 3421 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 3422 | + 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ), | |
| 3423 | + 'title' => esc_html( $site_title ), | |
| 3424 | + 'value' => wp_kses_post( stripslashes( $value ) ), | |
| 3425 | + 'required' => (bool) $field->is_required, | |
| 3426 | + 'validation_text' => ! empty( $field->is_required ) ? esc_attr__( stripslashes( $field->required_msg ), 'userswp' ) : '', | |
| 3427 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 3428 | + 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ), | |
| 3429 | + 'rows' => '4', | |
| 3430 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 3431 | + ) | |
| 3432 | + ); | |
| 3433 | + } else { | |
| 3434 | + ?> | |
| 3435 | + | |
| 3436 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 3437 | + class=" | |
| 3438 | + <?php | |
| 3439 | + if ( $field->is_required ) { | |
| 3440 | + echo 'required_field'; | |
| 3441 | + } | |
| 3442 | + ?> | |
| 3443 | + uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 3444 | + | |
| 3445 | + <?php | |
| 3446 | + | |
| 3447 | + if ( ! is_admin() ) { | |
| 3448 | + ?> | |
| 3449 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 3450 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 3451 | + <?php | |
| 3452 | + if ( $field->is_required ) { | |
| 3453 | + echo '<span>*</span>'; | |
| 3454 | + } | |
| 1700 | 3455 | ?> |
| 1701 | - <ul class="uwp_multi_choice"> | |
| 1702 | - <?php | |
| 1703 | - } | |
| 3456 | + </label> | |
| 3457 | + <?php } ?> | |
| 1704 | 3458 | |
| 1705 | - $option_values_arr = uwp_string_values_to_options($field->option_values, true); | |
| 1706 | - $select_options = ''; | |
| 1707 | - if (!empty($option_values_arr)) { | |
| 1708 | - foreach ($option_values_arr as $option_row) { | |
| 1709 | - if (isset($option_row['optgroup']) && ($option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end')) { | |
| 1710 | - $option_label = isset($option_row['label']) ? $option_row['label'] : ''; | |
| 3459 | + <textarea name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3460 | + class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>" | |
| 3461 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 3462 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 3463 | + oninvalid="this.setCustomValidity('<?php esc_attr_e( stripslashes( $field->required_msg ), 'userswp' ); ?>')" | |
| 3464 | + oninput="setCustomValidity('')" | |
| 3465 | + <?php | |
| 3466 | + if ( $field->is_required == 1 ) { | |
| 3467 | + echo 'required="required"'; | |
| 3468 | + } | |
| 3469 | + ?> | |
| 3470 | + type="<?php echo esc_attr( $field->field_type ); ?>" | |
| 3471 | + rows="4"><?php echo wp_kses_post( stripslashes( $value ) ); ?></textarea> | |
| 3472 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 3473 | + <?php if ( $field->is_required ) { ?> | |
| 3474 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 3475 | + <?php } ?> | |
| 3476 | + </div> | |
| 1711 | 3477 | |
| 1712 | - if ($multi_display == 'select') { | |
| 1713 | - $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; | |
| 1714 | - } else { | |
| 1715 | - $select_options .= $option_row['optgroup'] == 'start' ? '<li>' . $option_label . '</li>' : ''; | |
| 1716 | - } | |
| 1717 | - } else { | |
| 1718 | - $option_label = isset($option_row['label']) ? $option_row['label'] : ''; | |
| 1719 | - $option_value = isset($option_row['value']) ? $option_row['value'] : ''; | |
| 1720 | - $selected = $option_value == $value ? 'selected="selected"' : ''; | |
| 1721 | - $checked = ''; | |
| 3478 | + <?php | |
| 3479 | + } | |
| 3480 | + $html = ob_get_clean(); | |
| 3481 | + } | |
| 1722 | 3482 | |
| 1723 | - if ((!is_array($value) && trim($value) != '') || (is_array($value) && !empty($value))) { | |
| 1724 | - if (!is_array($value)) { | |
| 1725 | - $value_array = explode(',', $value); | |
| 1726 | - } else { | |
| 1727 | - $value_array = $value; | |
| 1728 | - } | |
| 3483 | + return $html; | |
| 3484 | + } | |
| 1729 | 3485 | |
| 1730 | - if (is_array($value_array)) { | |
| 1731 | - if (in_array($option_value, $value_array)) { | |
| 1732 | - $selected = 'selected="selected"'; | |
| 1733 | - $checked = 'checked="checked"'; | |
| 1734 | - } | |
| 1735 | - } | |
| 1736 | - } | |
| 3486 | + public function form_input_editor( $html, $field, $value, $form_type ) { | |
| 1737 | 3487 | |
| 1738 | - if ($multi_display == 'select') { | |
| 1739 | - $select_options .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; | |
| 1740 | - } else { | |
| 1741 | - $select_options .= '<li><input name="' . $field->name . '[]" ' . $checked . ' value="' . esc_attr($option_value) . '" class="uwp-' . $multi_display . '" type="' . $multi_display . '" /> ' . $option_label . ' </li>'; | |
| 1742 | - } | |
| 1743 | - } | |
| 1744 | - } | |
| 1745 | - } | |
| 1746 | - echo $select_options; | |
| 3488 | + // Check if there is a field specific filter. | |
| 3489 | + if ( has_filter( "uwp_form_input_editor_{$field->htmlvar_name}" ) ) { | |
| 3490 | + $html = apply_filters( "uwp_form_input_editor_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 3491 | + } | |
| 1747 | 3492 | |
| 1748 | - if ($multi_display == 'select') { ?></select></div> | |
| 1749 | - <?php } else { ?> | |
| 1750 | - </ul> | |
| 1751 | - <?php } ?> | |
| 1752 | - <?php if ($field->is_required) { ?> | |
| 1753 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 1754 | - <?php } ?> | |
| 1755 | - </div> | |
| 1756 | - <?php | |
| 1757 | - $html = ob_get_clean(); | |
| 1758 | - } | |
| 3493 | + if ( empty( $html ) ) { | |
| 1759 | 3494 | |
| 1760 | - return $html; | |
| 1761 | - } | |
| 3495 | + ob_start(); | |
| 1762 | 3496 | |
| 1763 | - /** | |
| 1764 | - * Form field template for file field type. | |
| 1765 | - * | |
| 1766 | - * @since 1.0.0 | |
| 1767 | - * @package userswp | |
| 1768 | - * | |
| 1769 | - * @param string $html Form field html | |
| 1770 | - * @param object $field Field info. | |
| 1771 | - * @param string $value Form field default value. | |
| 1772 | - * @param string $form_type Form type | |
| 1773 | - * | |
| 1774 | - * @return string Modified form field html. | |
| 1775 | - */ | |
| 1776 | - public function uwp_form_input_file($html, $field, $value, $form_type){ | |
| 3497 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 3498 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 3499 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 3500 | + $site_title = uwp_get_form_label( $field ); | |
| 1777 | 3501 | |
| 1778 | - $file_obj = new UsersWP_Files(); | |
| 1779 | - | |
| 1780 | - // Check if there is a field specific filter. | |
| 1781 | - if(has_filter("uwp_form_input_html_file_{$field->htmlvar_name}")){ | |
| 1782 | - $html = apply_filters("uwp_form_input_html_file_{$field->htmlvar_name}", $html, $field, $value, $form_type); | |
| 1783 | - } | |
| 3502 | + $content = stripslashes( $value ); | |
| 3503 | + $editor_id = $field->htmlvar_name; | |
| 3504 | + $args = array( | |
| 3505 | + 'textarea_rows' => 5, | |
| 3506 | + 'media_buttons' => false, | |
| 3507 | + 'quicktags' => false, | |
| 3508 | + ); | |
| 1784 | 3509 | |
| 1785 | - // If no html then we run the standard output. | |
| 1786 | - if(empty($html)) { | |
| 3510 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 3511 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 1787 | 3512 | |
| 1788 | - ob_start(); // Start buffering; | |
| 3513 | + // bootstrap | |
| 3514 | + if ( $design_style ) { | |
| 3515 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 1789 | 3516 | |
| 1790 | - ?> | |
| 1791 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 1792 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear"> | |
| 3517 | + echo aui()->textarea( | |
| 3518 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 3519 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 3520 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 3521 | + 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ), | |
| 3522 | + 'title' => esc_html( $site_title ), | |
| 3523 | + 'value' => wp_kses_post( stripslashes( $value ) ), | |
| 3524 | + 'required' => (bool) $field->is_required, | |
| 3525 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 3526 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 3527 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 3528 | + 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ), | |
| 3529 | + 'rows' => 5, | |
| 3530 | + 'wysiwyg' => true, | |
| 3531 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 3532 | + ) | |
| 3533 | + ); | |
| 3534 | + } else { | |
| 3535 | + ?> | |
| 3536 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 3537 | + class=" | |
| 3538 | + <?php | |
| 3539 | + if ( $field->is_required ) { | |
| 3540 | + echo 'required_field'; | |
| 3541 | + } | |
| 3542 | + ?> | |
| 3543 | + uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 1793 | 3544 | |
| 1794 | - <?php | |
| 1795 | - $site_title = uwp_get_form_label($field); | |
| 1796 | - if (!is_admin()) { ?> | |
| 1797 | - <label> | |
| 1798 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 1799 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 1800 | - </label> | |
| 1801 | - <?php } ?> | |
| 3545 | + <?php | |
| 1802 | 3546 | |
| 1803 | - <?php echo $file_obj->uwp_file_upload_preview($field, $value); ?> | |
| 1804 | - <input name="<?php echo $field->htmlvar_name; ?>" | |
| 1805 | - class="<?php echo $field->css_class; ?>" | |
| 1806 | - placeholder="<?php echo $site_title; ?>" | |
| 1807 | - title="<?php echo $site_title; ?>" | |
| 3547 | + if ( ! is_admin() ) { | |
| 3548 | + ?> | |
| 3549 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 3550 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 3551 | + <?php | |
| 3552 | + if ( $field->is_required ) { | |
| 3553 | + echo '<span>*</span>'; | |
| 3554 | + } | |
| 3555 | + ?> | |
| 3556 | + </label> | |
| 3557 | + <?php } ?> | |
| 3558 | + | |
| 3559 | + <?php wp_editor( $content, $editor_id, $args ); ?> | |
| 3560 | + | |
| 3561 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 3562 | + <?php if ( $field->is_required ) { ?> | |
| 3563 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 3564 | + <?php } ?> | |
| 3565 | + </div> | |
| 3566 | + <?php | |
| 3567 | + } | |
| 3568 | + $html = ob_get_clean(); | |
| 3569 | + } | |
| 3570 | + | |
| 3571 | + return $html; | |
| 3572 | + } | |
| 3573 | + | |
| 3574 | + /** | |
| 3575 | + * Form field template for fieldset field type. | |
| 3576 | + * | |
| 3577 | + * @param string $html Form field html | |
| 3578 | + * @param object $field Field info. | |
| 3579 | + * @param string $value Form field default value. | |
| 3580 | + * @param string $form_type Form type | |
| 3581 | + * | |
| 3582 | + * @return string Modified form field html. | |
| 3583 | + * @package userswp | |
| 3584 | + * | |
| 3585 | + * @since 1.0.0 | |
| 3586 | + */ | |
| 3587 | + public function form_input_fieldset( $html, $field, $value, $form_type ) { | |
| 3588 | + // Check if there is a custom field specific filter. | |
| 3589 | + if ( has_filter( "uwp_form_input_fieldset_{$field->htmlvar_name}" ) ) { | |
| 3590 | + $html = apply_filters( "uwp_form_input_fieldset_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 3591 | + } | |
| 3592 | + | |
| 3593 | + // If no html then we run the standard output. | |
| 3594 | + if ( empty( $html ) ) { | |
| 3595 | + | |
| 3596 | + ob_start(); // Start buffering; | |
| 3597 | + $site_title = uwp_get_form_label( $field ); | |
| 3598 | + ?> | |
| 3599 | + <h3 class="uwp_input_fieldset <?php echo esc_attr( $field->css_class ); ?>"> | |
| 3600 | + <?php echo esc_html( $site_title ); ?> | |
| 3601 | + <?php | |
| 3602 | + if ( $field->help_text != '' ) { | |
| 3603 | + echo '<small>( ' . wp_kses_post( $field->help_text ) . ' )</small>'; | |
| 3604 | + } | |
| 3605 | + ?> | |
| 3606 | + </h3> | |
| 3607 | + <?php | |
| 3608 | + $html = ob_get_clean(); | |
| 3609 | + } | |
| 3610 | + | |
| 3611 | + return $html; | |
| 3612 | + } | |
| 3613 | + | |
| 3614 | + /** | |
| 3615 | + * Form field template for url field type. | |
| 3616 | + * | |
| 3617 | + * @param string $html Form field html | |
| 3618 | + * @param object $field Field info. | |
| 3619 | + * @param string $value Form field default value. | |
| 3620 | + * @param string $form_type Form type | |
| 3621 | + * | |
| 3622 | + * @return string Modified form field html. | |
| 3623 | + * @package userswp | |
| 3624 | + * | |
| 3625 | + * @since 1.0.0 | |
| 3626 | + */ | |
| 3627 | + public function form_input_url( $html, $field, $value, $form_type ) { | |
| 3628 | + | |
| 3629 | + // Check if there is a custom field specific filter. | |
| 3630 | + if ( has_filter( "uwp_form_input_url_{$field->htmlvar_name}" ) ) { | |
| 3631 | + $html = apply_filters( "uwp_form_input_url_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 3632 | + } | |
| 3633 | + | |
| 3634 | + // If no html then we run the standard output. | |
| 3635 | + if ( empty( $html ) ) { | |
| 3636 | + | |
| 3637 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 3638 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 3639 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 3640 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 3641 | + | |
| 3642 | + ob_start(); // Start buffering; | |
| 3643 | + $site_title = uwp_get_form_label( $field ); | |
| 3644 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : __( 'Please enter a valid URL including https://', 'userswp' ); | |
| 3645 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 3646 | + | |
| 3647 | + // bootstrap | |
| 3648 | + if ( $design_style ) { | |
| 3649 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 3650 | + | |
| 3651 | + echo aui()->input( | |
| 3652 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 3653 | + 'type' => 'url', | |
| 3654 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 3655 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 3656 | + 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ), | |
| 3657 | + 'title' => esc_html( $site_title ), | |
| 3658 | + 'value' => esc_attr( $value ), | |
| 3659 | + 'required' => (bool) $field->is_required, | |
| 3660 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 3661 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 3662 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 3663 | + 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ), | |
| 3664 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 3665 | + ) | |
| 3666 | + ); | |
| 3667 | + } else { | |
| 3668 | + ?> | |
| 3669 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 3670 | + class=" | |
| 1808 | 3671 | <?php |
| 1809 | - if ($field->is_required == 1 ) { echo 'data-is-required="1"'; } | |
| 1810 | - if ($field->is_required == 1 && !$value) { echo 'required="required"'; } | |
| 3672 | + if ( $field->is_required ) { | |
| 3673 | + echo 'required_field'; | |
| 3674 | + } | |
| 1811 | 3675 | ?> |
| 1812 | - type="<?php echo $field->field_type; ?>"> | |
| 1813 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 1814 | - <?php if ($field->is_required) { ?> | |
| 1815 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 1816 | - <?php } ?> | |
| 1817 | - </div> | |
| 3676 | + uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 1818 | 3677 | |
| 1819 | - <?php | |
| 1820 | - $html = ob_get_clean(); | |
| 1821 | - } | |
| 3678 | + <?php | |
| 3679 | + if ( ! is_admin() ) { | |
| 3680 | + ?> | |
| 3681 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 3682 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 3683 | + <?php | |
| 3684 | + if ( $field->is_required ) { | |
| 3685 | + echo '<span>*</span>'; | |
| 3686 | + } | |
| 3687 | + ?> | |
| 3688 | + </label> | |
| 3689 | + <?php } ?> | |
| 1822 | 3690 | |
| 1823 | - return $html; | |
| 1824 | - } | |
| 3691 | + <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3692 | + class=" | |
| 3693 | + <?php | |
| 3694 | + //echo $field->css_class; | |
| 3695 | + ?> | |
| 3696 | + uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>" | |
| 3697 | + id="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3698 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 3699 | + value="<?php echo esc_attr( stripslashes( $value ) ); ?>" | |
| 3700 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 3701 | + <?php | |
| 3702 | + if ( $field->is_required == 1 ) { | |
| 3703 | + echo 'required="required"'; | |
| 3704 | + } | |
| 3705 | + ?> | |
| 3706 | + type="url" | |
| 3707 | + oninvalid="setCustomValidity('<?php esc_attr_e( 'Please enter a valid URL including http://', 'userswp' ); ?>')" | |
| 3708 | + onchange="try{setCustomValidity('')}catch(e){}" | |
| 3709 | + /> | |
| 3710 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 3711 | + <?php if ( $field->is_required ) { ?> | |
| 3712 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 3713 | + <?php } ?> | |
| 3714 | + </div> | |
| 1825 | 3715 | |
| 1826 | - /** | |
| 1827 | - * Form field template for checkbox field type. | |
| 1828 | - * | |
| 1829 | - * @since 1.0.0 | |
| 1830 | - * @package userswp | |
| 1831 | - * | |
| 1832 | - * @param string $html Form field html | |
| 1833 | - * @param object $field Field info. | |
| 1834 | - * @param string $value Form field default value. | |
| 1835 | - * @param string $form_type Form type | |
| 1836 | - * | |
| 1837 | - * @return string Modified form field html. | |
| 1838 | - */ | |
| 1839 | - public function uwp_form_input_checkbox($html, $field, $value, $form_type){ | |
| 3716 | + <?php | |
| 3717 | + } | |
| 1840 | 3718 | |
| 1841 | - // Check if there is a field specific filter. | |
| 1842 | - if(has_filter("uwp_form_input_html_checkbox_{$field->htmlvar_name}")){ | |
| 1843 | - $html = apply_filters("uwp_form_input_html_checkbox_{$field->htmlvar_name}", $html, $field, $value, $form_type); | |
| 1844 | - } | |
| 3719 | + $html = ob_get_clean(); | |
| 3720 | + } | |
| 1845 | 3721 | |
| 1846 | - // If no html then we run the standard output. | |
| 1847 | - if(empty($html)) { | |
| 3722 | + return $html; | |
| 3723 | + } | |
| 1848 | 3724 | |
| 1849 | - ob_start(); // Start buffering; | |
| 1850 | - $site_title = uwp_get_form_label($field); | |
| 1851 | - ?> | |
| 1852 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 1853 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear"> | |
| 1854 | - <input type="hidden" name="<?php echo $field->htmlvar_name; ?>" value="0" /> | |
| 1855 | - <input name="<?php echo $field->htmlvar_name; ?>" | |
| 1856 | - class="<?php echo $field->css_class; ?>" | |
| 1857 | - placeholder="<?php echo $site_title; ?>" | |
| 1858 | - title="<?php echo $site_title; ?>" | |
| 1859 | - <?php if ($field->is_required == 1) { echo 'required="required"'; } ?> | |
| 1860 | - <?php if ($value == '1') { echo 'checked="checked"'; } ?> | |
| 1861 | - type="<?php echo $field->field_type; ?>" | |
| 1862 | - value="1"> | |
| 1863 | - <?php | |
| 1864 | - echo (trim($site_title)) ? $site_title : ' '; | |
| 3725 | + /** | |
| 3726 | + * Form field template for email field type. | |
| 3727 | + * | |
| 3728 | + * @param string $html Form field html | |
| 3729 | + * @param object $field Field info. | |
| 3730 | + * @param string $value Form field default value. | |
| 3731 | + * @param string $form_type Form type | |
| 3732 | + * | |
| 3733 | + * @return string Modified form field html. | |
| 3734 | + * @package userswp | |
| 3735 | + * | |
| 3736 | + * @since 1.0.0 | |
| 3737 | + */ | |
| 3738 | + public function form_input_email( $html, $field, $value, $form_type ) { | |
| 3739 | + | |
| 3740 | + // Check if there is a custom field specific filter. | |
| 3741 | + if ( has_filter( "uwp_form_input_email_{$field->htmlvar_name}" ) ) { | |
| 3742 | + $html = apply_filters( "uwp_form_input_email_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 3743 | + } | |
| 3744 | + | |
| 3745 | + // If no html then we run the standard output. | |
| 3746 | + if ( empty( $html ) ) { | |
| 3747 | + | |
| 3748 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 3749 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 3750 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 3751 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 3752 | + | |
| 3753 | + ob_start(); // Start buffering; | |
| 3754 | + $site_title = uwp_get_form_label( $field ); | |
| 3755 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 3756 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 3757 | + | |
| 3758 | + if ( $design_style ) { | |
| 3759 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 3760 | + | |
| 3761 | + echo aui()->input( | |
| 3762 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 3763 | + 'type' => 'email', | |
| 3764 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 3765 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 3766 | + 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ), | |
| 3767 | + 'title' => esc_html( $site_title ), | |
| 3768 | + 'value' => esc_attr( wp_unslash( $value ) ), | |
| 3769 | + 'required' => (bool) $field->is_required, | |
| 3770 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 3771 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 3772 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 3773 | + 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ), | |
| 3774 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 3775 | + ) | |
| 3776 | + ); | |
| 3777 | + } else { | |
| 3778 | + ?> | |
| 3779 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 3780 | + class=" | |
| 3781 | + <?php | |
| 3782 | + if ( $field->is_required ) { | |
| 3783 | + echo 'required_field'; | |
| 3784 | + } | |
| 3785 | + ?> | |
| 3786 | + uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 3787 | + | |
| 3788 | + <?php | |
| 3789 | + if ( ! is_admin() ) { | |
| 3790 | + ?> | |
| 3791 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 3792 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 3793 | + <?php | |
| 3794 | + if ( $field->is_required ) { | |
| 3795 | + echo '<span>*</span>'; | |
| 3796 | + } | |
| 3797 | + ?> | |
| 3798 | + </label> | |
| 3799 | + <?php } ?> | |
| 3800 | + | |
| 3801 | + <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3802 | + class="<?php echo esc_attr( $field->css_class ); ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>" | |
| 3803 | + id="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3804 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 3805 | + value="<?php echo esc_attr( stripslashes( $value ) ); ?>" | |
| 3806 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 3807 | + <?php | |
| 3808 | + if ( $field->is_required == 1 ) { | |
| 3809 | + echo 'required="required"'; | |
| 3810 | + } | |
| 3811 | + ?> | |
| 3812 | + type="email" | |
| 3813 | + /> | |
| 3814 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 3815 | + <?php if ( $field->is_required ) { ?> | |
| 3816 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 3817 | + <?php } ?> | |
| 3818 | + </div> | |
| 3819 | + | |
| 3820 | + | |
| 3821 | + <?php | |
| 3822 | + } | |
| 3823 | + $html = ob_get_clean(); | |
| 3824 | + | |
| 3825 | + } | |
| 3826 | + | |
| 3827 | + if ( has_filter( "uwp_form_input_email_{$field->htmlvar_name}_after" ) ) { | |
| 3828 | + $html = apply_filters( "uwp_form_input_email_{$field->htmlvar_name}_after", $html, $field, $value, $form_type ); | |
| 3829 | + } | |
| 3830 | + | |
| 3831 | + return $html; | |
| 3832 | + } | |
| 3833 | + | |
| 3834 | + /** | |
| 3835 | + * Form field template for password field type. | |
| 3836 | + * | |
| 3837 | + * @param string $html Form field html | |
| 3838 | + * @param object $field Field info. | |
| 3839 | + * @param string $value Form field default value. | |
| 3840 | + * @param string $form_type Form type | |
| 3841 | + * | |
| 3842 | + * @return string Modified form field html. | |
| 3843 | + * @package userswp | |
| 3844 | + * | |
| 3845 | + * @since 1.0.0 | |
| 3846 | + */ | |
| 3847 | + public function form_input_password( $html, $field, $value, $form_type ) { | |
| 3848 | + | |
| 3849 | + // Check if there is a custom field specific filter. | |
| 3850 | + if ( has_filter( "uwp_form_input_password_{$field->htmlvar_name}" ) ) { | |
| 3851 | + $html = apply_filters( "uwp_form_input_password_{$field->htmlvar_name}", $html, $field, $value, $form_type ); | |
| 3852 | + } | |
| 3853 | + | |
| 3854 | + // If no html then we run the standard output. | |
| 3855 | + if ( empty( $html ) ) { | |
| 3856 | + | |
| 3857 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 3858 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 3859 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 3860 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 3861 | + | |
| 3862 | + ob_start(); // Start buffering; | |
| 3863 | + $site_title = uwp_get_form_label( $field ); | |
| 3864 | + | |
| 3865 | + if ( $design_style ) { | |
| 3866 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 3867 | + $required_msg = ( ! empty( $field->required_msg ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 3868 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 3869 | + $wrap_class = isset( $field->css_class ) ? $field->css_class . ' uwp-password-wrap' : 'uwp-password-wrap'; | |
| 3870 | + | |
| 3871 | + echo aui()->input( | |
| 3872 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 3873 | + 'type' => 'password', | |
| 3874 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 3875 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 3876 | + 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ), | |
| 3877 | + 'title' => esc_html( $site_title ), | |
| 3878 | + 'value' => esc_attr( $value ), | |
| 3879 | + 'required' => (bool) $field->is_required, | |
| 3880 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 3881 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 3882 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 3883 | + 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ), | |
| 3884 | + 'wrap_class' => esc_attr( $wrap_class ), | |
| 3885 | + ) | |
| 3886 | + ); | |
| 3887 | + } else { | |
| 3888 | + ?> | |
| 3889 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" class=" | |
| 3890 | + <?php | |
| 3891 | + if ( $field->is_required ) { | |
| 3892 | + echo 'required_field'; | |
| 3893 | + } | |
| 1865 | 3894 | ?> |
| 1866 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 1867 | - <?php if ($field->is_required) { ?> | |
| 1868 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 1869 | - <?php } ?> | |
| 1870 | - </div> | |
| 3895 | + uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 3896 | + <?php | |
| 3897 | + if ( ! is_admin() ) { | |
| 3898 | + ?> | |
| 3899 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 3900 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 3901 | + <?php | |
| 3902 | + if ( $field->is_required ) { | |
| 3903 | + echo '<span>*</span>'; | |
| 3904 | + } | |
| 3905 | + ?> | |
| 3906 | + </label> | |
| 3907 | + <?php } ?> | |
| 1871 | 3908 | |
| 1872 | - <?php | |
| 1873 | - $html = ob_get_clean(); | |
| 1874 | - } | |
| 3909 | + <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3910 | + class="<?php echo esc_attr( $field->css_class ); ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>" | |
| 3911 | + id="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 3912 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 3913 | + value="<?php echo esc_attr( stripslashes( $value ) ); ?>" | |
| 3914 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 3915 | + <?php | |
| 3916 | + if ( $field->is_required == 1 ) { | |
| 3917 | + echo 'required="required"'; | |
| 3918 | + } | |
| 3919 | + ?> | |
| 3920 | + type="password" | |
| 3921 | + /> | |
| 3922 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 3923 | + <?php if ( $field->is_required ) { ?> | |
| 3924 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 3925 | + <?php } ?> | |
| 3926 | + </div> | |
| 1875 | 3927 | |
| 1876 | - return $html; | |
| 1877 | - } | |
| 1878 | 3928 | |
| 1879 | - /** | |
| 1880 | - * Form field template for radio field type. | |
| 1881 | - * | |
| 1882 | - * @since 1.0.0 | |
| 1883 | - * @package userswp | |
| 1884 | - * | |
| 1885 | - * @param string $html Form field html | |
| 1886 | - * @param object $field Field info. | |
| 1887 | - * @param string $value Form field default value. | |
| 1888 | - * @param string $form_type Form type | |
| 1889 | - * | |
| 1890 | - * @return string Modified form field html. | |
| 1891 | - */ | |
| 1892 | - public function uwp_form_input_radio($html, $field, $value, $form_type){ | |
| 3929 | + <?php | |
| 3930 | + } | |
| 1893 | 3931 | |
| 1894 | - // Check if there is a field specific filter. | |
| 1895 | - if(has_filter("uwp_form_input_html_radio_{$field->htmlvar_name}")){ | |
| 1896 | - $html = apply_filters("uwp_form_input_html_radio_{$field->htmlvar_name}", $html, $field, $value, $form_type); | |
| 1897 | - } | |
| 3932 | + $html = ob_get_clean(); | |
| 3933 | + } | |
| 1898 | 3934 | |
| 1899 | - // If no html then we run the standard output. | |
| 1900 | - if(empty($html)) { | |
| 3935 | + if ( has_filter( "uwp_form_input_password_{$field->htmlvar_name}_after" ) ) { | |
| 3936 | + $html = apply_filters( "uwp_form_input_password_{$field->htmlvar_name}_after", $html, $field, $value, $form_type ); | |
| 3937 | + } | |
| 1901 | 3938 | |
| 1902 | - ob_start(); // Start buffering; | |
| 3939 | + return $html; | |
| 3940 | + } | |
| 1903 | 3941 | |
| 1904 | - ?> | |
| 1905 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 1906 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear"> | |
| 3942 | + /** | |
| 3943 | + * Form field template for Phone field. | |
| 3944 | + * | |
| 3945 | + * @param string $html Form field html | |
| 3946 | + * @param object $field Field info. | |
| 3947 | + * @param string $value Form field default value. | |
| 3948 | + * @param string $form_type Form type | |
| 3949 | + * | |
| 3950 | + * @return string $html Modified form field html. | |
| 3951 | + * @since 1.0.0 | |
| 3952 | + * | |
| 3953 | + */ | |
| 3954 | + public function form_input_phone( $html, $field, $value, $form_type ) { | |
| 3955 | + if ( empty( $html ) ) { | |
| 3956 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 3957 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 3958 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 3959 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 3960 | + ob_start(); // Start buffering; | |
| 3961 | + $site_title = uwp_get_form_label( $field ); | |
| 3962 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 3963 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 1907 | 3964 | |
| 1908 | - <?php | |
| 1909 | - $site_title = uwp_get_form_label($field); | |
| 1910 | - if (!is_admin()) { ?> | |
| 1911 | - <label> | |
| 1912 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 1913 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 1914 | - </label> | |
| 1915 | - <?php } ?> | |
| 3965 | + if ( $design_style ) { | |
| 3966 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 1916 | 3967 | |
| 3968 | + echo aui()->input( | |
| 3969 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 3970 | + 'type' => 'tel', | |
| 3971 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 3972 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 3973 | + 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ), | |
| 3974 | + 'title' => esc_html( $site_title ), | |
| 3975 | + 'value' => esc_attr( $value ), | |
| 3976 | + 'required' => (bool) $field->is_required, | |
| 3977 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 3978 | + 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ), | |
| 3979 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 3980 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 3981 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 3982 | + ) | |
| 3983 | + ); | |
| 3984 | + } else { | |
| 3985 | + ?> | |
| 3986 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 3987 | + class=" | |
| 3988 | + <?php | |
| 3989 | + if ( $field->is_required ) { | |
| 3990 | + echo 'required_field'; | |
| 3991 | + } | |
| 3992 | + ?> | |
| 3993 | + clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 3994 | + <?php | |
| 3995 | + if ( ! is_admin() ) { | |
| 3996 | + ?> | |
| 3997 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 3998 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 3999 | + <?php | |
| 4000 | + if ( $field->is_required ) { | |
| 4001 | + echo '<span>*</span>'; | |
| 4002 | + } | |
| 4003 | + ?> | |
| 4004 | + </label> | |
| 4005 | + <?php } ?> | |
| 4006 | + <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 4007 | + class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>" | |
| 4008 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 4009 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 4010 | + <?php | |
| 4011 | + if ( $field->for_admin_use == 1 ) { | |
| 4012 | + echo 'readonly="readonly"'; | |
| 4013 | + } | |
| 4014 | + ?> | |
| 4015 | + <?php | |
| 4016 | + if ( $field->is_required == 1 ) { | |
| 4017 | + echo 'required="required"'; | |
| 4018 | + } | |
| 4019 | + ?> | |
| 4020 | + type="tel" | |
| 4021 | + value="<?php echo esc_html( $value ); ?>"> | |
| 4022 | + </div> | |
| 4023 | + <?php | |
| 4024 | + } | |
| 4025 | + $html = ob_get_clean(); | |
| 4026 | + } | |
| 1917 | 4027 | |
| 1918 | - <?php if ($field->option_values) { | |
| 1919 | - $option_values = uwp_string_values_to_options($field->option_values, true); | |
| 4028 | + return $html; | |
| 4029 | + } | |
| 1920 | 4030 | |
| 1921 | - if (!empty($option_values)) { | |
| 1922 | - $count = 0; | |
| 1923 | - foreach ($option_values as $option_value) { | |
| 1924 | - if (empty($option_value['optgroup'])) { | |
| 1925 | - $count++; | |
| 1926 | - if ($count == 1) { | |
| 1927 | - $class = "uwp-radio-first"; | |
| 1928 | - } else { | |
| 1929 | - $class = ""; | |
| 1930 | - } | |
| 1931 | - ?> | |
| 1932 | - <span class="uwp-radios <?php echo $class; ?>"> | |
| 1933 | - <input name="<?php echo $field->htmlvar_name; ?>" | |
| 1934 | - id="<?php echo $field->htmlvar_name; ?>" | |
| 1935 | - title="<?php echo esc_attr($option_value['label']); ?>" | |
| 1936 | - <?php checked($value, $option_value['value']);?> | |
| 1937 | - <?php if ($field->is_required == 1) { echo 'required="required"'; } ?> | |
| 1938 | - value="<?php echo esc_attr($option_value['value']); ?>" | |
| 1939 | - class="uwp-radio" type="radio" /> | |
| 1940 | - <?php echo $option_value['label']; ?> | |
| 1941 | - </span> | |
| 1942 | - <?php | |
| 1943 | - } | |
| 1944 | - } | |
| 1945 | - } | |
| 1946 | - } | |
| 1947 | - ?> | |
| 1948 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 1949 | - <?php if ($field->is_required) { ?> | |
| 1950 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 1951 | - <?php } ?> | |
| 1952 | - </div> | |
| 1953 | - <?php | |
| 1954 | - $html = ob_get_clean(); | |
| 1955 | - } | |
| 4031 | + public function form_input_register_gdpr( $html, $field, $value, $form_type ) { | |
| 1956 | 4032 | |
| 1957 | - return $html; | |
| 1958 | - } | |
| 4033 | + $form_id = isset( $field->form_id ) ? (int) $field->form_id : 1; | |
| 4034 | + $reg_gdpr = uwp_get_register_form_by( $form_id, 'gdpr_page' ); | |
| 4035 | + if ( empty( $reg_gdpr ) ) { | |
| 4036 | + $reg_gdpr = uwp_get_option( 'register_gdpr_page', false ); | |
| 4037 | + } | |
| 1959 | 4038 | |
| 1960 | - /** | |
| 1961 | - * Form field template for text field type. | |
| 1962 | - * | |
| 1963 | - * @since 1.0.0 | |
| 1964 | - * @package userswp | |
| 1965 | - * | |
| 1966 | - * @param string $html Form field html | |
| 1967 | - * @param object $field Field info. | |
| 1968 | - * @param string $value Form field default value. | |
| 1969 | - * @param string $form_type Form type | |
| 1970 | - * | |
| 1971 | - * @return string Modified form field html. | |
| 1972 | - */ | |
| 1973 | - public function uwp_form_input_text($html, $field, $value, $form_type){ | |
| 4039 | + if ( ! empty( $reg_gdpr ) ) { | |
| 1974 | 4040 | |
| 1975 | - // Check if there is a custom field specific filter. | |
| 1976 | - if(has_filter("uwp_form_input_text_{$field->htmlvar_name}")){ | |
| 1977 | - $html = apply_filters("uwp_form_input_text_{$field->htmlvar_name}",$html, $field, $value, $form_type); | |
| 1978 | - } | |
| 4041 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 4042 | + $bs_form_group = $design_style ? 'form-group mb-3 form-check' : ''; | |
| 4043 | + $bs_form_control = $design_style ? 'form-check-input' : ''; | |
| 4044 | + $site_title = uwp_get_form_label( $field ); | |
| 4045 | + $field->htmlvar_name = 'register_gdpr'; | |
| 4046 | + $id = wp_doing_ajax() ? $field->htmlvar_name . '_ajax' : $field->htmlvar_name; | |
| 1979 | 4047 | |
| 1980 | - // If no html then we run the standard output. | |
| 1981 | - if(empty($html)) { | |
| 4048 | + $gdpr_page = get_permalink( $reg_gdpr ); | |
| 4049 | + $link_start = '<a href="' . esc_url( $gdpr_page ) . '" target="_blank">'; | |
| 4050 | + $link_end = '</a>'; | |
| 4051 | + $field_desc = uwp_get_field_description( $field, '' ); | |
| 4052 | + $field_desc = str_replace( '%%link_start%%', $link_start, $field_desc ); | |
| 4053 | + $field_desc = str_replace( '%%link_end%%', $link_end, $field_desc ); | |
| 4054 | + $content = $field_desc ? $field_desc : sprintf( __( 'By using this form I agree to the storage and handling of my data by this website. View our %1$s %2$s %3$s.', 'userswp' ), '<a href="' . esc_url( $gdpr_page ) . '" target="_blank">', $site_title, '</a>' ); | |
| 4055 | + $checked = $value == '1' ? true : false; | |
| 1982 | 4056 | |
| 1983 | - ob_start(); // Start buffering; | |
| 4057 | + ob_start(); // Start buffering; | |
| 1984 | 4058 | |
| 1985 | - $type = 'text'; | |
| 1986 | - $step = false; | |
| 1987 | - //number and float validation $validation_pattern | |
| 1988 | - if(isset($field->data_type) && $field->data_type == 'INT'){ | |
| 1989 | - $type = 'number'; | |
| 1990 | - } elseif(isset($field->data_type) && $field->data_type == 'FLOAT'){ | |
| 1991 | - $dp = $field->decimal_point; | |
| 1992 | - switch ($dp) { | |
| 1993 | - case "1": | |
| 1994 | - $step = "0.1"; | |
| 1995 | - break; | |
| 1996 | - case "2": | |
| 1997 | - $step = "0.01"; | |
| 1998 | - break; | |
| 1999 | - case "3": | |
| 2000 | - $step = "0.001"; | |
| 2001 | - break; | |
| 2002 | - case "4": | |
| 2003 | - $step = "0.0001"; | |
| 2004 | - break; | |
| 2005 | - case "5": | |
| 2006 | - $step = "0.00001"; | |
| 2007 | - break; | |
| 2008 | - case "6": | |
| 2009 | - $step = "0.000001"; | |
| 2010 | - break; | |
| 2011 | - case "7": | |
| 2012 | - $step = "0.0000001"; | |
| 2013 | - break; | |
| 2014 | - case "8": | |
| 2015 | - $step = "0.00000001"; | |
| 2016 | - break; | |
| 2017 | - case "9": | |
| 2018 | - $step = "0.000000001"; | |
| 2019 | - break; | |
| 2020 | - case "10": | |
| 2021 | - $step = "0.0000000001"; | |
| 2022 | - break; | |
| 2023 | - default: | |
| 2024 | - $step = "0.01"; | |
| 2025 | - break; | |
| 2026 | - } | |
| 2027 | - $type = 'number'; | |
| 2028 | - } | |
| 4059 | + // bootstrap | |
| 4060 | + if ( $design_style ) { | |
| 4061 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 4062 | + echo '<input type="hidden" name="' . esc_attr( $field->htmlvar_name ) . '" id="checkbox_' . esc_attr( $id ) . '" value="0"/>'; | |
| 2029 | 4063 | |
| 2030 | - ?> | |
| 4064 | + echo aui()->input( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 4065 | + array( | |
| 4066 | + 'id' => esc_attr( $id ), | |
| 4067 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 4068 | + 'type' => 'checkbox', | |
| 4069 | + 'value' => '1', | |
| 4070 | + 'title' => esc_html( $site_title ), | |
| 4071 | + 'label' => wp_kses_post( $content . $required ), | |
| 4072 | + 'label_show' => true, | |
| 4073 | + 'required' => ! empty( $field->is_required ) ? true : false, | |
| 4074 | + 'checked' => (bool) $checked, | |
| 4075 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 4076 | + 'validation_text' => ! empty( $field->is_required ) ? esc_attr__( stripslashes( $field->required_msg ), 'userswp' ) : '', | |
| 4077 | + ) | |
| 4078 | + ); | |
| 2031 | 4079 | |
| 2032 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 2033 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear"> | |
| 4080 | + } else { | |
| 4081 | + ?> | |
| 4082 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 4083 | + class=" | |
| 4084 | + <?php | |
| 4085 | + if ( $field->is_required ) { | |
| 4086 | + echo 'required_field'; | |
| 4087 | + } | |
| 4088 | + ?> | |
| 4089 | + uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 4090 | + <input type="hidden" name="<?php echo esc_attr( $field->htmlvar_name ); ?>" value="0"/> | |
| 4091 | + <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 4092 | + class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>" | |
| 4093 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 4094 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 4095 | + <?php | |
| 4096 | + if ( $value == '1' ) { | |
| 4097 | + echo 'checked="checked"'; | |
| 4098 | + } | |
| 4099 | + ?> | |
| 4100 | + type="<?php echo esc_attr( $field->field_type ); ?>" | |
| 4101 | + value="1"> | |
| 4102 | + <?php | |
| 4103 | + echo ( trim( $content ) ) ? wp_kses_post( $content ) : ' '; | |
| 4104 | + ?> | |
| 4105 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 4106 | + <?php if ( $field->is_required ) { ?> | |
| 4107 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 4108 | + <?php } ?> | |
| 4109 | + </div> | |
| 2034 | 4110 | |
| 2035 | - <?php | |
| 2036 | - $site_title = uwp_get_form_label($field); | |
| 2037 | - $manual_label = apply_filters('uwp_login_username_label_manual', true); | |
| 2038 | - if ($manual_label | |
| 2039 | - && isset($field->form_type) | |
| 2040 | - && $field->form_type == 'login' | |
| 2041 | - && $field->htmlvar_name == 'uwp_login_username') { | |
| 2042 | - $site_title = __("Username or Email", 'userswp'); | |
| 2043 | - } | |
| 2044 | - if (!is_admin()) { ?> | |
| 2045 | - <label> | |
| 2046 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 2047 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 2048 | - </label> | |
| 2049 | - <?php } ?> | |
| 4111 | + <?php | |
| 4112 | + } | |
| 2050 | 4113 | |
| 2051 | - <input name="<?php echo $field->htmlvar_name;?>" | |
| 2052 | - class="<?php echo $field->css_class; ?> uwp_textfield" | |
| 2053 | - id="<?php echo $field->htmlvar_name;?>" | |
| 2054 | - placeholder="<?php echo $site_title; ?>" | |
| 2055 | - value="<?php echo esc_attr(stripslashes($value));?>" | |
| 2056 | - title="<?php echo $site_title; ?>" | |
| 2057 | - oninvalid="this.setCustomValidity('<?php _e($field->required_msg, 'userswp'); ?>')" | |
| 2058 | - oninput="setCustomValidity('')" | |
| 2059 | - <?php if ($field->is_required == 1) { echo 'required="required"'; } ?> | |
| 2060 | - <?php if ($field->for_admin_use == 1) { echo 'readonly="readonly"'; } ?> | |
| 2061 | - type="<?php echo $type; ?>" | |
| 2062 | - <?php if ($step) { echo 'step="'.$step.'"'; } ?> | |
| 2063 | - /> | |
| 2064 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 2065 | - <?php if ($field->is_required) { ?> | |
| 2066 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 2067 | - <?php } ?> | |
| 2068 | - </div> | |
| 4114 | + $html = ob_get_clean(); | |
| 2069 | 4115 | |
| 4116 | + } else { | |
| 4117 | + $html = '<input type="hidden" name="register_gdpr" value="-1"/>'; | |
| 4118 | + } | |
| 2070 | 4119 | |
| 2071 | - <?php | |
| 2072 | - $html = ob_get_clean(); | |
| 2073 | - } | |
| 4120 | + return $html; | |
| 4121 | + } | |
| 2074 | 4122 | |
| 2075 | - return $html; | |
| 2076 | - } | |
| 4123 | + public function form_input_register_tos( $html, $field, $value, $form_type ) { | |
| 2077 | 4124 | |
| 2078 | - /** | |
| 2079 | - * Form field template for textarea field type. | |
| 2080 | - * | |
| 2081 | - * @since 1.0.0 | |
| 2082 | - * @package userswp | |
| 2083 | - * | |
| 2084 | - * @param string $html Form field html | |
| 2085 | - * @param object $field Field info. | |
| 2086 | - * @param string $value Form field default value. | |
| 2087 | - * @param string $form_type Form type | |
| 2088 | - * | |
| 2089 | - * @return string Modified form field html. | |
| 2090 | - */ | |
| 2091 | - public function uwp_form_input_textarea($html, $field, $value, $form_type){ | |
| 4125 | + $form_id = isset( $field->form_id ) ? (int) $field->form_id : 1; | |
| 4126 | + $reg_tos = uwp_get_register_form_by( $form_id, 'tos_page' ); | |
| 4127 | + if ( empty( $reg_tos ) ) { | |
| 4128 | + $reg_tos = uwp_get_option( 'register_terms_page', false ); | |
| 4129 | + } | |
| 2092 | 4130 | |
| 2093 | - // Check if there is a field specific filter. | |
| 2094 | - if(has_filter("uwp_form_input_textarea_{$field->htmlvar_name}")){ | |
| 2095 | - $html = apply_filters("uwp_form_input_textarea_{$field->htmlvar_name}", $html, $field, $value, $form_type); | |
| 2096 | - } | |
| 4131 | + if ( ! empty( $reg_tos ) ) { | |
| 2097 | 4132 | |
| 2098 | - // If no html then we run the standard output. | |
| 2099 | - if(empty($html)) { | |
| 4133 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 4134 | + $bs_form_group = $design_style ? 'form-group mb-3 form-check' : ''; | |
| 4135 | + $bs_form_control = $design_style ? 'form-check-input' : ''; | |
| 2100 | 4136 | |
| 2101 | - ob_start(); // Start buffering; | |
| 4137 | + $site_title = uwp_get_form_label( $field ); | |
| 4138 | + $terms_page = get_permalink( $reg_tos ); | |
| 4139 | + $link_start = '<a href="' . esc_url( $terms_page ) . '" target="_blank">'; | |
| 4140 | + $link_end = '</a>'; | |
| 4141 | + $field_desc = uwp_get_field_description( $field, '' ); | |
| 4142 | + $field_desc = str_replace( '%%link_start%%', $link_start, $field_desc ); | |
| 4143 | + $field_desc = str_replace( '%%link_end%%', $link_end, $field_desc ); | |
| 4144 | + $field->htmlvar_name = 'register_tos'; | |
| 4145 | + $id = wp_doing_ajax() ? $field->htmlvar_name . '_ajax' : $field->htmlvar_name; | |
| 2102 | 4146 | |
| 2103 | - ?> | |
| 2104 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 2105 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear"> | |
| 4147 | + $content = $field_desc ? $field_desc : sprintf( __( 'I accept the %1$s %2$s %3$s.', 'userswp' ), '<a href="' . esc_url( $terms_page ) . '" target="_blank">', $site_title, '</a>' ); | |
| 4148 | + $checked = $value == '1' ? true : false; | |
| 2106 | 4149 | |
| 2107 | - <?php | |
| 2108 | - $site_title = uwp_get_form_label($field); | |
| 2109 | - if (!is_admin()) { ?> | |
| 2110 | - <label> | |
| 2111 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 2112 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 2113 | - </label> | |
| 2114 | - <?php } ?> | |
| 4150 | + ob_start(); | |
| 2115 | 4151 | |
| 2116 | - <textarea name="<?php echo $field->htmlvar_name; ?>" | |
| 2117 | - class="<?php echo $field->css_class; ?>" | |
| 2118 | - placeholder="<?php echo $site_title; ?>" | |
| 2119 | - title="<?php echo $site_title; ?>" | |
| 2120 | - oninvalid="this.setCustomValidity('<?php _e($field->required_msg, 'userswp'); ?>')" | |
| 2121 | - oninput="setCustomValidity('')" | |
| 2122 | - <?php if ($field->is_required == 1) { echo 'required="required"'; } ?> | |
| 2123 | - type="<?php echo $field->field_type; ?>" | |
| 2124 | - rows="4"><?php echo stripslashes($value); ?></textarea> | |
| 2125 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 2126 | - <?php if ($field->is_required) { ?> | |
| 2127 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 2128 | - <?php } ?> | |
| 2129 | - </div> | |
| 4152 | + if ( $design_style ) { | |
| 4153 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 4154 | + echo '<input type="hidden" name="' . esc_attr( $field->htmlvar_name ) . '" id="checkbox_' . esc_attr( $id ) . '" value="0"/>'; | |
| 2130 | 4155 | |
| 2131 | - <?php | |
| 2132 | - $html = ob_get_clean(); | |
| 2133 | - } | |
| 4156 | + echo aui()->input( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 4157 | + array( | |
| 4158 | + 'id' => esc_attr( $id ), | |
| 4159 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 4160 | + 'type' => 'checkbox', | |
| 4161 | + 'value' => '1', | |
| 4162 | + 'title' => esc_html( $site_title ), | |
| 4163 | + 'label' => wp_kses_post( $content . $required ), | |
| 4164 | + 'label_show' => true, | |
| 4165 | + 'required' => ! empty( $field->is_required ) ? true : false, | |
| 4166 | + 'checked' => (bool) $checked, | |
| 4167 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 4168 | + 'validation_text' => ! empty( $field->is_required ) ? esc_attr__( stripslashes( $field->required_msg ), 'userswp' ) : '', | |
| 4169 | + ) | |
| 4170 | + ); | |
| 2134 | 4171 | |
| 2135 | - return $html; | |
| 2136 | - } | |
| 4172 | + } else { | |
| 4173 | + ?> | |
| 4174 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 4175 | + class=" | |
| 4176 | + <?php | |
| 4177 | + if ( $field->is_required ) { | |
| 4178 | + echo 'required_field'; | |
| 4179 | + } | |
| 4180 | + ?> | |
| 4181 | + uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 4182 | + <input type="hidden" name="<?php echo esc_attr( $field->htmlvar_name ); ?>" value="0"/> | |
| 4183 | + <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 4184 | + class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>" | |
| 4185 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 4186 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 4187 | + <?php | |
| 4188 | + if ( $value == '1' ) { | |
| 4189 | + echo 'checked="checked"'; | |
| 4190 | + } | |
| 4191 | + ?> | |
| 4192 | + type="<?php echo esc_attr( $field->field_type ); ?>" | |
| 4193 | + value="1"> | |
| 4194 | + <?php | |
| 4195 | + echo ( trim( $content ) ) ? wp_kses_post( $content ) : ' '; | |
| 4196 | + ?> | |
| 4197 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 4198 | + <?php if ( $field->is_required ) { ?> | |
| 4199 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 4200 | + <?php } ?> | |
| 4201 | + </div> | |
| 2137 | 4202 | |
| 2138 | - /** | |
| 2139 | - * Form field template for fieldset field type. | |
| 2140 | - * | |
| 2141 | - * @since 1.0.0 | |
| 2142 | - * @package userswp | |
| 2143 | - * | |
| 2144 | - * @param string $html Form field html | |
| 2145 | - * @param object $field Field info. | |
| 2146 | - * @param string $value Form field default value. | |
| 2147 | - * @param string $form_type Form type | |
| 2148 | - * | |
| 2149 | - * @return string Modified form field html. | |
| 2150 | - */ | |
| 2151 | - public function uwp_form_input_fieldset($html, $field, $value, $form_type) { | |
| 2152 | - // Check if there is a custom field specific filter. | |
| 2153 | - if(has_filter("uwp_form_input_fieldset_{$field->htmlvar_name}")){ | |
| 2154 | - $html = apply_filters("uwp_form_input_fieldset_{$field->htmlvar_name}",$html, $field, $value, $form_type); | |
| 2155 | - } | |
| 4203 | + <?php | |
| 2156 | 4204 | |
| 2157 | - // If no html then we run the standard output. | |
| 2158 | - if(empty($html)) { | |
| 4205 | + } | |
| 2159 | 4206 | |
| 2160 | - ob_start(); // Start buffering; | |
| 2161 | - ?> | |
| 2162 | - <h3 class="uwp_input_fieldset <?php echo $field->css_class; ?>"> | |
| 2163 | - <?php echo $field->site_title;; ?> | |
| 2164 | - <?php if ( $field->help_text != '' ) { | |
| 2165 | - echo '<small>( ' . $field->help_text . ' )</small>'; | |
| 2166 | - } ?></h3> | |
| 2167 | - <?php | |
| 2168 | - $html = ob_get_clean(); | |
| 2169 | - } | |
| 4207 | + $html = ob_get_clean(); | |
| 2170 | 4208 | |
| 2171 | - return $html; | |
| 2172 | - } | |
| 4209 | + } else { | |
| 4210 | + $html = '<input type="hidden" name="register_tos" value="-1"/>'; | |
| 4211 | + } | |
| 2173 | 4212 | |
| 2174 | - /** | |
| 2175 | - * Form field template for url field type. | |
| 2176 | - * | |
| 2177 | - * @since 1.0.0 | |
| 2178 | - * @package userswp | |
| 2179 | - * | |
| 2180 | - * @param string $html Form field html | |
| 2181 | - * @param object $field Field info. | |
| 2182 | - * @param string $value Form field default value. | |
| 2183 | - * @param string $form_type Form type | |
| 2184 | - * | |
| 2185 | - * @return string Modified form field html. | |
| 2186 | - */ | |
| 2187 | - public function uwp_form_input_url($html, $field, $value, $form_type){ | |
| 4213 | + return $html; | |
| 4214 | + } | |
| 2188 | 4215 | |
| 4216 | + /** | |
| 4217 | + * Adds enctype tag in form for file fields. | |
| 4218 | + * | |
| 4219 | + * @return void | |
| 4220 | + * @package userswp | |
| 4221 | + * | |
| 4222 | + * @since 1.0.0 | |
| 4223 | + */ | |
| 4224 | + function add_multipart_to_admin_edit_form() { | |
| 4225 | + global $wpdb; | |
| 4226 | + $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 4227 | + $fields = $wpdb->get_results( 'SELECT * FROM ' . $table_name . " WHERE form_type = 'account' AND field_type = 'file' AND is_default = '0' ORDER BY sort_order ASC" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 4228 | + if ( $fields ) { | |
| 4229 | + echo 'enctype="multipart/form-data"'; | |
| 4230 | + } | |
| 4231 | + } | |
| 2189 | 4232 | |
| 2190 | - // Check if there is a custom field specific filter. | |
| 2191 | - if(has_filter("uwp_form_input_url_{$field->htmlvar_name}")){ | |
| 2192 | - $html = apply_filters("uwp_form_input_url_{$field->htmlvar_name}",$html, $field, $value, $form_type); | |
| 2193 | - } | |
| 4233 | + /** | |
| 4234 | + * Handles UsersWP custom field requests from admin. | |
| 4235 | + * | |
| 4236 | + * @param int $user_id User ID. | |
| 4237 | + * | |
| 4238 | + * @return void | |
| 4239 | + * @since 1.0.0 | |
| 4240 | + * @package userswp | |
| 4241 | + * | |
| 4242 | + */ | |
| 4243 | + public function update_profile_extra_admin_edit( $user_id ) { | |
| 4244 | + global $wpdb; | |
| 4245 | + $file_obj = new UsersWP_Files(); | |
| 4246 | + $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 4247 | + //Normal fields | |
| 4248 | + $fields = $wpdb->get_results( 'SELECT * FROM ' . $table_name . " WHERE form_type = 'account' AND field_type != 'file' AND field_type != 'fieldset' ORDER BY sort_order ASC" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 4249 | + if ( $fields ) { | |
| 4250 | + if ( isset( $_POST['locale'] ) ) { | |
| 4251 | + $_POST['uwp_language'] = sanitize_text_field( $_POST['locale'] ); | |
| 4252 | + } | |
| 4253 | + $result = uwp_validate_fields( $_POST, 'account', $fields ); | |
| 4254 | + if ( is_wp_error( $result ) ) { | |
| 4255 | + die( wp_kses_post( $result->get_error_message() ) ); | |
| 4256 | + } | |
| 4257 | + if ( isset( $result['display_name'] ) && ! empty( $result['display_name'] ) ) { | |
| 4258 | + $display_name = $result['display_name']; | |
| 4259 | + } elseif ( ! empty( $first_name ) || ! empty( $last_name ) ) { | |
| 4260 | + $display_name = $result['first_name'] . ' ' . $result['last_name']; | |
| 4261 | + } else { | |
| 4262 | + $user_info = get_userdata( $user_id ); | |
| 4263 | + $display_name = $user_info->user_login; | |
| 4264 | + } | |
| 4265 | + $result['display_name'] = $display_name; | |
| 4266 | + if ( ! is_wp_error( $result ) ) { | |
| 4267 | + foreach ( $fields as $field ) { | |
| 4268 | + $value = isset( $result[ $field->htmlvar_name ] ) ? $result[ $field->htmlvar_name ] : ''; | |
| 4269 | + if ( $value == '0' || ! empty( $value ) ) { | |
| 4270 | + uwp_update_usermeta( $user_id, $field->htmlvar_name, $value ); | |
| 4271 | + } | |
| 4272 | + } | |
| 4273 | + } | |
| 4274 | + } | |
| 2194 | 4275 | |
| 2195 | - // If no html then we run the standard output. | |
| 2196 | - if(empty($html)) { | |
| 4276 | + //File fields | |
| 4277 | + $fields = $wpdb->get_results( 'SELECT * FROM ' . $table_name . " WHERE form_type = 'account' AND field_type = 'file' AND is_default = '0' ORDER BY sort_order ASC" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 4278 | + if ( $fields ) { | |
| 4279 | + $result = $file_obj->validate_uploads( $_FILES, 'account', true, $fields ); | |
| 4280 | + if ( ! is_wp_error( $result ) ) { | |
| 4281 | + foreach ( $fields as $field ) { | |
| 4282 | + $value = isset( $result[ $field->htmlvar_name ] ) ? $result[ $field->htmlvar_name ] : ''; | |
| 4283 | + if ( $value == '0' || ! empty( $value ) ) { | |
| 4284 | + uwp_update_usermeta( $user_id, $field->htmlvar_name, $value ); | |
| 4285 | + } | |
| 4286 | + } | |
| 4287 | + } | |
| 4288 | + } | |
| 4289 | + } | |
| 2197 | 4290 | |
| 2198 | - ob_start(); // Start buffering; | |
| 2199 | - ?> | |
| 2200 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 2201 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear"> | |
| 4291 | + /** | |
| 4292 | + * Form field template for country field. | |
| 4293 | + * | |
| 4294 | + * @param string $html Form field html | |
| 4295 | + * @param object $field Field info. | |
| 4296 | + * @param string $value Form field default value. | |
| 4297 | + * @param string $form_type Form type | |
| 4298 | + * | |
| 4299 | + * @return string Modified form field html. | |
| 4300 | + * @package userswp | |
| 4301 | + * | |
| 4302 | + * @since 1.0.0 | |
| 4303 | + */ | |
| 4304 | + public function form_input_select_country( $html, $field, $value, $form_type ) { | |
| 2202 | 4305 | |
| 4306 | + // If no html then we run the standard output. | |
| 4307 | + if ( empty( $html ) ) { | |
| 4308 | + | |
| 4309 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 4310 | + $bs_form_group = $design_style ? 'form-group m-0' : ''; // country wrapper div added by JS adds marginso we remove ours | |
| 4311 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 4312 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 4313 | + | |
| 4314 | + ob_start(); // Start buffering; | |
| 4315 | + ?> | |
| 4316 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" class="<?php echo ( $field->is_required ? 'required_field' : '' ); ?> uwp_clear <?php echo esc_attr( $bs_form_group . ' ' . $field->css_class ); ?>"> | |
| 4317 | + | |
| 4318 | + <?php | |
| 4319 | + $site_title = uwp_get_form_label( $field ); | |
| 4320 | + | |
| 4321 | + if ( ! is_admin() && ! wp_doing_ajax() ) { | |
| 4322 | + ?> | |
| 4323 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 4324 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 4325 | + <?php | |
| 4326 | + if ( $field->is_required ) { | |
| 4327 | + echo '<span class="text-danger">*</span>'; | |
| 4328 | + } | |
| 4329 | + ?> | |
| 4330 | + </label> | |
| 4331 | + <?php | |
| 4332 | + } | |
| 4333 | + // if value empty set the default | |
| 4334 | + if ( $value == '' && isset( $field->default_value ) && $field->default_value ) { | |
| 4335 | + $value = $field->default_value; | |
| 4336 | + } | |
| 4337 | + if ( $value === false ) { | |
| 4338 | + $value = ''; | |
| 4339 | + } | |
| 4340 | + $select_country_options = wp_json_encode( array( 'defaultCountry' => wp_unslash( $value ) ) ); | |
| 4341 | + $select_country_options = apply_filters( 'uwp_form_input_select_country', $select_country_options, $field, $value, $form_type ); | |
| 4342 | + | |
| 4343 | + $htmlvar_name = $field->htmlvar_name; | |
| 4344 | + if ( wp_doing_ajax() ) { | |
| 4345 | + $htmlvar_name .= '_ajax'; | |
| 4346 | + } | |
| 4347 | + ?> | |
| 4348 | + <input type="text" class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>" title="<?php echo esc_attr( $site_title ); ?>" id="<?php echo esc_attr( $htmlvar_name ); ?>"/> | |
| 4349 | + <input type="hidden" id="<?php echo esc_attr( $htmlvar_name ); ?>_code" name="<?php echo esc_attr( $field->htmlvar_name ); ?>"/> | |
| 4350 | + <script>jQuery(function(){jQuery("#<?php echo esc_js( $htmlvar_name ); ?>").countrySelect(<?php echo wp_json_encode( json_decode( $select_country_options ) ); ?>);});</script> | |
| 4351 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 4352 | + <?php if ( $field->is_required ) { ?> | |
| 4353 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 4354 | + <?php } ?> | |
| 4355 | + </div> | |
| 4356 | + <?php | |
| 4357 | + $html = ob_get_clean(); | |
| 4358 | + } | |
| 4359 | + | |
| 4360 | + return $html; | |
| 4361 | + } | |
| 4362 | + | |
| 4363 | + /** | |
| 4364 | + * Form field template for language field. | |
| 4365 | + * | |
| 4366 | + * @param string $html Form field html | |
| 4367 | + * @param object $field Field info. | |
| 4368 | + * @param string $value Form field default value. | |
| 4369 | + * @param string $form_type Form type | |
| 4370 | + * | |
| 4371 | + * @return string Modified form field html. | |
| 4372 | + * @package userswp | |
| 4373 | + * | |
| 4374 | + * @since 1.0.0 | |
| 4375 | + */ | |
| 4376 | + public function form_input_uwp_language( $html, $field, $value, $form_type ) { | |
| 4377 | + | |
| 4378 | + // If no html then we run the standard output. | |
| 4379 | + if ( empty( $html ) ) { | |
| 4380 | + | |
| 4381 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 4382 | + $bs_form_group = $design_style ? 'form-group m-0' : ''; | |
| 4383 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 4384 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 4385 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 4386 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 4387 | + | |
| 4388 | + ob_start(); // Start buffering; | |
| 4389 | + | |
| 4390 | + ?> | |
| 4391 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 4392 | + class=" | |
| 2203 | 4393 | <?php |
| 2204 | - $site_title = uwp_get_form_label($field); | |
| 2205 | - if (!is_admin()) { ?> | |
| 2206 | - <label> | |
| 2207 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 2208 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 4394 | + if ( $field->is_required ) { | |
| 4395 | + echo 'required_field'; | |
| 4396 | + } | |
| 4397 | + ?> | |
| 4398 | + uwp_clear <?php echo esc_attr( $bs_form_group . ' ' . $field->css_class ); ?>"> | |
| 4399 | + | |
| 4400 | + <?php | |
| 4401 | + $site_title = uwp_get_form_label( $field ); | |
| 4402 | + if ( ! is_admin() && ! wp_doing_ajax() ) { | |
| 4403 | + ?> | |
| 4404 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 4405 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 4406 | + <?php | |
| 4407 | + if ( $field->is_required ) { | |
| 4408 | + echo '<span class="text-danger">*</span>'; | |
| 4409 | + } | |
| 4410 | + ?> | |
| 2209 | 4411 | </label> |
| 2210 | - <?php } ?> | |
| 4412 | + <?php } ?> | |
| 2211 | 4413 | |
| 2212 | - <input name="<?php echo $field->htmlvar_name;?>" | |
| 2213 | - class="<?php echo $field->css_class; ?> uwp_textfield" | |
| 2214 | - id="<?php echo $field->htmlvar_name;?>" | |
| 2215 | - placeholder="<?php echo $site_title; ?>" | |
| 2216 | - value="<?php echo esc_attr(stripslashes($value));?>" | |
| 2217 | - title="<?php echo $site_title; ?>" | |
| 2218 | - <?php if ($field->is_required == 1) { echo 'required="required"'; } ?> | |
| 2219 | - type="url" | |
| 2220 | - oninvalid="setCustomValidity('<?php _e('Please enter a valid URL including http://', 'userswp'); ?>')" | |
| 2221 | - onchange="try{setCustomValidity('')}catch(e){}" | |
| 2222 | - /> | |
| 2223 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 2224 | - <?php if ($field->is_required) { ?> | |
| 2225 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 2226 | - <?php } ?> | |
| 2227 | - </div> | |
| 4414 | + <?php | |
| 4415 | + if ( empty( $field->default_value ) ) { | |
| 4416 | + $field->default_value = 'site-default'; | |
| 4417 | + } | |
| 2228 | 4418 | |
| 2229 | - <?php | |
| 2230 | - $html = ob_get_clean(); | |
| 2231 | - } | |
| 4419 | + // if value empty set the default | |
| 4420 | + if ( $value == '' && isset( $field->default_value ) && $field->default_value ) { | |
| 4421 | + $value = $field->default_value; | |
| 4422 | + } | |
| 2232 | 4423 | |
| 2233 | - return $html; | |
| 2234 | - } | |
| 4424 | + require_once ABSPATH . 'wp-admin/includes/translation-install.php'; | |
| 4425 | + $translations = wp_get_available_translations(); | |
| 4426 | + $available_languages = get_available_languages(); | |
| 4427 | + $languages = array( 'site-default' => __( 'Site Default', 'userswp' ) ); | |
| 2235 | 4428 | |
| 2236 | - /** | |
| 2237 | - * Form field template for email field type. | |
| 2238 | - * | |
| 2239 | - * @since 1.0.0 | |
| 2240 | - * @package userswp | |
| 2241 | - * | |
| 2242 | - * @param string $html Form field html | |
| 2243 | - * @param object $field Field info. | |
| 2244 | - * @param string $value Form field default value. | |
| 2245 | - * @param string $form_type Form type | |
| 2246 | - * | |
| 2247 | - * @return string Modified form field html. | |
| 2248 | - */ | |
| 2249 | - public function uwp_form_input_email($html, $field, $value, $form_type){ | |
| 4429 | + foreach ( $available_languages as $locale ) { | |
| 4430 | + if ( isset( $translations[ $locale ] ) ) { | |
| 4431 | + $translation = $translations[ $locale ]; | |
| 4432 | + $languages[ $translation['language'] ] = $translation['native_name']; | |
| 2250 | 4433 | |
| 4434 | + // Remove installed language from available translations. | |
| 4435 | + unset( $translations[ $locale ] ); | |
| 4436 | + } else { | |
| 4437 | + $languages[ $locale ] = $translation[ $locale ]; | |
| 4438 | + } | |
| 4439 | + } | |
| 2251 | 4440 | |
| 2252 | - // Check if there is a custom field specific filter. | |
| 2253 | - if(has_filter("uwp_form_input_email_{$field->htmlvar_name}")){ | |
| 2254 | - $html = apply_filters("uwp_form_input_email_{$field->htmlvar_name}",$html, $field, $value, $form_type); | |
| 2255 | - } | |
| 4441 | + if ( $design_style ) { | |
| 2256 | 4442 | |
| 2257 | - // If no html then we run the standard output. | |
| 2258 | - if(empty($html)) { | |
| 4443 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 2259 | 4444 | |
| 2260 | - ob_start(); // Start buffering; | |
| 2261 | - ?> | |
| 2262 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 2263 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear"> | |
| 4445 | + echo aui()->select( | |
| 4446 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 4447 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 4448 | + 'name' => esc_attr( $field->htmlvar_name ), | |
| 4449 | + 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ), | |
| 4450 | + 'title' => esc_attr( $site_title ), | |
| 4451 | + 'value' => esc_attr( $value ), | |
| 4452 | + 'required' => (bool) $field->is_required, | |
| 4453 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 4454 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 4455 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 4456 | + 'label' => wp_kses_post( $site_title . $required ), | |
| 4457 | + 'options' => $languages, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 4458 | + 'select2' => true, | |
| 4459 | + 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', | |
| 4460 | + ) | |
| 4461 | + ); | |
| 4462 | + } else { | |
| 4463 | + ?> | |
| 4464 | + <select name="<?php echo esc_attr( $field->htmlvar_name ); ?>" id="<?php echo esc_attr( $field->htmlvar_name ); ?>" | |
| 4465 | + class="uwp_textfield aui-select2 <?php echo esc_attr( $bs_form_control ); ?>" | |
| 4466 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 4467 | + data-placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 4468 | + ><?php echo $select_options; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> | |
| 4469 | + </select> | |
| 4470 | + <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span> | |
| 4471 | + <?php if ( $field->is_required ) { ?> | |
| 4472 | + <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span> | |
| 4473 | + <?php | |
| 4474 | + } | |
| 4475 | + } | |
| 2264 | 4476 | |
| 2265 | - <?php | |
| 2266 | - $site_title = uwp_get_form_label($field); | |
| 2267 | - if (!is_admin()) { ?> | |
| 2268 | - <label> | |
| 2269 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 2270 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 2271 | - </label> | |
| 2272 | - <?php } ?> | |
| 4477 | + $html = ob_get_clean(); | |
| 4478 | + } | |
| 2273 | 4479 | |
| 2274 | - <input name="<?php echo $field->htmlvar_name;?>" | |
| 2275 | - class="<?php echo $field->css_class; ?> uwp_textfield" | |
| 2276 | - id="<?php echo $field->htmlvar_name;?>" | |
| 2277 | - placeholder="<?php echo $site_title; ?>" | |
| 2278 | - value="<?php echo esc_attr(stripslashes($value));?>" | |
| 2279 | - title="<?php echo $site_title; ?>" | |
| 2280 | - <?php if ($field->is_required == 1) { echo 'required="required"'; } ?> | |
| 2281 | - type="email" | |
| 2282 | - /> | |
| 2283 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 2284 | - <?php if ($field->is_required) { ?> | |
| 2285 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 2286 | - <?php } ?> | |
| 2287 | - </div> | |
| 4480 | + return $html; | |
| 4481 | + } | |
| 2288 | 4482 | |
| 4483 | + /** | |
| 4484 | + * Adds confirm password field in forms. | |
| 4485 | + * | |
| 4486 | + * @param string $html Form field html | |
| 4487 | + * @param object $field Field info. | |
| 4488 | + * @param string $value Form field default value. | |
| 4489 | + * @param string $form_type Form type | |
| 4490 | + * | |
| 4491 | + * @return string Modified form field html. | |
| 4492 | + * @package userswp | |
| 4493 | + * | |
| 4494 | + * @since 1.0.0 | |
| 4495 | + */ | |
| 4496 | + public function register_confirm_password_field( $html, $field, $value, $form_type ) { | |
| 4497 | + if ( $form_type == 'register' ) { | |
| 4498 | + //confirm password field | |
| 4499 | + $extra = array(); | |
| 4500 | + if ( isset( $field->extra_fields ) && $field->extra_fields != '' ) { | |
| 4501 | + $extra = unserialize( $field->extra_fields ); | |
| 4502 | + } | |
| 2289 | 4503 | |
| 2290 | - <?php | |
| 2291 | - $html = ob_get_clean(); | |
| 2292 | - } | |
| 4504 | + $enable_confirm_password_field = isset( $extra['confirm_password'] ) ? $extra['confirm_password'] : '0'; | |
| 4505 | + if ( $enable_confirm_password_field == '1' ) { | |
| 2293 | 4506 | |
| 2294 | - if(has_filter("uwp_form_input_email_{$field->htmlvar_name}_after")){ | |
| 2295 | - $html = apply_filters("uwp_form_input_email_{$field->htmlvar_name}_after",$html, $field, $value, $form_type); | |
| 2296 | - } | |
| 4507 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 4508 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 4509 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 4510 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 4511 | + $site_title = $placeholder = __( 'Confirm Password', 'userswp' ); | |
| 4512 | + $required = ''; | |
| 4513 | + if ( isset( $field->is_required ) && ! empty( $field->is_required ) ) { | |
| 4514 | + $placeholder .= ' *'; | |
| 4515 | + $required = ' <span class="text-danger">*</span>'; | |
| 4516 | + } | |
| 4517 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 4518 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 4519 | + $wrap_class = isset( $field->css_class ) ? $field->css_class . ' uwp-password-wrap' : 'uwp-password-wrap'; | |
| 2297 | 4520 | |
| 2298 | - return $html; | |
| 2299 | - } | |
| 4521 | + ob_start(); // Start buffering; | |
| 2300 | 4522 | |
| 2301 | - /** | |
| 2302 | - * Form field template for password field type. | |
| 2303 | - * | |
| 2304 | - * @since 1.0.0 | |
| 2305 | - * @package userswp | |
| 2306 | - * | |
| 2307 | - * @param string $html Form field html | |
| 2308 | - * @param object $field Field info. | |
| 2309 | - * @param string $value Form field default value. | |
| 2310 | - * @param string $form_type Form type | |
| 2311 | - * | |
| 2312 | - * @return string Modified form field html. | |
| 2313 | - */ | |
| 2314 | - public function uwp_form_input_password($html, $field, $value, $form_type){ | |
| 4523 | + if ( $design_style ) { | |
| 2315 | 4524 | |
| 4525 | + echo aui()->input( | |
| 4526 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 4527 | + 'type' => 'password', | |
| 4528 | + 'id' => 'confirm_password', | |
| 4529 | + 'name' => 'confirm_password', | |
| 4530 | + 'placeholder' => esc_attr( $placeholder ), | |
| 4531 | + 'title' => esc_attr( $site_title ), | |
| 4532 | + 'value' => esc_attr( $value ), | |
| 4533 | + 'required' => (bool) $field->is_required, | |
| 4534 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 4535 | + 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ), | |
| 4536 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 4537 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 4538 | + 'wrap_class' => esc_attr( $wrap_class ), | |
| 4539 | + ) | |
| 4540 | + ); | |
| 4541 | + } else { | |
| 4542 | + ?> | |
| 4543 | + <div id="uwp_account_confirm_password_row" | |
| 4544 | + class="<?php echo 'required_field'; ?> uwp_form_password_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 2316 | 4545 | |
| 2317 | - // Check if there is a custom field specific filter. | |
| 2318 | - if(has_filter("uwp_form_input_password_{$field->htmlvar_name}")){ | |
| 2319 | - $html = apply_filters("uwp_form_input_password_{$field->htmlvar_name}",$html, $field, $value, $form_type); | |
| 2320 | - } | |
| 4546 | + <?php | |
| 2321 | 4547 | |
| 2322 | - // If no html then we run the standard output. | |
| 2323 | - if(empty($html)) { | |
| 4548 | + if ( ! is_admin() ) { | |
| 4549 | + ?> | |
| 4550 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 4551 | + <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : ' '; ?> | |
| 4552 | + <?php | |
| 4553 | + if ( $field->is_required ) { | |
| 4554 | + echo '<span>*</span>'; | |
| 4555 | + } | |
| 4556 | + ?> | |
| 4557 | + </label> | |
| 4558 | + <?php } ?> | |
| 4559 | + <input name="confirm_password" class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>" id="uwp_account_confirm_password" placeholder="<?php echo esc_attr( $placeholder ); ?>" value="" title="<?php echo esc_attr( $site_title ); ?>" <?php echo 'required="required"'; ?> type="password"/> | |
| 4560 | + </div> | |
| 2324 | 4561 | |
| 2325 | - ob_start(); // Start buffering; | |
| 2326 | - ?> | |
| 2327 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 2328 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear"> | |
| 4562 | + <?php | |
| 4563 | + } | |
| 4564 | + $confirm_html = ob_get_clean(); | |
| 4565 | + $html = $html . $confirm_html; | |
| 4566 | + } | |
| 4567 | + } | |
| 2329 | 4568 | |
| 2330 | - <?php | |
| 2331 | - $site_title = uwp_get_form_label($field); | |
| 2332 | - if (!is_admin()) { ?> | |
| 2333 | - <label> | |
| 2334 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 2335 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 2336 | - </label> | |
| 2337 | - <?php } ?> | |
| 4569 | + return $html; | |
| 4570 | + } | |
| 2338 | 4571 | |
| 2339 | - <input name="<?php echo $field->htmlvar_name;?>" | |
| 2340 | - class="<?php echo $field->css_class; ?> uwp_textfield" | |
| 2341 | - id="<?php echo $field->htmlvar_name;?>" | |
| 2342 | - placeholder="<?php echo $site_title; ?>" | |
| 2343 | - value="<?php echo esc_attr(stripslashes($value));?>" | |
| 2344 | - title="<?php echo $site_title; ?>" | |
| 2345 | - <?php if ($field->is_required == 1) { echo 'required="required"'; } ?> | |
| 2346 | - type="password" | |
| 2347 | - /> | |
| 2348 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 2349 | - <?php if ($field->is_required) { ?> | |
| 2350 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 2351 | - <?php } ?> | |
| 2352 | - </div> | |
| 4572 | + /** | |
| 4573 | + * Adds confirm email field in forms. | |
| 4574 | + * | |
| 4575 | + * @param string $html Form field html | |
| 4576 | + * @param object $field Field info. | |
| 4577 | + * @param string $value Form field default value. | |
| 4578 | + * @param string $form_type Form type | |
| 4579 | + * | |
| 4580 | + * @return string Modified form field html. | |
| 4581 | + * @package userswp | |
| 4582 | + * | |
| 4583 | + * @since 1.0.0 | |
| 4584 | + */ | |
| 4585 | + public function register_confirm_email_field( $html, $field, $value, $form_type ) { | |
| 4586 | + if ( $form_type == 'register' ) { | |
| 4587 | + //confirm email field | |
| 4588 | + $extra = array(); | |
| 4589 | + if ( isset( $field->extra_fields ) && $field->extra_fields != '' ) { | |
| 4590 | + $extra = unserialize( $field->extra_fields ); | |
| 4591 | + } | |
| 4592 | + $enable_confirm_email_field = isset( $extra['confirm_email'] ) ? $extra['confirm_email'] : '0'; | |
| 4593 | + if ( $enable_confirm_email_field == '1' ) { | |
| 2353 | 4594 | |
| 4595 | + $design_style = uwp_get_option( 'design_style', 'bootstrap' ); | |
| 4596 | + $bs_form_group = $design_style ? 'form-group mb-3' : ''; | |
| 4597 | + $bs_sr_only = $design_style ? 'sr-only' : ''; | |
| 4598 | + $bs_form_control = $design_style ? 'form-control' : ''; | |
| 4599 | + $site_title = __( 'Confirm Email', 'userswp' ); | |
| 4600 | + $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : ''; | |
| 4601 | + $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : ''; | |
| 2354 | 4602 | |
| 2355 | - <?php | |
| 2356 | - $html = ob_get_clean(); | |
| 2357 | - } | |
| 4603 | + ob_start(); | |
| 2358 | 4604 | |
| 2359 | - if(has_filter("uwp_form_input_password_{$field->htmlvar_name}_after")){ | |
| 2360 | - $html = apply_filters("uwp_form_input_password_{$field->htmlvar_name}_after",$html, $field, $value, $form_type); | |
| 2361 | - } | |
| 4605 | + if ( $design_style ) { | |
| 4606 | + $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : ''; | |
| 2362 | 4607 | |
| 2363 | - return $html; | |
| 2364 | - } | |
| 4608 | + echo aui()->input( | |
| 4609 | + array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 4610 | + 'type' => 'email', | |
| 4611 | + 'id' => esc_attr( $field->htmlvar_name ), | |
| 4612 | + 'name' => 'confirm_email', | |
| 4613 | + 'placeholder' => esc_attr( $site_title ), | |
| 4614 | + 'title' => esc_attr( $site_title ), | |
| 4615 | + 'value' => esc_attr( $value ), | |
| 4616 | + 'required' => (bool) $field->is_required, | |
| 4617 | + 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ), | |
| 4618 | + 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ), | |
| 4619 | + 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ), | |
| 4620 | + 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '', | |
| 4621 | + ) | |
| 4622 | + ); | |
| 4623 | + } else { | |
| 4624 | + ?> | |
| 4625 | + <div id="uwp_account_confirm_email_row" | |
| 4626 | + class="<?php echo 'required_field'; ?> uwp_form_email_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 2365 | 4627 | |
| 2366 | - /** | |
| 2367 | - * Adds enctype tag in form for file fields. | |
| 2368 | - * | |
| 2369 | - * @since 1.0.0 | |
| 2370 | - * @package userswp | |
| 2371 | - * | |
| 2372 | - * @return void | |
| 2373 | - */ | |
| 2374 | - function add_multipart_to_admin_edit_form() { | |
| 2375 | - global $wpdb; | |
| 2376 | - $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 2377 | - $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND field_type = 'file' AND is_default = '0' ORDER BY sort_order ASC"); | |
| 2378 | - if ($fields) { | |
| 2379 | - echo 'enctype="multipart/form-data"'; | |
| 2380 | - } | |
| 2381 | - } | |
| 4628 | + <?php | |
| 2382 | 4629 | |
| 2383 | - /** | |
| 2384 | - * Handles UsersWP custom field requests from admin. | |
| 2385 | - * | |
| 2386 | - * @since 1.0.0 | |
| 2387 | - * @package userswp | |
| 2388 | - * | |
| 2389 | - * @param int $user_id User ID. | |
| 2390 | - * | |
| 2391 | - * @return void | |
| 2392 | - */ | |
| 2393 | - public function update_profile_extra_admin_edit($user_id) { | |
| 2394 | - global $wpdb; | |
| 2395 | - $file_obj = new UsersWP_Files(); | |
| 2396 | - $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 2397 | - //Normal fields | |
| 2398 | - $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND field_type != 'file' AND field_type != 'fieldset' ORDER BY sort_order ASC"); | |
| 2399 | - if ($fields) { | |
| 2400 | - $_POST['uwp_account_first_name'] = $_POST['first_name']; | |
| 2401 | - $_POST['uwp_account_last_name'] = $_POST['last_name']; | |
| 2402 | - $_POST['uwp_account_display_name'] = $_POST['nickname']; | |
| 2403 | - $_POST['uwp_account_email'] = $_POST['email']; | |
| 2404 | - $_POST['uwp_account_bio'] = $_POST['description']; | |
| 2405 | - $result = uwp_validate_fields($_POST, 'account', $fields); | |
| 2406 | - if (isset($result['uwp_account_display_name']) && !empty($result['uwp_account_display_name'])) { | |
| 2407 | - $display_name = $result['uwp_account_display_name']; | |
| 2408 | - } else { | |
| 2409 | - if (!empty($first_name) || !empty($last_name)) { | |
| 2410 | - $display_name = $result['uwp_account_first_name'] . ' ' . $result['uwp_account_last_name']; | |
| 2411 | - } else { | |
| 2412 | - $user_info = get_userdata($user_id); | |
| 2413 | - $display_name = $user_info->user_login; | |
| 2414 | - } | |
| 2415 | - } | |
| 2416 | - $result['uwp_account_display_name'] = $display_name; | |
| 2417 | - if (!is_wp_error($result)) { | |
| 2418 | - foreach ($fields as $field) { | |
| 2419 | - $value = isset($result[$field->htmlvar_name]) ? $result[$field->htmlvar_name] : ''; | |
| 2420 | - if ($value == '0' || !empty($value)) { | |
| 2421 | - uwp_update_usermeta($user_id, $field->htmlvar_name, $value); | |
| 2422 | - } | |
| 2423 | - } | |
| 2424 | - } | |
| 2425 | - } | |
| 4630 | + if ( ! is_admin() ) { | |
| 4631 | + ?> | |
| 4632 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 4633 | + <?php echo ( trim( $site_title ) ) ? esc_attr( $site_title ) : ' '; ?> | |
| 4634 | + <?php | |
| 4635 | + if ( $field->is_required ) { | |
| 4636 | + echo '<span>*</span>'; | |
| 4637 | + } | |
| 4638 | + ?> | |
| 4639 | + </label> | |
| 4640 | + <?php } ?> | |
| 2426 | 4641 | |
| 2427 | - //File fields | |
| 2428 | - $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND field_type = 'file' AND is_default = '0' ORDER BY sort_order ASC"); | |
| 2429 | - if ($fields) { | |
| 2430 | - $result = $file_obj->uwp_validate_uploads($_FILES, 'account', true, $fields); | |
| 2431 | - if (!is_wp_error($result)) { | |
| 2432 | - foreach ($fields as $field) { | |
| 2433 | - $value = $result[$field->htmlvar_name]; | |
| 2434 | - if ($value == '0' || !empty($value)) { | |
| 2435 | - uwp_update_usermeta($user_id, $field->htmlvar_name, $value); | |
| 2436 | - } | |
| 2437 | - } | |
| 2438 | - } | |
| 2439 | - } | |
| 2440 | - } | |
| 4642 | + <input name="confirm_email" | |
| 4643 | + class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>" | |
| 4644 | + id="uwp_account_confirm_email" | |
| 4645 | + placeholder="<?php echo esc_attr( $site_title ); ?>" | |
| 4646 | + value="" | |
| 4647 | + title="<?php echo esc_attr( $site_title ); ?>" | |
| 4648 | + <?php echo 'required="required"'; ?> | |
| 4649 | + type="email" | |
| 4650 | + /> | |
| 4651 | + </div> | |
| 4652 | + <?php | |
| 4653 | + } | |
| 4654 | + $confirm_html = ob_get_clean(); | |
| 4655 | + $html = $html . $confirm_html; | |
| 4656 | + } | |
| 4657 | + } | |
| 2441 | 4658 | |
| 4659 | + return $html; | |
| 4660 | + } | |
| 2442 | 4661 | |
| 2443 | - /** | |
| 2444 | - * Adds search form keyword input html. | |
| 2445 | - * | |
| 2446 | - * @since 1.0.0 | |
| 2447 | - * @package userswp | |
| 2448 | - * | |
| 2449 | - * @param string $keyword Search keyword. | |
| 2450 | - * | |
| 2451 | - * @return void | |
| 2452 | - */ | |
| 2453 | - public function uwp_users_search_form_text_field($keyword) { | |
| 2454 | - ?> | |
| 2455 | - <input placeholder="Search For" name="uwps" value="<?php echo $keyword; ?>" class="s search-input" type="text"> | |
| 2456 | - <?php | |
| 2457 | - } | |
| 4662 | + /** | |
| 4663 | + * Handles the privacy form submission. | |
| 4664 | + * | |
| 4665 | + * @return void | |
| 4666 | + * @package userswp | |
| 4667 | + * | |
| 4668 | + * @since 1.0.0 | |
| 4669 | + */ | |
| 4670 | + public function privacy_submit_handler() { | |
| 4671 | + if ( isset( $_POST['uwp_privacy_submit'] ) ) { | |
| 4672 | + if ( ! isset( $_POST['uwp_privacy_nonce'] ) || ! wp_verify_nonce( $_POST['uwp_privacy_nonce'], 'uwp-privacy-nonce' ) ) { | |
| 4673 | + return; | |
| 4674 | + } | |
| 2458 | 4675 | |
| 2459 | - /** | |
| 2460 | - * Adds search form submit button html. | |
| 2461 | - * | |
| 2462 | - * @since 1.0.0 | |
| 2463 | - * @package userswp | |
| 2464 | - * | |
| 2465 | - * @return void | |
| 2466 | - */ | |
| 2467 | - public function uwp_users_search_form_submit() { | |
| 2468 | - ?> | |
| 2469 | - <input class="uwp-searchsubmit uwp-search-submit" value="Search" type="submit"> | |
| 2470 | - <?php | |
| 2471 | - } | |
| 4676 | + global $wpdb, $uwp_notices; | |
| 2472 | 4677 | |
| 2473 | - /** | |
| 2474 | - * Checks for errors in mail submission. | |
| 2475 | - * | |
| 2476 | - * @since 1.0.0 | |
| 2477 | - * @package userswp | |
| 2478 | - * | |
| 2479 | - * @param array $res Result array. | |
| 2480 | - * @param object $user_data User object. | |
| 2481 | - * @param WP_Error $errors Error object | |
| 2482 | - * | |
| 2483 | - * @return WP_Error|array Error object when error. Result array when success. | |
| 2484 | - */ | |
| 2485 | - public function uwp_forms_check_for_send_mail_errors($res, $user_data, $errors) { | |
| 2486 | - if (!$res) { | |
| 2487 | - if (get_option('admin_email') == $user_data->user_email) { | |
| 2488 | - $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong when sending email. Please check your site error log for more details.', 'userswp')); | |
| 2489 | - } else { | |
| 2490 | - $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong when sending email. Please contact site admin.', 'userswp')); | |
| 2491 | - } | |
| 2492 | - } | |
| 4678 | + // Save fields privacy settings | |
| 4679 | + $extra_where = "AND is_public='2'"; | |
| 4680 | + $fields = get_account_form_fields( $extra_where ); | |
| 4681 | + $fields = apply_filters( 'uwp_account_privacy_fields', $fields ); | |
| 4682 | + $user_id = get_current_user_id(); | |
| 4683 | + $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta'; | |
| 2493 | 4684 | |
| 2494 | - $error_code = $errors->get_error_code(); | |
| 2495 | - if (!empty($error_code)) { | |
| 2496 | - return $errors; | |
| 2497 | - } else { | |
| 2498 | - return $res; | |
| 2499 | - } | |
| 2500 | - | |
| 2501 | - } | |
| 4685 | + $user_meta_info = $wpdb->get_row( $wpdb->prepare( "SELECT user_privacy, tabs_privacy FROM $meta_table WHERE user_id = %d", $user_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 4686 | + if ( ! empty( $user_meta_info->user_privacy ) ) { | |
| 4687 | + $public_fields = explode( ',', $user_meta_info->user_privacy ); | |
| 4688 | + } else { | |
| 4689 | + $public_fields = array(); | |
| 4690 | + } | |
| 2502 | 4691 | |
| 2503 | - /** | |
| 2504 | - * Form field template for country field. | |
| 2505 | - * | |
| 2506 | - * @since 1.0.0 | |
| 2507 | - * @package userswp | |
| 2508 | - * | |
| 2509 | - * @param string $html Form field html | |
| 2510 | - * @param object $field Field info. | |
| 2511 | - * @param string $value Form field default value. | |
| 2512 | - * @param string $form_type Form type | |
| 2513 | - * | |
| 2514 | - * @return string Modified form field html. | |
| 2515 | - */ | |
| 2516 | - public function uwp_form_input_select_country($html, $field, $value, $form_type){ | |
| 4692 | + if ( $fields ) { | |
| 2517 | 4693 | |
| 2518 | - // Check if there is a field specific filter. | |
| 2519 | - if(has_filter("uwp_form_input_html_select_{$field->htmlvar_name}")){ | |
| 2520 | - $html = apply_filters("uwp_form_input_html_select_{$field->htmlvar_name}", $html, $field, $value, $form_type); | |
| 2521 | - } | |
| 4694 | + foreach ( $fields as $field ) { | |
| 4695 | + $field_name = $field->htmlvar_name . '_privacy'; | |
| 4696 | + $field_value = strip_tags( esc_sql( $_POST[ $field_name ] ) ); | |
| 2522 | 4697 | |
| 2523 | - //print_r($field); | |
| 4698 | + if ( $field_value == 'no' ) { | |
| 4699 | + if ( ! in_array( $field_name, $public_fields ) ) { | |
| 4700 | + $public_fields[] = $field_name; | |
| 4701 | + } | |
| 4702 | + } elseif ( ( $field_name = array_search( $field_name, $public_fields ) ) !== false ) { | |
| 4703 | + unset( $public_fields[ $field_name ] ); | |
| 4704 | + } | |
| 4705 | + } | |
| 2524 | 4706 | |
| 2525 | - // If no html then we run the standard output. | |
| 2526 | - if(empty($html)) { | |
| 4707 | + $value = implode( ',', $public_fields ); | |
| 4708 | + uwp_update_usermeta( $user_id, 'user_privacy', $value ); | |
| 4709 | + } | |
| 2527 | 4710 | |
| 2528 | - ob_start(); // Start buffering; | |
| 4711 | + // Save tabs privacy settings | |
| 4712 | + $tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs'; | |
| 4713 | + $tabs = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $tabs_table_name . ' WHERE form_type=%s AND user_decided = 1 ORDER BY sort_order ASC', 'profile-tabs' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 2529 | 4714 | |
| 2530 | - ?> | |
| 2531 | - <div id="<?php echo $field->htmlvar_name;?>_row" | |
| 2532 | - class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row uwp_clear"> | |
| 4715 | + if ( $tabs ) { | |
| 4716 | + $public_fields = maybe_unserialize( $user_meta_info->tabs_privacy ); | |
| 4717 | + $do_tabs_update = false; | |
| 4718 | + foreach ( $tabs as $tab ) { | |
| 4719 | + $field_name = $tab->tab_key . '_tab_privacy'; | |
| 2533 | 4720 | |
| 2534 | - <?php | |
| 2535 | - $site_title = uwp_get_form_label($field); | |
| 2536 | - if (!is_admin()) { ?> | |
| 2537 | - <label> | |
| 2538 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 2539 | - <?php if ($field->is_required) echo '<span>*</span>';?> | |
| 2540 | - </label> | |
| 2541 | - <?php } ?> | |
| 4721 | + if ( isset( $_POST[ $field_name ] ) ) { | |
| 4722 | + $do_tabs_update = true; | |
| 4723 | + $field_value = $_POST[ $field_name ] == '' ? '' : absint( $_POST[ $field_name ] ); | |
| 2542 | 4724 | |
| 2543 | - <?php | |
| 2544 | - // if value empty set the default | |
| 2545 | - if($value=='' && isset($field->default_value) && $field->default_value){ | |
| 2546 | - $value = $field->default_value; | |
| 2547 | - } | |
| 2548 | - $select_country_options = apply_filters('uwp_form_input_select_country',"{defaultCountry: '$value'}",$field, $value, $form_type); | |
| 2549 | - ?> | |
| 4725 | + if ( $field_value === '' && isset( $public_fields[ $field_name ] ) ) { | |
| 4726 | + unset( $public_fields[ $field_name ] ); | |
| 4727 | + } else { | |
| 4728 | + $public_fields[ $field_name ] = $field_value; | |
| 4729 | + } | |
| 4730 | + } | |
| 4731 | +} | |
| 2550 | 4732 | |
| 2551 | - <input type="text" class="uwp_textfield" title="<?php echo $site_title; ?>" id="<?php echo $field->htmlvar_name;?>" /> | |
| 2552 | - <input type="hidden" id="<?php echo $field->htmlvar_name;?>_code" name="<?php echo $field->htmlvar_name;?>" /> | |
| 4733 | + if ( $do_tabs_update ) { | |
| 4734 | + uwp_update_usermeta( $user_id, 'tabs_privacy', maybe_serialize( $public_fields ) ); | |
| 4735 | + } | |
| 4736 | + } | |
| 2553 | 4737 | |
| 2554 | - <script> | |
| 2555 | - jQuery("#<?php echo $field->htmlvar_name;?>").countrySelect(<?php echo $select_country_options;?>); | |
| 2556 | - </script> | |
| 4738 | + if ( isset( $_POST['uwp_hide_from_listing'] ) && 1 == $_POST['uwp_hide_from_listing'] ) { | |
| 4739 | + update_user_meta( $user_id, 'uwp_hide_from_listing', 1 ); | |
| 4740 | + } else { | |
| 4741 | + update_user_meta( $user_id, 'uwp_hide_from_listing', 0 ); | |
| 4742 | + } | |
| 2557 | 4743 | |
| 4744 | + $make_profile_private = uwp_can_make_profile_private(); | |
| 4745 | + if ( $make_profile_private ) { | |
| 4746 | + $field_name = 'uwp_make_profile_private'; | |
| 4747 | + if ( isset( $_POST[ $field_name ] ) ) { | |
| 4748 | + $value = strip_tags( esc_sql( $_POST[ $field_name ] ) ); | |
| 4749 | + $user_id = get_current_user_id(); | |
| 4750 | + update_user_meta( $user_id, $field_name, $value ); | |
| 4751 | + } | |
| 4752 | + } | |
| 2558 | 4753 | |
| 2559 | - <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span> | |
| 2560 | - <?php if ($field->is_required) { ?> | |
| 2561 | - <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span> | |
| 2562 | - <?php } ?> | |
| 2563 | - </div> | |
| 4754 | + $message = apply_filters( 'uwp_privacy_update_success_message', __( 'Privacy settings updated successfully.', 'userswp' ) ); | |
| 4755 | + $message = aui()->alert( | |
| 4756 | + array( | |
| 4757 | + 'type' => 'success', | |
| 4758 | + 'content' => $message, | |
| 4759 | + ) | |
| 4760 | + ); | |
| 4761 | + $uwp_notices[] = array( 'account' => $message ); | |
| 2564 | 4762 | |
| 2565 | - <?php | |
| 2566 | - $html = ob_get_clean(); | |
| 4763 | + } | |
| 4764 | + } | |
| 4765 | + | |
| 4766 | + /** | |
| 4767 | + * Get the ajax login form. | |
| 4768 | + * | |
| 4769 | + * @since 1.2.0 | |
| 4770 | + */ | |
| 4771 | + public function ajax_login_form() { | |
| 4772 | + | |
| 4773 | + // add the modal error container | |
| 4774 | + add_action( 'uwp_template_display_notices', array( $this, 'modal_error_container' ) ); | |
| 4775 | + | |
| 4776 | + $args = array( | |
| 4777 | + 'form_title' => __( 'Login', 'userswp' ), | |
| 4778 | + ); | |
| 4779 | + | |
| 4780 | + // get the form | |
| 4781 | + ob_start(); | |
| 4782 | + uwp_get_template( 'bootstrap/login.php', $args ); | |
| 4783 | + $form = ob_get_clean(); | |
| 4784 | + | |
| 4785 | + // bs5 | |
| 4786 | + if ( function_exists( 'aui_bs_convert_sd_output' ) ) { | |
| 4787 | + $form = aui_bs_convert_sd_output( $form ); | |
| 2567 | 4788 | } |
| 4789 | + // send ajax response | |
| 4790 | + wp_send_json_success( $form ); | |
| 4791 | + } | |
| 2568 | 4792 | |
| 2569 | - return $html; | |
| 2570 | - } | |
| 4793 | + /** | |
| 4794 | + * Get the ajax register form. | |
| 4795 | + * | |
| 4796 | + * @since 1.2.0 | |
| 4797 | + */ | |
| 4798 | + public function ajax_register_form() { | |
| 2571 | 4799 | |
| 2572 | - /** | |
| 2573 | - * Prints the username link in "Edit Account" page | |
| 2574 | - * | |
| 2575 | - * @since 1.0.0 | |
| 2576 | - * @package userswp | |
| 2577 | - * | |
| 2578 | - * @param string $type Page type. | |
| 2579 | - * | |
| 2580 | - * @return void | |
| 2581 | - */ | |
| 2582 | - public function uwp_display_username_in_account($type) { | |
| 2583 | - if ($type == 'account') { | |
| 2584 | - $user_id = get_current_user_id(); | |
| 2585 | - $user_info = get_userdata($user_id); | |
| 2586 | - $display_name = $user_info->user_login; | |
| 2587 | - ?> | |
| 2588 | - <span class="uwp_account_page_username"> | |
| 2589 | - <a href="<?php echo uwp_build_profile_tab_url($user_id); ?>">( @<?php echo $display_name; ?> )</a> | |
| 2590 | - </span> | |
| 2591 | - <?php | |
| 2592 | - } | |
| 2593 | - } | |
| 4800 | + // add the modal error container | |
| 4801 | + add_action( 'uwp_template_display_notices', array( $this, 'modal_error_container' ) ); | |
| 2594 | 4802 | |
| 4803 | + global $wp_scripts; | |
| 4804 | + if ( empty( $wp_scripts ) ) { | |
| 4805 | + $wp_scripts = wp_scripts(); | |
| 4806 | + } | |
| 2595 | 4807 | |
| 2596 | - /** | |
| 2597 | - * Adds confirm password field in forms. | |
| 2598 | - * | |
| 2599 | - * @since 1.0.0 | |
| 2600 | - * @package userswp | |
| 2601 | - * | |
| 2602 | - * @param string $html Form field html | |
| 2603 | - * @param object $field Field info. | |
| 2604 | - * @param string $value Form field default value. | |
| 2605 | - * @param string $form_type Form type | |
| 2606 | - * | |
| 2607 | - * @return string Modified form field html. | |
| 2608 | - */ | |
| 2609 | - public function uwp_register_confirm_password_field($html, $field, $value, $form_type) { | |
| 2610 | - if ($form_type == 'register') { | |
| 2611 | - //confirm password field | |
| 2612 | - $extra = array(); | |
| 2613 | - if (isset($field->extra_fields) && $field->extra_fields != '') { | |
| 2614 | - $extra = unserialize($field->extra_fields); | |
| 2615 | - } | |
| 2616 | - $enable_confirm_password_field = isset($extra['confirm_password']) ? $extra['confirm_password'] : '0'; | |
| 2617 | - if ($enable_confirm_password_field == '1') { | |
| 2618 | - ob_start(); // Start buffering; | |
| 2619 | - ?> | |
| 2620 | - <div id="uwp_account_confirm_password_row" | |
| 2621 | - class="<?php echo 'required_field';?> uwp_form_password_row uwp_clear"> | |
| 4808 | + // do we need country code script in ajax? | |
| 4809 | + $country_field = false; | |
| 4810 | + $lightbox_forms = uwp_get_option( 'register_modal_form', 1 ); | |
| 2622 | 4811 | |
| 2623 | - <?php | |
| 2624 | - $site_title = __("Confirm Password", 'userswp'); | |
| 2625 | - if (!is_admin()) { ?> | |
| 2626 | - <label> | |
| 2627 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 2628 | - <?php echo '<span>*</span>'; ?> | |
| 2629 | - </label> | |
| 2630 | - <?php } ?> | |
| 4812 | + if ( isset( $_POST['form_id'] ) && ! empty( $_POST['form_id'] ) ) { | |
| 4813 | + $form_id = (int)$_POST['form_id']; | |
| 4814 | + } elseif ( is_array( $lightbox_forms ) && count( $lightbox_forms ) > 0 ) { | |
| 4815 | + $form_id = reset( $lightbox_forms ); | |
| 4816 | + } else { | |
| 4817 | + $form_id = 1; | |
| 4818 | + } | |
| 2631 | 4819 | |
| 2632 | - <input name="uwp_account_confirm_password" | |
| 2633 | - class="uwp_textfield" | |
| 2634 | - id="uwp_account_confirm_password" | |
| 2635 | - placeholder="<?php echo $site_title; ?>" | |
| 2636 | - value="" | |
| 2637 | - title="<?php echo $site_title; ?>" | |
| 2638 | - <?php echo 'required="required"'; ?> | |
| 2639 | - type="password" | |
| 2640 | - /> | |
| 2641 | - </div> | |
| 4820 | + $fields = get_register_form_fields( $form_id ); | |
| 4821 | + if ( ! empty( $fields ) ) { | |
| 4822 | + foreach ( $fields as $field ) { | |
| 4823 | + if ( $field->field_type_key == 'country' || $field->field_type_key == 'uwp_country' ) { | |
| 4824 | + $country_field = true; | |
| 4825 | + } | |
| 4826 | + } | |
| 4827 | + } | |
| 2642 | 4828 | |
| 2643 | - <?php | |
| 2644 | - $confirm_html = ob_get_clean(); | |
| 2645 | - $html = $html.$confirm_html; | |
| 2646 | - } | |
| 2647 | - } | |
| 2648 | - return $html; | |
| 2649 | - } | |
| 4829 | + ob_start(); | |
| 2650 | 4830 | |
| 2651 | - /** | |
| 2652 | - * Adds confirm email field in forms. | |
| 2653 | - * | |
| 2654 | - * @since 1.0.0 | |
| 2655 | - * @package userswp | |
| 2656 | - * | |
| 2657 | - * @param string $html Form field html | |
| 2658 | - * @param object $field Field info. | |
| 2659 | - * @param string $value Form field default value. | |
| 2660 | - * @param string $form_type Form type | |
| 2661 | - * | |
| 2662 | - * @return string Modified form field html. | |
| 2663 | - */ | |
| 2664 | - public function uwp_register_confirm_email_field($html, $field, $value, $form_type) { | |
| 2665 | - if ($form_type == 'register') { | |
| 2666 | - //confirm email field | |
| 2667 | - $extra = array(); | |
| 2668 | - if (isset($field->extra_fields) && $field->extra_fields != '') { | |
| 2669 | - $extra = unserialize($field->extra_fields); | |
| 2670 | - } | |
| 2671 | - $enable_confirm_email_field = isset($extra['confirm_email']) ? $extra['confirm_email'] : '0'; | |
| 2672 | - if ($enable_confirm_email_field == '1') { | |
| 2673 | - ob_start(); // Start buffering; | |
| 2674 | - ?> | |
| 2675 | - <div id="uwp_account_confirm_email_row" | |
| 2676 | - class="<?php echo 'required_field';?> uwp_form_email_row uwp_clear"> | |
| 4831 | + // maybe add country code JS | |
| 4832 | + if ( $country_field ) { | |
| 4833 | + $country_data = uwp_get_country_data(); | |
| 4834 | + echo '<script>var uwp_country_data = ' . json_encode( $country_data ) . '</script>'; | |
| 4835 | + echo "<script type='text/javascript' src='" . esc_url( USERSWP_PLUGIN_URL ) . 'assets/js/countrySelect.min.js' . "' ></script>"; | |
| 4836 | + } | |
| 2677 | 4837 | |
| 2678 | - <?php | |
| 2679 | - $site_title = __("Confirm Email", 'userswp'); | |
| 2680 | - if (!is_admin()) { ?> | |
| 2681 | - <label> | |
| 2682 | - <?php echo (trim($site_title)) ? $site_title : ' '; ?> | |
| 2683 | - <?php echo '<span>*</span>'; ?> | |
| 2684 | - </label> | |
| 2685 | - <?php } ?> | |
| 4838 | + $args = array( 'form_title' => '' ); | |
| 4839 | + if ( $form_id > 0 ) { | |
| 4840 | + $args['id'] = $form_id; | |
| 4841 | + } | |
| 2686 | 4842 | |
| 2687 | - <input name="uwp_account_confirm_email" | |
| 2688 | - class="uwp_textfield" | |
| 2689 | - id="uwp_account_confirm_email" | |
| 2690 | - placeholder="<?php echo $site_title; ?>" | |
| 2691 | - value="" | |
| 2692 | - title="<?php echo $site_title; ?>" | |
| 2693 | - <?php echo 'required="required"'; ?> | |
| 2694 | - type="email" | |
| 2695 | - /> | |
| 2696 | - </div> | |
| 4843 | + $args['limit'] = $lightbox_forms; | |
| 2697 | 4844 | |
| 2698 | - <?php | |
| 2699 | - $confirm_html = ob_get_clean(); | |
| 2700 | - $html = $html.$confirm_html; | |
| 2701 | - } | |
| 4845 | + // get template | |
| 4846 | + uwp_get_template( 'bootstrap/register.php', $args ); | |
| 4847 | + | |
| 4848 | + // only show the JS if NOT doing a block render | |
| 4849 | + if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] != 'super_duper_output_shortcode' ) { | |
| 4850 | + // load scripts | |
| 4851 | + $wp_scripts->do_item( 'zxcvbn-async' ); | |
| 4852 | + $wp_scripts->do_item( 'wp-hooks' ); | |
| 4853 | + $wp_scripts->do_item( 'wp-i18n' ); | |
| 4854 | + $wp_scripts->do_item( 'password-strength-meter' ); | |
| 4855 | + ?> | |
| 4856 | + <script> | |
| 4857 | + // Password strength indicator script | |
| 4858 | + jQuery(function ($) { | |
| 4859 | + | |
| 4860 | + // Load the settings like WP does. | |
| 4861 | + var first, s; | |
| 4862 | + s = document.createElement('script'); | |
| 4863 | + s.src = _zxcvbnSettings.src; | |
| 4864 | + s.type = 'text/javascript'; | |
| 4865 | + s.async = true; | |
| 4866 | + first = document.getElementsByTagName('script')[0]; | |
| 4867 | + first.parentNode.insertBefore(s, first); | |
| 4868 | + | |
| 4869 | + // Enable any pass inputs. | |
| 4870 | + $('body').on('keyup', 'input[name=password], input[name=confirm_password]', | |
| 4871 | + function (event) { | |
| 4872 | + var $form = $(this).closest('form'); | |
| 4873 | + if( ! $form.hasClass('uwp-login-form') ) { | |
| 4874 | + uwp_checkPasswordStrength( | |
| 4875 | + $('input[name=password]', $form), // First password field | |
| 4876 | + $('input[name=confirm_password]', $form), // Second password field | |
| 4877 | + $('#uwp-password-strength', $form), // Strength meter | |
| 4878 | + $('input[type=submit]', $form), // Submit button | |
| 4879 | + ['black', 'listed', 'word'] // Blacklisted words | |
| 4880 | + ); | |
| 4881 | + } | |
| 4882 | + } | |
| 4883 | + ); | |
| 4884 | + }); | |
| 4885 | + </script> | |
| 4886 | + <?php | |
| 4887 | + } | |
| 4888 | + $form = ob_get_clean(); | |
| 4889 | + | |
| 4890 | + // bs5 | |
| 4891 | + if ( function_exists( 'aui_bs_convert_sd_output' ) ) { | |
| 4892 | + $form = aui_bs_convert_sd_output( $form ); | |
| 2702 | 4893 | } |
| 2703 | - return $html; | |
| 2704 | - } | |
| 2705 | 4894 | |
| 4895 | + // send ajax response | |
| 4896 | + wp_send_json_success( $form ); | |
| 4897 | + } | |
| 2706 | 4898 | |
| 2707 | - /** | |
| 2708 | - * Handles the privacy form submission. | |
| 2709 | - * | |
| 2710 | - * @since 1.0.0 | |
| 2711 | - * @package userswp | |
| 2712 | - * | |
| 2713 | - * @return void | |
| 2714 | - */ | |
| 2715 | - public function uwp_privacy_submit_handler() { | |
| 2716 | - if (isset($_POST['uwp_privacy_submit'])) { | |
| 2717 | - if( ! isset( $_POST['uwp_privacy_nonce'] ) || ! wp_verify_nonce( $_POST['uwp_privacy_nonce'], 'uwp-privacy-nonce' ) ) { | |
| 2718 | - return; | |
| 2719 | - } | |
| 4899 | + /** | |
| 4900 | + * Get the ajax forgot password form. | |
| 4901 | + * | |
| 4902 | + * @since 1.2.0 | |
| 4903 | + */ | |
| 4904 | + public function ajax_forgot_password_form() { | |
| 2720 | 4905 | |
| 2721 | - $extra_where = "AND is_public='2'"; | |
| 2722 | - $fields = get_account_form_fields($extra_where); | |
| 2723 | - $fields = apply_filters('uwp_account_privacy_fields', $fields); | |
| 2724 | - if ($fields) { | |
| 2725 | - foreach ($fields as $field) { | |
| 2726 | - $field_name = $field->htmlvar_name.'_privacy'; | |
| 2727 | - if (isset($_POST[$field_name])) { | |
| 2728 | - $value = strip_tags(esc_sql($_POST[$field_name])); | |
| 2729 | - $user_id = get_current_user_id(); | |
| 2730 | - uwp_update_usermeta($user_id, $field_name, $value); | |
| 2731 | - } | |
| 2732 | - } | |
| 2733 | - } | |
| 4906 | + // add the modal error container | |
| 4907 | + add_action( 'uwp_template_display_notices', array( $this, 'modal_error_container' ) ); | |
| 2734 | 4908 | |
| 2735 | - $user_id = get_current_user_id(); | |
| 2736 | - if (isset($_POST['uwp_hide_from_listing']) && 1 == $_POST['uwp_hide_from_listing']) { | |
| 2737 | - update_user_meta($user_id, 'uwp_hide_from_listing', 1); | |
| 2738 | - } else { | |
| 2739 | - update_user_meta($user_id, 'uwp_hide_from_listing', 0); | |
| 2740 | - } | |
| 4909 | + // get the form | |
| 4910 | + ob_start(); | |
| 4911 | + uwp_get_template( 'bootstrap/forgot.php' ); | |
| 4912 | + $form = ob_get_clean(); | |
| 2741 | 4913 | |
| 2742 | - $make_profile_private = uwp_can_make_profile_private(); | |
| 2743 | - if ($make_profile_private) { | |
| 2744 | - $field_name = 'uwp_make_profile_private'; | |
| 2745 | - if (isset($_POST[$field_name])) { | |
| 2746 | - $value = strip_tags(esc_sql($_POST[$field_name])); | |
| 2747 | - $user_id = get_current_user_id(); | |
| 2748 | - update_user_meta($user_id, $field_name, $value); | |
| 2749 | - } | |
| 2750 | - } | |
| 4914 | + // bs5 | |
| 4915 | + if ( function_exists( 'aui_bs_convert_sd_output' ) ) { | |
| 4916 | + $form = aui_bs_convert_sd_output( $form ); | |
| 4917 | + } | |
| 2751 | 4918 | |
| 2752 | - } | |
| 2753 | - } | |
| 4919 | + // send ajax response | |
| 4920 | + wp_send_json_success( $form ); | |
| 4921 | + } | |
| 2754 | 4922 | |
| 2755 | -} | |
| 4923 | + /** | |
| 4924 | + * Output the modal error container. | |
| 4925 | + * | |
| 4926 | + * @param string $type | |
| 4927 | + * | |
| 4928 | + * @since 1.2.0 | |
| 4929 | + */ | |
| 4930 | + public function modal_error_container( $type = '' ) { | |
| 4931 | + echo '<div class="form-group mb-3"><div class="modal-error"></div></div>'; | |
| 4932 | + } | |
| 4933 | + | |
| 4934 | + public function form_custom_html( $html, $field, $value, $form_type ) { | |
| 4935 | + | |
| 4936 | + $html = ! empty( $field->default_value ) ? $field->default_value : ' '; | |
| 4937 | + | |
| 4938 | + return $html; | |
| 4939 | + } | |
| 4940 | +} | |