-
Notifications
You must be signed in to change notification settings - Fork 84
User prefered learning mood #2465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
031e916
Add learning mood preference to user settings and update Utils for re…
nur-alam 8c44429
Merge branch 'kids-mood-v4' of github.com:themeum/tutor into user-pre…
nur-alam fa4ae56
Refactor learning mood retrieval in UserPreference and Utils classes …
nur-alam ee3239d
Refactor is_kids_mode method in Utils class to improve clarity by rea…
nur-alam 9fbd82f
Add learning mood icon and update related references in the codebase
nur-alam e2599da
Merge branch '4.0.0-dev' of github.com:themeum/tutor into user-prefer…
nur-alam ba627df
Merge branch '4.0.0-dev' of github.com:themeum/tutor into user-prefer…
nur-alam c1b96ef
refactor: add reset preferences functionality & Update theme attribut…
nur-alam 6a69e3e
Merge branch '4.0.0-dev' of github.com:themeum/tutor into user-prefer…
nur-alam bb74ebf
feat: implement reset preferences feature
nur-alam 49936f7
refactor: remove reset preferences SVG and update preferences reset l…
nur-alam 78288e6
mend
nur-alam 9b37d4a
update reset preference modal illustrations
nur-alam 97d5960
Merge branch '4.0.0-dev' of github.com:themeum/tutor into user-prefer…
nur-alam d9b3a42
refactor: simplify learning mode preference retrieval and update plac…
nur-alam 6df6512
refactor: restrict learning mood setting visibility to student view a…
nur-alam 4c377ae
Merge branch '4.0.0-dev' of github.com:themeum/tutor into user-prefer…
nur-alam 3e6b2e3
refactor: simplify admin kids mode check by removing redundant variable
nur-alam 4569e9a
Merge branch '4.0.0-dev' of github.com:themeum/tutor into user-prefer…
nur-alam 54257d7
fix: correct kids mode detection and user preference handling
nur-alam f07dd29
Merge branch '4.0.0-dev' of github.com:themeum/tutor into user-prefer…
nur-alam a9574e5
fix: prevent undefined variable warning in user preference handling
nur-alam 239401e
Merge branch '4.0.0-dev' of github.com:themeum/tutor into user-prefer…
nur-alam fc1c67f
fix: remove boolean type cast from auto_play_next preference
nur-alam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
|
|
||
| use Tutor\Cache\TutorCache; | ||
| use Tutor\Helpers\HttpHelper; | ||
| use Tutor\Options_V2; | ||
| use Tutor\Traits\JsonResponse; | ||
|
|
||
| /** | ||
|
|
@@ -113,6 +114,7 @@ public function __construct( $register_hooks = true ) { | |
| } | ||
|
|
||
| add_action( 'wp_ajax_tutor_save_user_preferences', array( $this, 'ajax_save_user_preferences' ) ); | ||
| add_action( 'wp_ajax_tutor_reset_user_preferences', array( $this, 'ajax_reset_user_preferences' ) ); | ||
| add_filter( 'body_class', array( $this, 'add_theme_attribute' ) ); | ||
| add_action( 'wp_head', array( $this, 'apply_font_scale' ) ); | ||
| } | ||
|
|
@@ -152,7 +154,7 @@ public function add_theme_attribute( $classes ) { | |
| if ( ! in_array( $theme, self::THEMES, true ) ) { | ||
| $theme = self::DEFAULT_THEME; | ||
| } | ||
| echo ' data-theme="' . esc_attr( $theme ) . '"'; | ||
| echo ' data-tutor-theme="' . esc_attr( $theme ) . '"'; | ||
| return $classes; | ||
| } | ||
|
|
||
|
|
@@ -226,10 +228,15 @@ public function save_preferences( array $prefs, $user_id = 0 ) { | |
| return false; | ||
| } | ||
|
|
||
| $current_preferences = $this->get_preferences( $user_id ); | ||
| $preferences = array_merge( $current_preferences, $prefs ); | ||
| // Get from database. | ||
| $current_preferences = get_user_meta( $user_id, self::META_KEY, true ); | ||
| if ( ! is_array( $current_preferences ) ) { | ||
| $current_preferences = array(); | ||
| } | ||
|
|
||
| $preferences = apply_filters( 'tutor_user_preference_data', $preferences, $user_id ); | ||
| $combined_preferences = array_merge( $current_preferences, $prefs ); | ||
|
|
||
| $preferences = apply_filters( 'tutor_user_preference_data', $combined_preferences, $user_id ); | ||
|
|
||
| update_user_meta( $user_id, self::META_KEY, $preferences ); | ||
|
|
||
|
|
@@ -248,24 +255,49 @@ public function save_preferences( array $prefs, $user_id = 0 ) { | |
| public function ajax_save_user_preferences() { | ||
| tutor_utils()->check_nonce(); | ||
|
|
||
| if ( ! is_user_logged_in() ) { | ||
| $auto_play_next = Input::post( 'auto_play_next', null ); | ||
| $theme = Input::post( 'theme', null ); | ||
| $font_scale = Input::post( 'font_scale', null ); | ||
| $learning_mood = Input::post( 'learning_mood', null ); | ||
|
|
||
| $preferences_settings = array(); | ||
|
|
||
| if ( null !== $auto_play_next ) { | ||
| $default_auto_play_next = (bool) tutor_utils()->get_option( 'autoload_next_course_content' ); | ||
| $auto_play_next = 'true' === $auto_play_next ? true : false; | ||
| if ( $auto_play_next !== $default_auto_play_next ) { | ||
| $preferences_settings['auto_play_next'] = $auto_play_next; | ||
| } | ||
| } | ||
|
|
||
| if ( null !== $theme ) { | ||
| $preferences_settings['theme'] = $theme; | ||
| } | ||
|
|
||
| if ( null !== $font_scale ) { | ||
| $preferences_settings['font_scale'] = (int) $font_scale; | ||
| } | ||
|
|
||
| if ( null !== $learning_mood ) { | ||
| // Validate learning_mood against allowed values. | ||
| $allowed_moods = array( Options_V2::LEARNING_MODE_MODERN, Options_V2::LEARNING_MODE_KIDS ); | ||
| if ( ! in_array( $learning_mood, $allowed_moods, true ) ) { | ||
| $learning_mood = Options_V2::LEARNING_MODE_MODERN; | ||
| } | ||
| $default_learning_mood = tutor_utils()->get_option( 'learning_mode', Options_V2::LEARNING_MODE_MODERN ); | ||
| if ( $learning_mood !== $default_learning_mood ) { | ||
| $preferences_settings['learning_mood'] = $learning_mood; | ||
| } | ||
| } | ||
|
|
||
| if ( empty( $preferences_settings ) ) { | ||
| $this->json_response( | ||
| tutor_utils()->error_message( 'forbidden' ), | ||
| __( 'No changes detected', 'tutor' ), | ||
| null, | ||
| HttpHelper::STATUS_UNAUTHORIZED | ||
| HttpHelper::STATUS_OK | ||
| ); | ||
| } | ||
|
|
||
| $auto_play_next = Input::post( 'auto_play_next', false, INPUT::TYPE_BOOL ); | ||
| $theme = Input::post( 'theme', self::DEFAULT_THEME ); | ||
| $font_scale = Input::post( 'font_scale', self::DEFAULT_FONT_SCALE, INPUT::TYPE_INT ); | ||
|
|
||
| $preferences_settings = array( | ||
| 'auto_play_next' => $auto_play_next, | ||
| 'theme' => $theme, | ||
| 'font_scale' => $font_scale, | ||
| ); | ||
|
|
||
| $preference_data = $this->save_preferences( $preferences_settings, get_current_user_id() ); | ||
|
|
||
| if ( false === $preference_data ) { | ||
|
|
@@ -282,6 +314,34 @@ public function ajax_save_user_preferences() { | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * AJAX handler: reset current user's preferences back to defaults. | ||
| * | ||
| * @since 4.0.0 | ||
| * | ||
| * @return void | ||
| */ | ||
| public function ajax_reset_user_preferences() { | ||
| tutor_utils()->check_nonce(); | ||
|
|
||
| $user_id = get_current_user_id(); | ||
| if ( ! $user_id ) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need |
||
| $this->json_response( | ||
| __( 'Failed to reset preferences', 'tutor' ), | ||
| null, | ||
| HttpHelper::STATUS_NOT_FOUND | ||
| ); | ||
| } | ||
|
|
||
| // Delete user meta. | ||
| delete_user_meta( $user_id, self::META_KEY ); | ||
|
|
||
| $this->json_response( | ||
| __( 'Preferences reset successfully', 'tutor' ), | ||
| null | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Get default preferences. | ||
| * | ||
|
|
@@ -297,6 +357,7 @@ private static function get_default_preferences() { | |
| 'auto_play_next' => (bool) tutor_utils()->get_option( 'autoload_next_course_content' ), | ||
| 'theme' => self::DEFAULT_THEME, | ||
| 'font_scale' => self::DEFAULT_FONT_SCALE, | ||
| 'learning_mood' => tutor_utils()->get_option( 'learning_mode', Options_V2::LEARNING_MODE_MODERN ), | ||
| ) | ||
| ); | ||
|
|
||
|
|
@@ -327,6 +388,26 @@ public static function get_theme_options() { | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Get learning mood options for UI selects. | ||
| * | ||
| * @since 4.0.0 | ||
| * | ||
| * @return array<int,array{label:string,value:string}> | ||
| */ | ||
| public static function get_learning_mood_options() { | ||
| return array( | ||
| array( | ||
| 'label' => __( 'Modern', 'tutor' ), | ||
| 'value' => Options_V2::LEARNING_MODE_MODERN, | ||
| ), | ||
| array( | ||
| 'label' => __( 'Kids', 'tutor' ), | ||
| 'value' => Options_V2::LEARNING_MODE_KIDS, | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Get font scale options for UI selects. | ||
| * | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.