-
Notifications
You must be signed in to change notification settings - Fork 82
Preference settings #2344
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
base: 4.0.0-dev
Are you sure you want to change the base?
Preference settings #2344
Conversation
… preference-settings
…nd auto-play-next Introduce a new UserPreference class to manage per-user settings including theme (light/dark/system), font scale, and auto-play next lesson. This provides a centralized way to store and retrieve user-specific UI/UX preferences via WordPress user meta. - Add AJAX endpoint for saving preferences - Apply theme via data-theme attribute and font scale via CSS - Update dashboard and account templates with proper HTML structure - Extend frontend with new PreferenceService and settings UI - Integrate with existing Tutor core and Alpine.js components
Fix inconsistent behavior when user preferences are empty by returning an empty array instead of false. This prevents type errors when merging preferences and ensures the default value is properly applied. Also rename variables for clarity and fix filter hook name consistency.
- Move hardcoded font scale options to a filterable method in UserPreference class - Remove unused preference service exposure and refactor theme initialization - Clean up font scale calculation by using constants and improve readability - Fix a typo in a success message string
Initialize mediaQuery and activeTheme in constructor instead of inline declaration to ensure proper setup order. Use constant for data-theme attribute to avoid magic strings. Change applyTheme parameter to Theme type for better type safety.
Replace hard-coded 'system' string literals with THEME.SYSTEM constant to improve maintainability and consistency across theme handling logic.
…ucture - Move hardcoded theme options array to UserPreference::get_theme_options() method - Define DEFAULT_THEME, DEFAULT_FONT_SCALE, and FONT_SCALE_OPTIONS constants - Use constants consistently across template, PHP class, and TypeScript service - Simplify font scaling logic in TypeScript by removing unnecessary wrapper function - Improve error message when saving preferences fails
classes/UserPreference.php
Outdated
| return; | ||
| } | ||
|
|
||
| add_action( 'wp_ajax_tutor_save_user_preferences', array( $this, 'tutor_save_user_preferences' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add prefix ajax to callback method. It's already in a namespace and inside class. Do not use tutor prefix
ajax_save_user_preferences
classes/UserPreference.php
Outdated
|
|
||
| update_user_meta( $user_id, self::META_KEY, $preferences ); | ||
|
|
||
| do_action( 'tutor_user_preference_data', $user_id, $preferences ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tutor_user_preference_saved
classes/UserPreference.php
Outdated
| return array( | ||
| array( | ||
| 'label' => __( 'Light', 'tutor' ), | ||
| 'value' => 'light', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create these value as const
const THEME_LIGHT = 'light';
const THEME_DARK = 'dark';
const THEME_SYSTEM = 'system';Replace magic string theme values with named constants for better maintainability and type safety. Rename hook and method for consistency and update docblock types. Conditionally apply user preferences only on dashboard pages to prevent unintended side effects.
No description provided.