account.php
5 days ago
header.php
5 days ago
preferences.php
5 days ago
reset-password-modal.php
5 days ago
security.php
5 days ago
social-accounts.php
5 days ago
withdraw.php
5 days ago
account.php
380 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Settings Account |
| 4 | * |
| 5 | * @package Tutor\Templates |
| 6 | * @author Themeum <support@themeum.com> |
| 7 | * @link https://themeum.com |
| 8 | * @since 4.0.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | use TUTOR\Icon; |
| 14 | use TUTOR\User; |
| 15 | use Tutor\Components\Button; |
| 16 | use Tutor\Components\InputField; |
| 17 | use Tutor\Components\Modal; |
| 18 | use Tutor\Components\Constants\Size; |
| 19 | use Tutor\Components\Constants\Variant; |
| 20 | use Tutor\Components\Constants\InputType; |
| 21 | use Tutor\Components\Tooltip; |
| 22 | use Tutor\Components\WPEditor; |
| 23 | |
| 24 | $user = wp_get_current_user(); |
| 25 | $settings_data = User::get_profile_settings_data( $user->ID ); |
| 26 | |
| 27 | $display_name_options = array(); |
| 28 | foreach ( $settings_data['public_display'] as $_id => $item ) { |
| 29 | $display_name_options[] = array( |
| 30 | 'label' => $item, |
| 31 | 'value' => $item, |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | $timezone_options = array(); |
| 36 | foreach ( tutor_global_timezone_lists() as $key => $value ) { |
| 37 | $timezone_options[] = array( |
| 38 | 'label' => $value, |
| 39 | 'value' => $key, |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | $default_values = array( |
| 44 | 'first_name' => $user->first_name, |
| 45 | 'last_name' => $user->last_name, |
| 46 | 'username' => $user->user_login, |
| 47 | 'phone_number' => $settings_data['phone_number'], |
| 48 | 'timezone' => $settings_data['timezone'], |
| 49 | 'tutor_profile_job_title' => $settings_data['job_title'], |
| 50 | 'tutor_profile_bio' => $settings_data['profile_bio'], |
| 51 | 'display_name' => $user->display_name, |
| 52 | 'profile_photo' => $settings_data['profile_photo_src'], |
| 53 | 'cover_photo' => $settings_data['cover_photo_src'], |
| 54 | ); |
| 55 | |
| 56 | $default_values = (array) apply_filters( 'tutor_profile_default_values', $default_values, $user ); |
| 57 | |
| 58 | ?> |
| 59 | |
| 60 | <div class="tutor-account-section"> |
| 61 | <?php do_action( 'tutor_profile_edit_form_before' ); ?> |
| 62 | |
| 63 | <form |
| 64 | id="<?php echo esc_attr( $form_id ); ?>" |
| 65 | x-data='tutorForm({ |
| 66 | id: "<?php echo esc_attr( $form_id ); ?>", |
| 67 | mode: "onChange", |
| 68 | defaultValues: <?php echo esc_attr( wp_json_encode( $default_values ) ); ?>, |
| 69 | })' |
| 70 | x-bind="getFormBindings()" |
| 71 | @submit="handleSubmit((data) => handleUpdateProfile(data, '<?php echo esc_attr( $form_id ); ?>'))($event)" |
| 72 | class="tutor-flex tutor-flex-column tutor-gap-6" |
| 73 | > |
| 74 | <div class="tutor-flex tutor-flex-column tutor-gap-4"> |
| 75 | <h5 class="tutor-h5 tutor-md-hidden tutor-my-none"><?php echo esc_html__( 'Account', 'tutor' ); ?></h5> |
| 76 | <div class="tutor-card tutor-card-rounded-2xl tutor-flex tutor-flex-column tutor-gap-5"> |
| 77 | <div> |
| 78 | <div |
| 79 | x-data="tutorFileUploader({ |
| 80 | value: [getValue('cover_photo')], |
| 81 | variant: 'image-uploader', |
| 82 | accept: '.png,.jpg,.jpeg', |
| 83 | onFileSelect: handleUploadCoverPhoto, |
| 84 | imagePreviewPlaceholder: '<?php echo esc_attr( $settings_data['cover_placeholder'] ); ?>', |
| 85 | })" |
| 86 | class="tutor-account-cover-photo" |
| 87 | :class="{ |
| 88 | 'is-loading': uploadCoverPhotoMutation?.isPending || removeCoverPhotoMutation?.isPending, |
| 89 | }" |
| 90 | :style="`background-image: url(${imagePreview ? imagePreview : '<?php echo esc_url( $settings_data['cover_placeholder'] ); ?>'})`" |
| 91 | > |
| 92 | <input |
| 93 | class="tutor-hidden" |
| 94 | type="file" |
| 95 | name="cover_photo" |
| 96 | x-ref="fileInput" |
| 97 | :multiple="multiple" |
| 98 | :accept="accept" |
| 99 | @change="handleFileSelect($event)" |
| 100 | /> |
| 101 | |
| 102 | <div class="tutor-account-cover-photo-action"> |
| 103 | <div |
| 104 | x-data="tutorPopover({ |
| 105 | placement: 'bottom-end', |
| 106 | offset: 4, |
| 107 | })" |
| 108 | > |
| 109 | <?php |
| 110 | Button::make() |
| 111 | ->icon_only() |
| 112 | ->variant( Variant::OUTLINE ) |
| 113 | ->label( __( 'Edit Cover Photo', 'tutor' ) ) |
| 114 | ->size( Size::X_SMALL ) |
| 115 | ->icon( Icon::CAMERA ) |
| 116 | ->attr( 'type', 'button' ) |
| 117 | ->attr( 'x-ref', 'trigger' ) |
| 118 | ->attr( '@click', "imagePreview && imagePreview !== '" . esc_url( $settings_data['cover_placeholder'] ) . "' ? toggle() : openFileDialog()" ) |
| 119 | ->render(); |
| 120 | ?> |
| 121 | |
| 122 | <div |
| 123 | x-ref="content" |
| 124 | x-show="open" |
| 125 | x-cloak |
| 126 | @click.outside="handleClickOutside()" |
| 127 | class="tutor-popover" |
| 128 | > |
| 129 | <div class="tutor-flex tutor-flex-column tutor-gap-3 tutor-p-5"> |
| 130 | <?php |
| 131 | Button::make() |
| 132 | ->label( __( 'Upload Photo', 'tutor' ) ) |
| 133 | ->size( Size::X_SMALL ) |
| 134 | ->attr( 'type', 'button' ) |
| 135 | ->attr( '@click', 'openFileDialog(), hide()' ) |
| 136 | ->render(); |
| 137 | |
| 138 | Button::make() |
| 139 | ->label( __( 'Remove Photo', 'tutor' ) ) |
| 140 | ->variant( Variant::SECONDARY ) |
| 141 | ->size( Size::X_SMALL ) |
| 142 | ->attr( 'type', 'button' ) |
| 143 | ->attr( '@click', 'removeFile(), hide(), handleRemoveCoverPhoto()' ) |
| 144 | ->attr( 'x-show', "imagePreview && imagePreview !== '" . esc_url( $settings_data['cover_placeholder'] ) . "'" ) |
| 145 | ->render(); |
| 146 | ?> |
| 147 | </div> |
| 148 | </div> |
| 149 | </div> |
| 150 | <?php |
| 151 | Tooltip::make() |
| 152 | ->content( __( 'Profile Photo Size: 200x200 pixels Cover Photo Size: 700x430 pixels', 'tutor' ) ) |
| 153 | ->trigger_element( |
| 154 | Button::make() |
| 155 | ->variant( Variant::OUTLINE ) |
| 156 | ->label( __( 'Cover Photo Info', 'tutor' ) ) |
| 157 | ->size( Size::X_SMALL ) |
| 158 | ->icon( Icon::INFO_OCTAGON ) |
| 159 | ->icon_only() |
| 160 | ->attr( 'type', 'button' ) |
| 161 | ->get() |
| 162 | ) |
| 163 | ->placement( Tooltip::PLACEMENT_BOTTOM ) |
| 164 | ->arrow( Tooltip::ARROW_CENTER ) |
| 165 | ->size( Size::MEDIUM ) |
| 166 | ->render(); |
| 167 | ?> |
| 168 | </div> |
| 169 | </div> |
| 170 | |
| 171 | <div class="tutor-account-avatar-wrapper"> |
| 172 | <div x-data="tutorPopover({ |
| 173 | placement: 'right-top', |
| 174 | offset: 4, |
| 175 | })"> |
| 176 | <div |
| 177 | x-data="tutorFileUploader({ |
| 178 | value: [getValue('profile_photo')], |
| 179 | variant: 'image-uploader', |
| 180 | accept: '.png,.jpg,.jpeg', |
| 181 | onFileSelect: handleUploadProfilePhoto, |
| 182 | imagePreviewPlaceholder: '<?php echo esc_attr( $settings_data['profile_placeholder'] ); ?>', |
| 183 | })" |
| 184 | class="tutor-account-avatar" |
| 185 | :class="{ |
| 186 | 'active': open, |
| 187 | 'is-loading': uploadProfilePhotoMutation?.isPending || removeProfilePhotoMutation?.isPending, |
| 188 | }" |
| 189 | > |
| 190 | <input |
| 191 | class="tutor-hidden" |
| 192 | type="file" |
| 193 | name="profile_photo" |
| 194 | x-ref="fileInput" |
| 195 | :multiple="multiple" |
| 196 | :accept="accept" |
| 197 | @change="handleFileSelect($event)" |
| 198 | /> |
| 199 | <img |
| 200 | :src="imagePreview ? imagePreview : '<?php echo esc_url( $settings_data['profile_placeholder'] ); ?>'" |
| 201 | class="tutor-avatar-image" |
| 202 | :style="imagePreview && imagePreview !== '<?php echo esc_url( $settings_data['profile_placeholder'] ); ?>' ? 'cursor: pointer;' : ''" |
| 203 | alt="<?php esc_attr_e( 'User Avatar', 'tutor' ); ?>" |
| 204 | @click="imagePreview && imagePreview !== '<?php echo esc_url( $settings_data['profile_placeholder'] ); ?>' ? TutorCore.modal.showModal('tutor-profile-photo-modal') : openFileDialog()" |
| 205 | > |
| 206 | |
| 207 | <?php |
| 208 | Button::make() |
| 209 | ->variant( Variant::SECONDARY ) |
| 210 | ->label( __( 'Upload Photo', 'tutor' ) ) |
| 211 | ->size( Size::X_SMALL ) |
| 212 | ->icon( Icon::CAMERA ) |
| 213 | ->icon_only() |
| 214 | ->attr( 'type', 'button' ) |
| 215 | ->attr( 'class', 'tutor-account-avatar-edit' ) |
| 216 | ->attr( 'x-ref', 'trigger' ) |
| 217 | ->attr( '@click', "imagePreview && imagePreview !== '" . esc_url( $settings_data['profile_placeholder'] ) . "' ? toggle() : openFileDialog()" ) |
| 218 | ->render(); |
| 219 | ?> |
| 220 | |
| 221 | <div |
| 222 | x-ref="content" |
| 223 | x-show="open" |
| 224 | x-cloak |
| 225 | @click.outside="handleClickOutside()" |
| 226 | class="tutor-popover" |
| 227 | > |
| 228 | <div class="tutor-flex tutor-flex-column tutor-gap-3 tutor-p-5"> |
| 229 | <?php |
| 230 | Button::make() |
| 231 | ->label( __( 'Upload Photo', 'tutor' ) ) |
| 232 | ->size( Size::X_SMALL ) |
| 233 | ->attr( 'type', 'button' ) |
| 234 | ->attr( 'x-ref', 'upload' ) |
| 235 | ->attr( '@click', 'openFileDialog()' ) |
| 236 | ->render(); |
| 237 | |
| 238 | Button::make() |
| 239 | ->label( __( 'Remove Photo', 'tutor' ) ) |
| 240 | ->variant( Variant::SECONDARY ) |
| 241 | ->size( Size::X_SMALL ) |
| 242 | ->attr( 'type', 'button' ) |
| 243 | ->attr( '@click', 'removeFile(), hide(), handleRemoveProfilePhoto()' ) |
| 244 | ->attr( 'x-show', "imagePreview && imagePreview !== '" . esc_url( $settings_data['profile_placeholder'] ) . "'" ) |
| 245 | ->render(); |
| 246 | ?> |
| 247 | </div> |
| 248 | </div> |
| 249 | |
| 250 | <?php |
| 251 | Modal::make() |
| 252 | ->id( 'tutor-profile-photo-modal' ) |
| 253 | ->title( __( 'Profile Photo', 'tutor' ) ) |
| 254 | ->body( |
| 255 | '<div class="tutor-flex-center"> |
| 256 | <img |
| 257 | :src="imagePreview ? imagePreview : \'' . esc_url( $settings_data['profile_placeholder'] ) . '\'" |
| 258 | alt="' . esc_attr__( 'User Avatar', 'tutor' ) . '" |
| 259 | style="max-width: 100%; height: auto; border-radius: 8px;" |
| 260 | /> |
| 261 | </div>', |
| 262 | 'strval' |
| 263 | ) |
| 264 | ->render(); |
| 265 | ?> |
| 266 | </div> |
| 267 | </div> |
| 268 | </div> |
| 269 | </div> |
| 270 | |
| 271 | <?php do_action( 'tutor_profile_edit_input_before' ); ?> |
| 272 | |
| 273 | <div class="tutor-grid tutor-md-grid-cols-1 tutor-grid-cols-2 tutor-gap-5"> |
| 274 | <?php |
| 275 | InputField::make() |
| 276 | ->type( InputType::TEXT ) |
| 277 | ->label( __( 'First Name', 'tutor' ) ) |
| 278 | ->name( 'first_name' ) |
| 279 | ->clearable() |
| 280 | ->id( 'first_name' ) |
| 281 | ->placeholder( __( 'Enter your first name', 'tutor' ) ) |
| 282 | ->attr( 'x-bind', "register('first_name')" ) |
| 283 | ->render(); |
| 284 | |
| 285 | InputField::make() |
| 286 | ->type( InputType::TEXT ) |
| 287 | ->label( __( 'Last Name', 'tutor' ) ) |
| 288 | ->name( 'last_name' ) |
| 289 | ->clearable() |
| 290 | ->id( 'last_name' ) |
| 291 | ->placeholder( __( 'Enter your last name', 'tutor' ) ) |
| 292 | ->attr( 'x-bind', "register('last_name')" ) |
| 293 | ->render(); |
| 294 | ?> |
| 295 | </div> |
| 296 | |
| 297 | <?php |
| 298 | InputField::make() |
| 299 | ->type( InputType::TEXT ) |
| 300 | ->label( __( 'Username', 'tutor' ) ) |
| 301 | ->name( 'username' ) |
| 302 | ->disabled() |
| 303 | ->clearable() |
| 304 | ->id( 'username' ) |
| 305 | ->placeholder( __( 'Enter your username', 'tutor' ) ) |
| 306 | ->attr( 'x-bind', "register('username')" ) |
| 307 | ->render(); |
| 308 | |
| 309 | InputField::make() |
| 310 | ->type( InputType::TEXT ) |
| 311 | ->label( __( 'Phone Number', 'tutor' ) ) |
| 312 | ->name( 'phone_number' ) |
| 313 | ->clearable() |
| 314 | ->id( 'phone_number' ) |
| 315 | ->placeholder( __( 'Enter your phone number', 'tutor' ) ) |
| 316 | ->attr( |
| 317 | 'x-bind', |
| 318 | "register('phone_number', { pattern: { value: /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im } } )" |
| 319 | ) |
| 320 | ->render(); |
| 321 | |
| 322 | InputField::make() |
| 323 | ->type( InputType::TEXT ) |
| 324 | ->label( __( 'Skill/Occupation', 'tutor' ) ) |
| 325 | ->name( 'tutor_profile_job_title' ) |
| 326 | ->clearable() |
| 327 | ->id( 'tutor_profile_job_title' ) |
| 328 | ->placeholder( __( 'Enter your skill/occupation', 'tutor' ) ) |
| 329 | ->attr( 'x-bind', "register('tutor_profile_job_title')" ) |
| 330 | ->render(); |
| 331 | |
| 332 | if ( ! User::is_admin() ) { |
| 333 | Inputfield::make() |
| 334 | ->type( InputType::SELECT ) |
| 335 | ->label( __( 'Timezone', 'tutor' ) ) |
| 336 | ->name( 'timezone' ) |
| 337 | ->options( $timezone_options ) |
| 338 | ->searchable() |
| 339 | ->clearable() |
| 340 | ->id( 'timezone' ) |
| 341 | ->placeholder( __( 'Select your timezone', 'tutor' ) ) |
| 342 | ->attr( 'x-bind', "register('timezone')" ) |
| 343 | ->render(); |
| 344 | } |
| 345 | ?> |
| 346 | </div> |
| 347 | </div> |
| 348 | |
| 349 | <div class="tutor-flex tutor-flex-column tutor-gap-4"> |
| 350 | <h5 class="tutor-h5"><?php echo esc_html__( 'Public Profile', 'tutor' ); ?></h5> |
| 351 | <div class="tutor-card tutor-card-rounded-2xl tutor-flex tutor-flex-column tutor-gap-5"> |
| 352 | <?php |
| 353 | InputField::make() |
| 354 | ->type( InputType::SELECT ) |
| 355 | ->label( __( 'Display Name', 'tutor' ) ) |
| 356 | ->name( 'display_name' ) |
| 357 | ->options( $display_name_options ) |
| 358 | ->id( 'display_name' ) |
| 359 | ->placeholder( __( 'Enter your display name', 'tutor' ) ) |
| 360 | ->attr( 'x-bind', "register('display_name')" ) |
| 361 | ->render(); |
| 362 | |
| 363 | WPEditor::make() |
| 364 | ->label( __( 'Bio', 'tutor' ) ) |
| 365 | ->name( 'tutor_profile_bio' ) |
| 366 | ->placeholder( __( 'Enter your bio', 'tutor' ) ) |
| 367 | ->content( $default_values['tutor_profile_bio'] ) |
| 368 | ->attr( 'x-bind', "register('tutor_profile_bio')" ) |
| 369 | ->editor_config( tutor_utils()->get_profile_bio_editor_config( 'tutor_profile_bio' ) ) |
| 370 | ->render(); |
| 371 | ?> |
| 372 | </div> |
| 373 | </div> |
| 374 | |
| 375 | <?php do_action( 'tutor_profile_edit_input_after', $user ); ?> |
| 376 | </form> |
| 377 | |
| 378 | <?php do_action( 'tutor_profile_edit_form_after' ); ?> |
| 379 | </div> |
| 380 |