| @@ -9,17 +9,8 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace TUTOR; |
| 12 | 12 | |
| 13 | -use Tutor\Ecommerce\CartController; | |
| 14 | -use Tutor\Ecommerce\CheckoutController; | |
| 15 | -use Tutor\Ecommerce\CouponController; | |
| 16 | -use Tutor\Ecommerce\OptionKeys; | |
| 17 | -use Tutor\Ecommerce\OrderController; | |
| 18 | -use Tutor\Ecommerce\Settings; | |
| 19 | -use Tutor\Models\CourseModel; | |
| 20 | -use Tutor\Options_V2; | |
| 21 | - | |
| 22 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 23 | 14 | exit; |
| 24 | 15 | } |
| 25 | 16 | |
| @@ -29,26 +20,16 @@ | ||
| 29 | 20 | * @since 1.0.0 |
| 30 | 21 | */ |
| 31 | 22 | class Assets { |
| 32 | 23 | |
| 33 | - | |
| 34 | 24 | /** |
| 35 | 25 | * Constructor |
| 36 | 26 | * |
| 37 | 27 | * @since 1.0.0 |
| 38 | - * | |
| 39 | - * @since 3.0.0 register hook param added | |
| 40 | - * | |
| 41 | - * @param bool $register_hooks param added to enable or disable registering hooks. | |
| 42 | - * | |
| 43 | 28 | * @return void |
| 44 | 29 | */ |
| 45 | - public function __construct( $register_hooks = true ) { | |
| 46 | - if ( ! $register_hooks ) { | |
| 47 | - return; | |
| 48 | - } | |
| 49 | - | |
| 50 | - /** | |
| 30 | + public function __construct() { | |
| 31 | + /** | |
| 51 | 32 | * Common scripts loading |
| 52 | 33 | */ |
| 53 | 34 | add_action( 'admin_enqueue_scripts', array( $this, 'common_scripts' ) ); |
| 54 | 35 | add_action( 'wp_enqueue_scripts', array( $this, 'common_scripts' ) ); |
| @@ -72,9 +53,9 @@ | ||
| 72 | 53 | * Register translatable function to load |
| 73 | 54 | * Handled script with text domain attached to |
| 74 | 55 | * |
| 75 | 56 | * @since 1.9.0 |
| 76 | - */ | |
| 57 | + */ | |
| 77 | 58 | add_action( 'admin_head', array( $this, 'tutor_add_mce_button' ) ); |
| 78 | 59 | add_filter( 'get_the_generator_html', array( $this, 'tutor_generator_tag' ), 10, 2 ); |
| 79 | 60 | add_filter( 'get_the_generator_xhtml', array( $this, 'tutor_generator_tag' ), 10, 2 ); |
| 80 | 61 | |
| @@ -98,25 +79,8 @@ | ||
| 98 | 79 | * |
| 99 | 80 | * @since v2.0.5 |
| 100 | 81 | */ |
| 101 | 82 | add_action( 'enqueue_block_editor_assets', __CLASS__ . '::add_frontend_editor_button' ); |
| 102 | - | |
| 103 | - /** | |
| 104 | - * Enqueue styles & scripts | |
| 105 | - * | |
| 106 | - * @since 4.0.0 | |
| 107 | - */ | |
| 108 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); | |
| 109 | - | |
| 110 | - // Add custom meta. | |
| 111 | - add_action( 'wp_head', array( $this, 'add_custom_data' ) ); | |
| 112 | - | |
| 113 | - /** | |
| 114 | - * Add preload to CSS | |
| 115 | - * | |
| 116 | - * @since 4.0.0 | |
| 117 | - */ | |
| 118 | - add_filter( 'style_loader_tag', array( $this, 'add_preload_to_css' ), 10, 2 ); | |
| 119 | 83 | } |
| 120 | 84 | |
| 121 | 85 | /** |
| 122 | 86 | * Load default localized data |
| @@ -123,9 +87,9 @@ | ||
| 123 | 87 | * |
| 124 | 88 | * @since 1.0.0 |
| 125 | 89 | * @return array |
| 126 | 90 | */ |
| 127 | - public function get_default_localized_data() { | |
| 91 | + private function get_default_localized_data() { | |
| 128 | 92 | $home_url = get_home_url(); |
| 129 | 93 | $parsed = parse_url( $home_url ); |
| 130 | 94 | |
| 131 | 95 | $base_path = ( is_array( $parsed ) && isset( $parsed['path'] ) ) ? $parsed['path'] : '/'; |
| @@ -135,61 +99,11 @@ | ||
| 135 | 99 | $post_type = get_post_type( $post_id ); |
| 136 | 100 | |
| 137 | 101 | $current_page = tutor_utils()->get_current_page_slug(); |
| 138 | 102 | |
| 139 | - /** | |
| 140 | - * Only required current user data. | |
| 141 | - * | |
| 142 | - * @since 2.6.2 | |
| 143 | - */ | |
| 144 | - $current_user = array(); | |
| 145 | - $userdata = get_userdata( get_current_user_id() ); | |
| 146 | - | |
| 147 | - if ( $userdata ) { | |
| 148 | - $current_user = array( | |
| 149 | - 'roles' => array_values( $userdata->roles ), | |
| 150 | - 'data' => array( | |
| 151 | - 'id' => $userdata->ID, | |
| 152 | - 'display_name' => $userdata->display_name, | |
| 153 | - ), | |
| 154 | - ); | |
| 155 | - } | |
| 156 | - | |
| 157 | - $tutor_currency = array( | |
| 158 | - 'symbol' => Settings::get_currency_symbol_by_code( tutor_utils()->get_option( OptionKeys::CURRENCY_CODE, 'USD' ) ), | |
| 159 | - 'currency' => tutor_utils()->get_option( OptionKeys::CURRENCY_CODE ), | |
| 160 | - 'position' => tutor_utils()->get_option( OptionKeys::CURRENCY_POSITION, 'left' ), | |
| 161 | - 'thousand_separator' => tutor_utils()->get_option( OptionKeys::THOUSAND_SEPARATOR, ',' ), | |
| 162 | - 'decimal_separator' => tutor_utils()->get_option( OptionKeys::DECIMAL_SEPARATOR, '.' ), | |
| 163 | - 'no_of_decimal' => tutor_utils()->get_option( OptionKeys::NUMBER_OF_DECIMALS, '2' ), | |
| 164 | - ); | |
| 165 | - | |
| 166 | - /** | |
| 167 | - * Get only required options. | |
| 168 | - * | |
| 169 | - * @since 3.0.0 | |
| 170 | - */ | |
| 171 | - $required_options = array( | |
| 172 | - 'monetize_by', | |
| 173 | - ); | |
| 174 | - | |
| 175 | - $tutor_settings = Options_V2::get_only( $required_options ); | |
| 176 | - | |
| 177 | - // Load available kids mode icons to avoid frontend 404s if kids mode is active. | |
| 178 | - $kids_icons = array(); | |
| 179 | - if ( tutor_utils()->is_kids_mode() ) { | |
| 180 | - $kids_icons = array_map( | |
| 181 | - function ( $file ) { | |
| 182 | - return basename( $file, '.svg' ); | |
| 183 | - }, | |
| 184 | - glob( tutor()->path . 'assets/icons/kids/*.svg' ) ?: array() | |
| 185 | - ); | |
| 186 | - } | |
| 187 | - | |
| 188 | 103 | return array( |
| 189 | 104 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 190 | - 'home_url' => rtrim( get_home_url(), '/' ), | |
| 191 | - 'site_url' => rtrim( get_site_url(), '/' ), | |
| 105 | + 'home_url' => get_home_url(), | |
| 192 | 106 | 'site_title' => get_bloginfo( 'title' ), |
| 193 | 107 | 'base_path' => tutor()->basepath, |
| 194 | 108 | 'tutor_url' => tutor()->url, |
| 195 | 109 | 'tutor_pro_url' => function_exists( 'tutor_pro' ) ? tutor_pro()->url : null, |
| @@ -198,35 +112,21 @@ | ||
| 198 | 112 | 'loading_icon_url' => get_admin_url() . 'images/wpspin_light.gif', |
| 199 | 113 | 'placeholder_img_src' => tutor_placeholder_img_src(), |
| 200 | 114 | 'enable_lesson_classic_editor' => get_tutor_option( 'enable_lesson_classic_editor' ), |
| 201 | 115 | 'tutor_frontend_dashboard_url' => tutor_utils()->get_tutor_dashboard_page_permalink(), |
| 202 | - 'is_dashboard_page' => tutor_utils()->is_dashboard_page(), | |
| 203 | 116 | 'wp_date_format' => tutor_js_date_format_against_wp(), |
| 204 | - 'start_of_week' => get_option( 'start_of_week', 1 ), | |
| 205 | 117 | 'is_admin' => is_admin(), |
| 206 | 118 | 'is_admin_bar_showing' => is_admin_bar_showing(), |
| 207 | 119 | 'addons_data' => tutor_utils()->prepare_free_addons_data(), |
| 208 | - 'current_user' => $current_user, | |
| 120 | + 'current_user' => wp_get_current_user(), | |
| 209 | 121 | 'content_change_event' => 'tutor_content_changed_event', |
| 210 | 122 | 'is_tutor_course_edit' => isset( $_GET['action'] ) && 'edit' === $_GET['action'] && tutor()->course_post_type === get_post_type( get_the_ID() ) ? true : false, |
| 123 | + 'assignment_max_file_allowed' => 'tutor_assignments' === $post_type ? (int) tutor_utils()->get_assignment_option( $post_id, 'upload_files_limit' ) : 0, | |
| 211 | 124 | 'current_page' => $current_page, |
| 212 | 125 | 'quiz_answer_display_time' => 1000 * (int) tutor_utils()->get_option( 'quiz_answer_display_time' ), |
| 213 | 126 | 'is_ssl' => is_ssl(), |
| 214 | 127 | 'course_list_page_url' => admin_url( 'admin.php?page=tutor' ), |
| 215 | 128 | 'course_post_type' => tutor()->course_post_type, |
| 216 | - 'tutor_currency' => $tutor_currency, | |
| 217 | - 'local' => get_locale(), | |
| 218 | - 'settings' => $tutor_settings, | |
| 219 | - 'max_upload_size' => wp_max_upload_size(), | |
| 220 | - 'monetize_by' => tutor_utils()->get_option( 'monetize_by' ), | |
| 221 | - 'kids_icons_registry' => $kids_icons, | |
| 222 | - 'is_kids_mode' => tutor_utils()->is_kids_mode(), | |
| 223 | - 'user_preferences' => UserPreference::get_preferences( get_current_user_id() ), | |
| 224 | - 'is_legacy_learning_mode' => tutor_utils()->is_legacy_learning_mode(), | |
| 225 | - 'course_slug' => tutor_utils()->get_option( 'course_permalink_base', 'courses' ), | |
| 226 | - 'lesson_slug' => tutor_utils()->get_option( 'lesson_permalink_base', 'lessons' ), | |
| 227 | - 'quiz_slug' => tutor_utils()->get_option( 'quiz_permalink_base', 'quizzes' ), | |
| 228 | - 'is_tour_completed' => (bool) get_user_meta( get_current_user_id(), User::TOUR_COMPLETED_META, true ), | |
| 229 | 129 | ); |
| 230 | 130 | } |
| 231 | 131 | |
| 232 | 132 | /** |
| @@ -232,18 +132,13 @@ | ||
| 232 | 132 | /** |
| 233 | 133 | * Enqueue scripts for admin |
| 234 | 134 | * |
| 235 | 135 | * @since 1.0.0 |
| 236 | - * @since 3.0.0 Order details & coupon scripts added. | |
| 237 | - * | |
| 238 | - * @param string $slug The page slug. | |
| 239 | - * | |
| 240 | 136 | * @return void |
| 241 | 137 | */ |
| 242 | - public function admin_scripts( $slug ) { | |
| 243 | - wp_enqueue_style( 'tutor-select2', tutor()->url . 'assets/lib/select2/select2.min.css', array(), TUTOR_VERSION ); | |
| 138 | + public function admin_scripts() { | |
| 139 | + wp_enqueue_style( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.min.css', array(), TUTOR_VERSION ); | |
| 244 | 140 | wp_enqueue_style( 'tutor-admin', tutor()->url . 'assets/css/tutor-admin.min.css', array(), TUTOR_VERSION ); |
| 245 | - | |
| 246 | 141 | /** |
| 247 | 142 | * Scripts |
| 248 | 143 | */ |
| 249 | 144 | wp_enqueue_media(); |
| @@ -253,42 +148,10 @@ | ||
| 253 | 148 | |
| 254 | 149 | wp_enqueue_script( 'jquery-ui-slider' ); |
| 255 | 150 | wp_enqueue_script( 'jquery-ui-datepicker' ); |
| 256 | 151 | |
| 257 | - wp_enqueue_script( 'tutor-select2', tutor()->url . 'assets/lib/select2/select2.full.min.js', array( 'jquery' ), TUTOR_VERSION, true ); | |
| 258 | - wp_enqueue_script( 'tutor-admin', tutor()->url . 'assets/js/tutor-admin.js', array( 'jquery', 'tutor-script', 'wp-color-picker', 'wp-i18n', 'wp-data' ), TUTOR_VERSION, true ); | |
| 259 | - | |
| 260 | - // Tutor order detail & coupon scripts. | |
| 261 | - $page = Input::get( 'page', '' ); | |
| 262 | - $action = Input::get( 'action' ); | |
| 263 | - $sub_page = Input::get( 'sub_page' ); | |
| 264 | - | |
| 265 | - $allowed_actions = array( 'add_new', 'edit' ); | |
| 266 | - | |
| 267 | - if ( tutor_utils()->is_monetize_by_tutor() ) { | |
| 268 | - if ( OrderController::PAGE_SLUG === $page && 'edit' === $action ) { | |
| 269 | - wp_enqueue_script( 'tutor-order-details', tutor()->url . 'assets/js/tutor-order-details.js', array( 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true ); | |
| 270 | - } | |
| 271 | - | |
| 272 | - if ( CouponController::PAGE_SLUG === $page && in_array( $action, $allowed_actions, true ) ) { | |
| 273 | - wp_enqueue_script( 'tutor-coupon', tutor()->url . 'assets/js/tutor-coupon.js', array( 'wp-date', 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true ); | |
| 274 | - } | |
| 275 | - | |
| 276 | - // @since 3.0.0 add tax react app on the settings page. | |
| 277 | - if ( 'tutor_settings' === $page && ! Input::has( 'edit' ) ) { | |
| 278 | - wp_enqueue_editor(); | |
| 279 | - wp_enqueue_script( 'tutor-tax-settings', tutor()->url . 'assets/js/tutor-tax-settings.js', array( 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true ); | |
| 280 | - wp_enqueue_script( 'tutor-payment-settings', tutor()->url . 'assets/js/tutor-payment-settings.js', array( 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true ); | |
| 281 | - } | |
| 282 | - } | |
| 283 | - | |
| 284 | - if ( 'tutor-tools' === $page && 'import_export' === $sub_page ) { | |
| 285 | - wp_enqueue_script( 'tutor-import-export', tutor()->url . 'assets/js/tutor-import-export.js', array( 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true ); | |
| 286 | - } | |
| 287 | - | |
| 288 | - if ( 'tutor-addons' === $page ) { | |
| 289 | - wp_enqueue_script( 'tutor-coupon', tutor()->url . 'assets/js/tutor-addon-list.js', array( 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true ); | |
| 290 | - } | |
| 152 | + wp_enqueue_script( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.full.min.js', array( 'jquery' ), TUTOR_VERSION, true ); | |
| 153 | + wp_enqueue_script( 'tutor-admin', tutor()->url . 'assets/js/tutor-admin.min.js', array( 'jquery', 'wp-color-picker', 'wp-i18n', 'wp-data' ), TUTOR_VERSION, true ); | |
| 291 | 154 | } |
| 292 | 155 | |
| 293 | 156 | /** |
| 294 | 157 | * Load frontend scripts |
| @@ -293,60 +156,90 @@ | ||
| 293 | 156 | /** |
| 294 | 157 | * Load frontend scripts |
| 295 | 158 | * |
| 296 | 159 | * @since 1.0.0 |
| 297 | - * | |
| 298 | - * @since 4.0.0 Legacy scripts loading check added. | |
| 299 | - * | |
| 300 | 160 | * @return void |
| 301 | 161 | */ |
| 302 | 162 | public function frontend_scripts() { |
| 303 | - $load_legacy_scripts = self::should_load_legacy_scripts(); | |
| 304 | - if ( ! $load_legacy_scripts ) { | |
| 305 | - return; | |
| 306 | - } | |
| 163 | + global $post, $wp_query; | |
| 307 | 164 | |
| 308 | 165 | /** |
| 309 | 166 | * We checked wp_enqueue_editor() in condition because it conflicting with Divi Builder |
| 310 | 167 | * condition updated @since v.1.7.4 |
| 311 | - * | |
| 312 | - * @since 2.7.0 is_user_logged_in() check added to remove duplicate H1 tag on each single post. | |
| 313 | 168 | */ |
| 314 | - if ( is_single() && is_user_logged_in() ) { | |
| 169 | + | |
| 170 | + if ( is_single() ) { | |
| 315 | 171 | if ( function_exists( 'et_pb_is_pagebuilder_used' ) ) { |
| 316 | 172 | $is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() ); |
| 317 | 173 | if ( ! $is_page_builder_used ) { |
| 318 | 174 | wp_enqueue_editor(); |
| 319 | - wp_enqueue_script( 'quicktags' ); | |
| 320 | 175 | } |
| 321 | 176 | } else { |
| 322 | 177 | wp_enqueue_editor(); |
| 323 | - wp_enqueue_script( 'quicktags' ); | |
| 324 | 178 | } |
| 325 | 179 | } |
| 326 | 180 | |
| 327 | 181 | /** |
| 182 | + * Initializing quicktags script to use in wp_editor(); | |
| 183 | + */ | |
| 184 | + wp_enqueue_script( 'quicktags' ); | |
| 185 | + | |
| 186 | + $tutor_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' ); | |
| 187 | + if ( get_the_ID() === $tutor_dashboard_page_id ) { | |
| 188 | + wp_enqueue_media(); | |
| 189 | + } | |
| 190 | + | |
| 191 | + /** | |
| 328 | 192 | * Enabling Sorting, draggable, droppable... |
| 329 | 193 | */ |
| 330 | 194 | wp_enqueue_script( 'jquery-ui-sortable' ); |
| 331 | - wp_enqueue_script('jquery-touch-punch', ['jquery-ui-sortable']); //phpcs:ignore | |
| 195 | + wp_enqueue_script( 'jquery-touch-punch', array( 'jquery-ui-sortable' ) ); | |
| 332 | 196 | |
| 333 | 197 | // Plyr. |
| 334 | 198 | if ( is_single_course( true ) ) { |
| 335 | - wp_enqueue_style( 'tutor-plyr', tutor()->url . 'assets/lib/plyr/plyr.css', array(), TUTOR_VERSION ); | |
| 336 | - wp_enqueue_script( 'tutor-plyr', tutor()->url . 'assets/lib/plyr/plyr.polyfilled.min.js', array( 'jquery' ), TUTOR_VERSION, true ); | |
| 199 | + wp_enqueue_style( 'tutor-plyr', tutor()->url . 'assets/packages/plyr/plyr.css', array(), TUTOR_VERSION ); | |
| 200 | + wp_enqueue_script( 'tutor-plyr', tutor()->url . 'assets/packages/plyr/plyr.polyfilled.min.js', array( 'jquery' ), TUTOR_VERSION, true ); | |
| 337 | 201 | } |
| 338 | 202 | |
| 339 | 203 | // Social Share. |
| 340 | - wp_enqueue_script( 'tutor-social-share', tutor()->url . 'assets/lib/SocialShare/SocialShare.min.js', array( 'jquery' ), TUTOR_VERSION, true ); | |
| 204 | + wp_enqueue_script( 'tutor-social-share', tutor()->url . 'assets/packages/SocialShare/SocialShare.min.js', array( 'jquery' ), TUTOR_VERSION, true ); | |
| 341 | 205 | |
| 342 | 206 | /** |
| 207 | + * Chart Data | |
| 208 | + */ | |
| 209 | + if ( ! empty( $wp_query->query_vars['tutor_dashboard_page'] ) ) { | |
| 210 | + wp_enqueue_script( 'jquery-ui-slider' ); | |
| 211 | + | |
| 212 | + wp_enqueue_style( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.min.css', array(), TUTOR_VERSION ); | |
| 213 | + wp_enqueue_script( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.full.min.js', array( 'jquery' ), TUTOR_VERSION, true ); | |
| 214 | + | |
| 215 | + if ( 'earning' === $wp_query->query_vars['tutor_dashboard_page'] ) { | |
| 216 | + wp_enqueue_script( 'tutor-front-chart-js', tutor()->url . 'assets/js/lib/Chart.bundle.min.js', array(), TUTOR_VERSION ); | |
| 217 | + wp_enqueue_script( 'jquery-ui-datepicker' ); | |
| 218 | + } | |
| 219 | + } | |
| 220 | + /** | |
| 343 | 221 | * Dependency wp-i18n added for translate js file |
| 344 | 222 | * |
| 345 | 223 | * @since 1.9.0 |
| 346 | 224 | */ |
| 347 | 225 | wp_enqueue_style( 'tutor-frontend', tutor()->url . 'assets/css/tutor-front.min.css', array(), TUTOR_VERSION ); |
| 348 | - wp_enqueue_script( 'tutor-frontend', tutor()->url . 'assets/js/tutor-front.js', array( 'jquery', 'wp-i18n', 'wp-date' ), TUTOR_VERSION, true ); | |
| 226 | + wp_enqueue_script( 'tutor-frontend', tutor()->url . 'assets/js/tutor-front.min.js', array( 'jquery', 'wp-i18n' ), TUTOR_VERSION, true ); | |
| 227 | + | |
| 228 | + /** | |
| 229 | + * Load frontend dashboard style | |
| 230 | + * | |
| 231 | + * @since v1.9.8 | |
| 232 | + */ | |
| 233 | + $should_load_dashboard_styles = apply_filters( 'tutor_should_load_dashboard_styles', tutor_utils()->is_tutor_frontend_dashboard() ); | |
| 234 | + if ( $should_load_dashboard_styles ) { | |
| 235 | + wp_enqueue_style( 'tutor-frontend-dashboard-css', tutor()->url . 'assets/css/tutor-frontend-dashboard.min.css', TUTOR_VERSION ); | |
| 236 | + } | |
| 237 | + | |
| 238 | + // Load date picker for announcement at frontend. | |
| 239 | + wp_enqueue_script( 'jquery-ui-datepicker' ); | |
| 240 | + $css = '.mce-notification.mce-notification-error{display: none !important;}'; | |
| 241 | + wp_add_inline_style( 'tutor-frontend', $css ); | |
| 349 | 242 | } |
| 350 | 243 | |
| 351 | 244 | /** |
| 352 | 245 | * Modify localize data |
| @@ -360,24 +253,12 @@ | ||
| 360 | 253 | global $post; |
| 361 | 254 | |
| 362 | 255 | if ( is_admin() ) { |
| 363 | 256 | $taxonomy = Input::get( 'taxonomy' ); |
| 364 | - if ( CourseModel::COURSE_CATEGORY === $taxonomy || CourseModel::COURSE_TAG === $taxonomy ) { | |
| 257 | + if ( 'course-category' === $taxonomy || 'course-tag' === $taxonomy ) { | |
| 365 | 258 | $localize_data['open_tutor_admin_menu'] = true; |
| 366 | 259 | } |
| 367 | - | |
| 368 | - if ( 'en_US' !== $localize_data['local'] ) { | |
| 369 | - $page = Input::get( 'page', '' ); | |
| 370 | - $action = Input::get( 'action' ); | |
| 371 | - $allowed_actions = array( 'add_new', 'edit' ); | |
| 372 | - if ( CouponController::PAGE_SLUG === $page && in_array( $action, $allowed_actions, true ) ) { | |
| 373 | - $localize_data['coupon_main_content_locales'] = tutils()->get_script_locale_data( 'tutor-coupon-main-content', $localize_data['local'] ); | |
| 374 | - } | |
| 375 | - } | |
| 376 | 260 | } else { |
| 377 | - if ( 'en_US' !== $localize_data['local'] ) { | |
| 378 | - $localize_data['calendar_locales'] = tutils()->get_script_locale_data( 'tutor-calendar', $localize_data['local'] ); | |
| 379 | - } | |
| 380 | 261 | |
| 381 | 262 | // Assign quiz option. |
| 382 | 263 | if ( ! empty( $post->post_type ) && 'tutor_quiz' === $post->post_type ) { |
| 383 | 264 | $single_quiz_options = (array) tutor_utils()->get_quiz_option( $post->ID ); |
| @@ -414,19 +295,11 @@ | ||
| 414 | 295 | /** |
| 415 | 296 | * Load common scripts for frontend and backend |
| 416 | 297 | * |
| 417 | 298 | * @since 1.0.0 |
| 418 | - * | |
| 419 | - * @since 4.0.0 Legacy scripts loading check added. | |
| 420 | - * | |
| 421 | - * @param string $slug The page slug. | |
| 422 | - * | |
| 423 | 299 | * @return void |
| 424 | 300 | */ |
| 425 | - public function common_scripts( $slug ) { | |
| 426 | - if ( ! self::should_load_legacy_scripts() ) { | |
| 427 | - return; | |
| 428 | - } | |
| 301 | + public function common_scripts() { | |
| 429 | 302 | |
| 430 | 303 | /** |
| 431 | 304 | * Load TinyMCE for tutor settings page if tutor pro is not available. |
| 432 | 305 | * |
| @@ -442,19 +315,25 @@ | ||
| 442 | 315 | wp_enqueue_style( 'tutor-icon', tutor()->url . 'assets/css/tutor-icon.min.css', array(), TUTOR_VERSION ); |
| 443 | 316 | |
| 444 | 317 | // Common css library. |
| 445 | 318 | if ( is_rtl() ) { |
| 446 | - wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor-rtl.min.css', array(), TUTOR_VERSION ); | |
| 319 | + wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor.rtl.min.css', array(), TUTOR_VERSION ); | |
| 447 | 320 | } else { |
| 448 | 321 | wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor.min.css', array(), TUTOR_VERSION ); |
| 449 | 322 | } |
| 450 | 323 | |
| 324 | + // Load course builder resources. | |
| 325 | + $load_course_builder_scripts = apply_filters( 'tutor_load_course_builder_scripts', tutor_utils()->get_course_builder_screen() ); | |
| 326 | + if ( $load_course_builder_scripts ) { | |
| 327 | + wp_enqueue_script( 'tutor-course-builder', tutor()->url . 'assets/js/tutor-course-builder.min.js', array( 'jquery', 'wp-i18n' ), TUTOR_VERSION, true ); | |
| 328 | + wp_enqueue_style( 'tutor-course-builder-css', tutor()->url . 'assets/css/tutor-course-builder.min.css', array(), TUTOR_VERSION ); | |
| 329 | + } | |
| 451 | 330 | /** |
| 452 | 331 | * Load tutor common scripts both backend and frontend |
| 453 | 332 | * |
| 454 | 333 | * @since v2.0.0 |
| 455 | 334 | */ |
| 456 | - wp_enqueue_script( 'tutor-script', tutor()->url . 'assets/js/tutor.js', array( 'jquery', 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true ); | |
| 335 | + wp_enqueue_script( 'tutor-script', tutor()->url . 'assets/js/tutor.min.js', array( 'jquery', 'wp-i18n' ), TUTOR_VERSION, true ); | |
| 457 | 336 | |
| 458 | 337 | /** |
| 459 | 338 | * Enqueue datetime countdown scripts & styles |
| 460 | 339 | * |
| @@ -465,17 +344,17 @@ | ||
| 465 | 344 | * @since v2.1.0 |
| 466 | 345 | */ |
| 467 | 346 | $should_enqueue = apply_filters( 'tutor_should_enqueue_countdown_scripts', false ); |
| 468 | 347 | if ( $should_enqueue ) { |
| 469 | - wp_enqueue_script( 'tutor-moment', tutor()->url . 'assets/lib/countdown/moment.min.js', array(), TUTOR_VERSION, true ); | |
| 348 | + wp_enqueue_script( 'tutor-moment', tutor()->url . 'assets/js/lib/countdown/moment.min.js', array(), TUTOR_VERSION, true ); | |
| 470 | 349 | |
| 471 | - wp_enqueue_script( 'tutor-moment-timezone', tutor()->url . 'assets/lib/countdown/moment-timezone-with-data.min.js', array(), TUTOR_VERSION, true ); | |
| 350 | + wp_enqueue_script( 'tutor-moment-timezone', tutor()->url . 'assets/js/lib/countdown/moment-timezone-with-data.min.js', array(), TUTOR_VERSION, true ); | |
| 472 | 351 | |
| 473 | - wp_enqueue_script( 'tutor-jquery-countdown', tutor()->url . 'assets/lib/countdown/jquery.countdown.min.js', array( 'jquery' ), TUTOR_VERSION, true ); | |
| 352 | + wp_enqueue_script( 'tutor-jquery-countdown', tutor()->url . 'assets/js/lib/countdown/jquery.countdown.min.js', array( 'jquery' ), TUTOR_VERSION, true ); | |
| 474 | 353 | |
| 475 | - wp_enqueue_script( 'tutor-countdown', tutor()->url . 'assets/lib/countdown/tutor-countdown.min.js', array( 'jquery' ), TUTOR_VERSION, true ); | |
| 354 | + wp_enqueue_script( 'tutor-countdown', tutor()->url . 'assets/js/lib/countdown/tutor-countdown.min.js', array( 'jquery' ), TUTOR_VERSION, true ); | |
| 476 | 355 | |
| 477 | - wp_enqueue_style( 'tutor-countdown', tutor()->url . 'assets/lib/countdown/tutor-countdown.min.css', '', TUTOR_VERSION ); | |
| 356 | + wp_enqueue_style( 'tutor-countdown', tutor()->url . 'assets/js/lib/countdown/tutor-countdown.min.css', '', TUTOR_VERSION ); | |
| 478 | 357 | } |
| 479 | 358 | } |
| 480 | 359 | |
| 481 | 360 | /** |
| @@ -488,13 +367,10 @@ | ||
| 488 | 367 | // Localize scripts. |
| 489 | 368 | $localize_data = apply_filters( 'tutor_localize_data', $this->get_default_localized_data() ); |
| 490 | 369 | wp_localize_script( 'tutor-frontend', '_tutorobject', $localize_data ); |
| 491 | 370 | wp_localize_script( 'tutor-admin', '_tutorobject', $localize_data ); |
| 371 | + wp_localize_script( 'tutor-course-builder', '_tutorobject', $localize_data ); | |
| 492 | 372 | wp_localize_script( 'tutor-script', '_tutorobject', $localize_data ); |
| 493 | - wp_localize_script( 'tutor-order-details', '_tutorobject', $localize_data ); | |
| 494 | - wp_localize_script( 'tutor-tax-settings', '_tutorobject', $localize_data ); | |
| 495 | - wp_localize_script( 'tutor-coupon', '_tutorobject', $localize_data ); | |
| 496 | - wp_localize_script( 'tutor-course-builder', '_tutorobject', $localize_data ); | |
| 497 | 373 | |
| 498 | 374 | // Inline styles. |
| 499 | 375 | wp_add_inline_style( 'tutor-frontend', $this->load_color_palette() ); |
| 500 | 376 | wp_add_inline_style( 'tutor-admin', $this->load_color_palette() ); |
| @@ -506,151 +382,97 @@ | ||
| 506 | 382 | * @since 1.0.0 |
| 507 | 383 | * @return string |
| 508 | 384 | */ |
| 509 | 385 | private function load_color_palette() { |
| 510 | - $colors = array( | |
| 511 | - 'tutor_primary_color' => '--tutor-color-primary', | |
| 512 | - 'tutor_primary_hover_color' => '--tutor-color-primary-hover', | |
| 513 | - 'tutor_text_color' => '--tutor-body-color', | |
| 514 | - 'tutor_border_color' => '--tutor-border-color', | |
| 515 | - 'tutor_gray_color' => '--tutor-color-gray', | |
| 516 | - ); | |
| 386 | + $colors = array( | |
| 387 | + 'tutor_primary_color' => '--tutor-color-primary', | |
| 388 | + 'tutor_primary_hover_color' => '--tutor-color-primary-hover', | |
| 389 | + 'tutor_text_color' => '--tutor-body-color', | |
| 390 | + 'tutor_border_color' => '--tutor-border-color', | |
| 391 | + 'tutor_gray_color' => '--tutor-color-gray', | |
| 392 | + ); | |
| 517 | 393 | |
| 518 | - // Admin colors. | |
| 519 | - $admin_colors = array(); | |
| 520 | - if ( is_admin() ) { | |
| 521 | - $admin_colors = array( | |
| 522 | - '--tutor-color-primary' => '#3E64DE', | |
| 523 | - '--tutor-color-primary-hover' => '#3A5CCC', | |
| 524 | - '--tutor-body-color' => '#212327', | |
| 525 | - '--tutor-border-color' => '#CDCFD5', | |
| 526 | - '--tutor-color-gray' => '#CDCFD5', | |
| 527 | - ); | |
| 528 | - } | |
| 394 | + // Admin colors. | |
| 395 | + $admin_colors = array(); | |
| 396 | + if ( is_admin() ) { | |
| 397 | + $admin_color = get_user_option( 'admin_color' ); | |
| 529 | 398 | |
| 530 | - $fallback_colors = array( | |
| 531 | - 'tutor_primary_color' => '#3E64DE', | |
| 532 | - 'tutor_primary_hover_color' => '#3A5CCC', | |
| 533 | - 'tutor_text_color' => '#212327', | |
| 534 | - 'tutor_border_color' => '#E3E5EB', | |
| 535 | - 'tutor_gray_color' => '#CDCFD5', | |
| 536 | - ); | |
| 399 | + switch ( $admin_color ) { | |
| 400 | + case 'light': | |
| 401 | + $admin_color_codes = array( '#04a4cc', '#04b0db' ); | |
| 402 | + break; | |
| 537 | 403 | |
| 538 | - $brand_color = tutor_utils()->get_brand_color(); | |
| 404 | + case 'modern': | |
| 405 | + $admin_color_codes = array( '#3858e9', '#4664eb' ); | |
| 406 | + break; | |
| 539 | 407 | |
| 540 | - $color_string = ''; | |
| 541 | - foreach ( $colors as $key => $property ) { | |
| 542 | - $fallback_color = isset( $fallback_colors[ $key ] ) ? $fallback_colors[ $key ] : '#212327'; | |
| 543 | - $color = $fallback_color; | |
| 408 | + case 'blue': | |
| 409 | + $admin_color_codes = array( '#e1a948', '#e3af55' ); | |
| 410 | + break; | |
| 544 | 411 | |
| 545 | - if ( Options_V2::DEFAULT_BRAND_COLOR !== $brand_color ) { | |
| 546 | - if ( 'tutor_primary_color' === $key ) { | |
| 547 | - $color = $brand_color; | |
| 548 | - } | |
| 412 | + case 'coffee': | |
| 413 | + $admin_color_codes = array( '#c7a589', '#ccad93' ); | |
| 414 | + break; | |
| 549 | 415 | |
| 550 | - if ( 'tutor_primary_hover_color' === $key ) { | |
| 551 | - $palette = $this->generate_color_palette( $brand_color ); | |
| 552 | - $color = $palette[700]; | |
| 553 | - } | |
| 554 | - } | |
| 416 | + case 'ectoplasm': | |
| 417 | + $admin_color_codes = array( '#a3b745', '#a9bd4f' ); | |
| 418 | + break; | |
| 555 | 419 | |
| 556 | - $color_rgb = tutor_utils()->hex2rgb( $color ); | |
| 420 | + case 'midnight': | |
| 421 | + $admin_color_codes = array( '#e14d43', '#e35950' ); | |
| 422 | + break; | |
| 557 | 423 | |
| 558 | - if ( is_admin() && isset( $admin_colors[ $property ] ) ) { | |
| 559 | - $color = $admin_colors[ $property ]; | |
| 560 | - $color_rgb = tutor_utils()->hex2rgb( $admin_colors[ $property ] ); | |
| 561 | - } | |
| 424 | + case 'ocean': | |
| 425 | + $admin_color_codes = array( '#9ebaa0', '#a7c0a9' ); | |
| 426 | + break; | |
| 562 | 427 | |
| 563 | - if ( $color ) { | |
| 564 | - $color_string .= $property . ':' . $color . ';'; | |
| 565 | - } | |
| 428 | + case 'sunrise': | |
| 429 | + $admin_color_codes = array( '#dd823b', '#df8a48' ); | |
| 430 | + break; | |
| 566 | 431 | |
| 567 | - if ( $color_rgb ) { | |
| 568 | - $color_string .= $property . '-rgb:' . $color_rgb . ';'; | |
| 569 | - } | |
| 570 | - } | |
| 432 | + default: | |
| 433 | + $admin_color_codes = array( '#007cba', '#006ba1' ); | |
| 434 | + break; | |
| 435 | + } | |
| 571 | 436 | |
| 572 | - return ':root{' . $color_string . '}'; | |
| 573 | - } | |
| 437 | + $admin_colors = array( | |
| 438 | + '--tutor-color-primary' => $admin_color_codes[0], | |
| 439 | + '--tutor-color-primary-hover' => $admin_color_codes[1], | |
| 440 | + ); | |
| 441 | + } | |
| 574 | 442 | |
| 575 | - /** | |
| 576 | - * Generate color palette | |
| 577 | - * | |
| 578 | - * @since 4.0.0 | |
| 579 | - * | |
| 580 | - * @param string $base_hex HEX color code. | |
| 581 | - * | |
| 582 | - * @return array | |
| 583 | - */ | |
| 584 | - private function generate_color_palette( $base_hex ) { | |
| 585 | - $base = tutor_utils()->hex_to_hsl( $base_hex ); | |
| 443 | + $fallback_colors = array( | |
| 444 | + 'tutor_primary_color' => '#3E64DE', | |
| 445 | + 'tutor_primary_hover_color' => '#395BCA', | |
| 446 | + 'tutor_text_color' => '#212327', | |
| 447 | + 'tutor_border_color' => '#E3E5EB', | |
| 448 | + 'tutor_gray_color' => '#CDCFD5', | |
| 449 | + ); | |
| 586 | 450 | |
| 587 | - // Mapping of [Hue-Shift, Saturation-Shift, Target-Lightness]. | |
| 588 | - $rules = array( | |
| 589 | - 100 => array( -1, 3, 97.5 ), | |
| 590 | - 200 => array( -3, 1, 94.1 ), | |
| 591 | - 300 => array( -3, -2, 92.2 ), | |
| 592 | - 400 => array( -4, 0, 79.6 ), | |
| 593 | - 450 => array( -2, -3, 76.7 ), | |
| 594 | - 500 => array( -4, 5, 59.8 ), | |
| 595 | - 600 => array( 0, 0, $base['l'] ), | |
| 596 | - 700 => array( 3, -7, 48.0 ), | |
| 597 | - 800 => array( 4, -12, 40.2 ), | |
| 598 | - 900 => array( 5, -17, 33.1 ), | |
| 599 | - 950 => array( 6, -24, 20.8 ), | |
| 600 | - ); | |
| 451 | + $color_string = ''; | |
| 452 | + foreach ( $colors as $key => $property ) { | |
| 453 | + $fallback_color = isset( $fallback_colors[ $key ] ) ? $fallback_colors[ $key ] : '#212327'; | |
| 454 | + $color = tutor_utils()->get_option( $key, $fallback_color ); | |
| 455 | + $color_rgb = tutor_utils()->hex2rgb( $color ); | |
| 601 | 456 | |
| 602 | - $palette = array(); | |
| 603 | - foreach ( $rules as $weight => $modifier ) { | |
| 604 | - if ( 600 === $weight ) { | |
| 605 | - $palette[ $weight ] = strtolower( $base_hex ); | |
| 606 | - continue; | |
| 607 | - } | |
| 457 | + if ( is_admin() && isset( $admin_colors[ $property ] ) ) { | |
| 458 | + $color = $admin_colors[ $property ]; | |
| 459 | + $color_rgb = tutor_utils()->hex2rgb( $admin_colors[ $property ] ); | |
| 460 | + } | |
| 608 | 461 | |
| 609 | - $new_h = fmod( ( $base['h'] + $modifier[0] + 360 ), 360 ); | |
| 610 | - $new_s = max( 0, min( 100, $base['s'] + $modifier[1] ) ); | |
| 611 | - $new_l = max( 0, min( 100, $modifier[2] ) ); | |
| 462 | + if ( $color ) { | |
| 463 | + $color_string .= $property . ':' . $color . ';'; | |
| 464 | + } | |
| 612 | 465 | |
| 613 | - $palette[ $weight ] = tutor_utils()->hsl_to_hex( $new_h, $new_s, $new_l ); | |
| 614 | - } | |
| 466 | + if ( $color_rgb ) { | |
| 467 | + $color_string .= $property . '-rgb:' . $color_rgb . ';'; | |
| 468 | + } | |
| 469 | + } | |
| 615 | 470 | |
| 616 | - return $palette; | |
| 471 | + return ':root{' . $color_string . '}'; | |
| 617 | 472 | } |
| 618 | 473 | |
| 619 | 474 | /** |
| 620 | - * Load core color palette | |
| 621 | - * | |
| 622 | - * @since 4.0.0 | |
| 623 | - * | |
| 624 | - * @param string $brand_color Base color code. | |
| 625 | - * | |
| 626 | - * @return string | |
| 627 | - */ | |
| 628 | - private function load_core_color_palette( $brand_color ) { | |
| 629 | - if ( empty( $brand_color ) ) { | |
| 630 | - return ''; | |
| 631 | - } | |
| 632 | - | |
| 633 | - $palette = $this->generate_color_palette( $brand_color ); | |
| 634 | - | |
| 635 | - return " | |
| 636 | - :root { | |
| 637 | - --tutor-brand-100: {$palette[100]}; | |
| 638 | - --tutor-brand-200: {$palette[200]}; | |
| 639 | - --tutor-brand-300: {$palette[300]}; | |
| 640 | - --tutor-brand-400: {$palette[400]}; | |
| 641 | - --tutor-brand-450: {$palette[450]}; | |
| 642 | - --tutor-brand-500: {$palette[500]}; | |
| 643 | - --tutor-brand-600: {$palette[600]}; | |
| 644 | - --tutor-brand-700: {$palette[700]}; | |
| 645 | - --tutor-brand-800: {$palette[800]}; | |
| 646 | - --tutor-brand-900: {$palette[900]}; | |
| 647 | - --tutor-brand-950: {$palette[950]}; | |
| 648 | - } | |
| 649 | - "; | |
| 650 | - } | |
| 651 | - | |
| 652 | - /** | |
| 653 | 475 | * Add Tinymce button for placing shortcode |
| 654 | 476 | * |
| 655 | 477 | * @since 1.0.0 |
| 656 | 478 | * @return void|null |
| @@ -675,9 +497,9 @@ | ||
| 675 | 497 | * @param array $plugin_array plugin array. |
| 676 | 498 | * @return array |
| 677 | 499 | */ |
| 678 | 500 | public function tutor_add_tinymce_js( $plugin_array ) { |
| 679 | - $plugin_array['tutor_button'] = tutor()->url . 'assets/lib/mce-button.js'; | |
| 501 | + $plugin_array['tutor_button'] = tutor()->url . 'assets/js/lib/mce-button.js'; | |
| 680 | 502 | return $plugin_array; |
| 681 | 503 | } |
| 682 | 504 | |
| 683 | 505 | /** |
| @@ -719,29 +541,14 @@ | ||
| 719 | 541 | * Load text domain handled script after all enqueue_scripts |
| 720 | 542 | * registered functions |
| 721 | 543 | * |
| 722 | 544 | * @since 1.9.0 |
| 723 | - * @since 3.9.2 Refactored to dynamically detect scripts instead of hardcoded list. | |
| 724 | - * | |
| 725 | 545 | * @return void |
| 726 | 546 | */ |
| 727 | 547 | public function tutor_script_text_domain() { |
| 728 | - global $wp_scripts; | |
| 729 | - | |
| 730 | - if ( empty( $wp_scripts->registered ) ) { | |
| 731 | - return; | |
| 732 | - } | |
| 733 | - | |
| 734 | - foreach ( $wp_scripts->registered as $handle => $data ) { | |
| 735 | - $src = $data->src ?? ''; | |
| 736 | - $is_from_tutor = str_contains( $src, 'tutor/assets/js' ); | |
| 737 | - | |
| 738 | - if ( ! $is_from_tutor ) { | |
| 739 | - continue; | |
| 740 | - } | |
| 741 | - | |
| 742 | - wp_set_script_translations( $handle, 'tutor', tutor()->path . 'languages/' ); | |
| 743 | - } | |
| 548 | + wp_set_script_translations( 'tutor-frontend', 'tutor', tutor()->path . 'languages/' ); | |
| 549 | + wp_set_script_translations( 'tutor-admin', 'tutor', tutor()->path . 'languages/' ); | |
| 550 | + wp_set_script_translations( 'tutor-course-builder', 'tutor', tutor()->path . 'languages/' ); | |
| 744 | 551 | } |
| 745 | 552 | |
| 746 | 553 | /** |
| 747 | 554 | * Add translation support for external tinyMCE button |
| @@ -767,9 +574,9 @@ | ||
| 767 | 574 | $to_add = array( 'tutor-lms' ); |
| 768 | 575 | |
| 769 | 576 | // Add backend course editor identifier class to body. |
| 770 | 577 | if ( $course_builder_screen ) { |
| 771 | - $to_add[] = is_admin() ? 'tutor-backend' : 'tutor-frontend'; | |
| 578 | + $to_add[] = is_admin() ? 'tutor-backend' : ''; | |
| 772 | 579 | $to_add[] = ' tutor-screen-course-builder tutor-screen-course-builder-' . $course_builder_screen . ' '; |
| 773 | 580 | } |
| 774 | 581 | |
| 775 | 582 | // Add frontend course builder identifier class. |
| @@ -776,33 +583,8 @@ | ||
| 776 | 583 | if ( ! $course_builder_screen && tutor_utils()->is_tutor_frontend_dashboard() ) { |
| 777 | 584 | $to_add[] = 'tutor-screen-frontend-dashboard'; |
| 778 | 585 | } |
| 779 | 586 | |
| 780 | - if ( is_post_type_archive( tutor()->course_post_type ) ) { | |
| 781 | - $to_add[] = 'tutor-frontend'; | |
| 782 | - } | |
| 783 | - | |
| 784 | - if ( tutor_utils()->is_tutor_frontend_dashboard() ) { | |
| 785 | - $to_add[] = 'tutor-frontend'; | |
| 786 | - } | |
| 787 | - | |
| 788 | - if ( is_single() ) { | |
| 789 | - global $post; | |
| 790 | - | |
| 791 | - $post_types = array( | |
| 792 | - tutor()->course_post_type, | |
| 793 | - tutor()->lesson_post_type, | |
| 794 | - tutor()->quiz_post_type, | |
| 795 | - tutor()->assignment_post_type, | |
| 796 | - tutor()->zoom_post_type, | |
| 797 | - tutor()->meet_post_type, | |
| 798 | - ); | |
| 799 | - | |
| 800 | - if ( isset( $post->post_type ) && in_array( $post->post_type, $post_types, true ) ) { | |
| 801 | - $to_add[] = 'tutor-frontend'; | |
| 802 | - } | |
| 803 | - } | |
| 804 | - | |
| 805 | 587 | if ( is_admin() ) { |
| 806 | 588 | $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; |
| 807 | 589 | $base = ( $screen && is_object( $screen ) && property_exists( $screen, 'base' ) ) ? $screen->base : ''; |
| 808 | 590 | $index = strpos( $base, 'tutor' ); |
| @@ -842,11 +624,11 @@ | ||
| 842 | 624 | public static function add_frontend_editor_button() { |
| 843 | 625 | $wp_screen = get_current_screen(); |
| 844 | 626 | |
| 845 | 627 | if ( is_a( $wp_screen, 'WP_Screen' ) && tutor()->course_post_type === $wp_screen->post_type ) { |
| 846 | - wp_enqueue_script( 'tutor-gutenberg', tutor()->url . 'assets/js/tutor-gutenberg.js', array(), TUTOR_VERSION, true ); | |
| 628 | + wp_enqueue_script( 'tutor-gutenberg', tutor()->url . 'assets/js/tutor-gutenberg.min.js', array(), TUTOR_VERSION, true ); | |
| 847 | 629 | $data = array( |
| 848 | - 'frontend_dashboard_url' => esc_url( trailingslashit( tutor_utils()->tutor_dashboard_url( 'create-course' ) ) ) . '?course_id=' . get_the_ID(), | |
| 630 | + 'frontend_dashboard_url' => esc_url( trailingslashit( tutor_utils()->tutor_dashboard_url( 'create-course' ) ) ) . '?course_ID=' . get_the_ID(), | |
| 849 | 631 | ); |
| 850 | 632 | |
| 851 | 633 | wp_add_inline_script( |
| 852 | 634 | 'tutor-gutenberg', |
| @@ -853,166 +635,6 @@ | ||
| 853 | 635 | 'const tutorInlineData =' . json_encode( $data ), |
| 854 | 636 | 'before' |
| 855 | 637 | ); |
| 856 | 638 | } |
| 857 | - } | |
| 858 | - | |
| 859 | - /** | |
| 860 | - * Enqueue styles & scripts for latest design system | |
| 861 | - * | |
| 862 | - * @since 4.0.0 | |
| 863 | - * | |
| 864 | - * @return void | |
| 865 | - */ | |
| 866 | - public function enqueue_scripts() { | |
| 867 | - if ( self::should_load_legacy_scripts() ) { | |
| 868 | - return; | |
| 869 | - } | |
| 870 | - | |
| 871 | - $is_dashboard = tutor_utils()->is_dashboard_page(); | |
| 872 | - $is_learning_area = tutor_utils()->is_learning_area(); | |
| 873 | - $is_kids_mode = tutor_utils()->is_kids_mode(); | |
| 874 | - $is_legacy_learning = Options_V2::LEARNING_MODE_LEGACY === tutor_utils()->get_option( 'learning_mode' ); | |
| 875 | - | |
| 876 | - $core_css_url = tutor()->assets_url . 'css/tutor-core.min.css'; | |
| 877 | - $kids_css_url = tutor()->assets_url . 'css/tutor-kids.min.css'; | |
| 878 | - $dashboard_css_url = tutor()->assets_url . 'css/tutor-dashboard.min.css'; | |
| 879 | - $learning_area_css_url = tutor()->assets_url . 'css/tutor-learning-area.min.css'; | |
| 880 | - $google_font_url = 'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap'; | |
| 881 | - | |
| 882 | - $core_js_url = tutor()->assets_url . 'js/tutor-core.js'; | |
| 883 | - $dashboard_js_url = tutor()->assets_url . 'js/tutor-dashboard.js'; | |
| 884 | - $learning_area_js_url = tutor()->assets_url . 'js/tutor-learning-area.js'; | |
| 885 | - | |
| 886 | - $version = TUTOR_ENV === 'DEV' ? time() : TUTOR_VERSION; | |
| 887 | - | |
| 888 | - $is_course_list_page = tutor_utils()->is_course_list_page(); | |
| 889 | - $is_course_details_page = tutor_utils()->is_course_details_page(); | |
| 890 | - | |
| 891 | - $localize_data = apply_filters( 'tutor_localize_data', $this->get_default_localized_data() ); | |
| 892 | - if ( $is_kids_mode ) { | |
| 893 | - $google_font_url = 'https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;500;600;700&display=swap'; | |
| 894 | - wp_enqueue_style( 'tutor-kids', $kids_css_url, array( 'tutor-core' ), $version ); | |
| 895 | - } | |
| 896 | - | |
| 897 | - // Core. | |
| 898 | - wp_enqueue_style( 'tutor-google-fonts', $google_font_url, array(), $version ); | |
| 899 | - | |
| 900 | - wp_enqueue_style( 'tutor-core', $core_css_url, array( 'tutor-google-fonts' ), $version ); | |
| 901 | - wp_enqueue_script( 'tutor-core', $core_js_url, array( 'wp-i18n' ), $version, true ); | |
| 902 | - | |
| 903 | - wp_localize_script( 'tutor-core', '_tutorobject', $localize_data ); | |
| 904 | - | |
| 905 | - // Generate color palette from user selected brand color and add to the root. | |
| 906 | - $brand_color = tutor_utils()->get_brand_color(); | |
| 907 | - if ( Options_V2::DEFAULT_BRAND_COLOR !== $brand_color ) { | |
| 908 | - wp_add_inline_style( 'tutor-core', $this->load_core_color_palette( $brand_color ) ); | |
| 909 | - } | |
| 910 | - | |
| 911 | - if ( $is_dashboard ) { | |
| 912 | - wp_enqueue_style( 'tutor-dashboard', $dashboard_css_url, array(), $version ); | |
| 913 | - wp_enqueue_script( 'tutor-dashboard', $dashboard_js_url, array( 'tutor-core', 'wp-i18n' ), $version, true ); | |
| 914 | - } | |
| 915 | - | |
| 916 | - if ( $is_learning_area ) { | |
| 917 | - wp_enqueue_style( 'tutor-learning', $learning_area_css_url, array(), $version ); | |
| 918 | - wp_enqueue_script( 'tutor-learning', $learning_area_js_url, array( 'tutor-core', 'wp-i18n' ), $version, true ); | |
| 919 | - | |
| 920 | - if ( is_single_course( true ) ) { | |
| 921 | - wp_enqueue_style( 'tutor-plyr', tutor()->url . 'assets/lib/plyr/plyr.css', array(), $version ); | |
| 922 | - wp_enqueue_script( 'tutor-plyr', tutor()->url . 'assets/lib/plyr/plyr.polyfilled.min.js', array( 'jquery' ), $version, true ); | |
| 923 | - } | |
| 924 | - } | |
| 925 | - } | |
| 926 | - | |
| 927 | - /** | |
| 928 | - * Check if need to load legacy scripts | |
| 929 | - * | |
| 930 | - * If the current screen is dashboard or new learning area | |
| 931 | - * then this method will return false to avoid loading legacy css & js files | |
| 932 | - * | |
| 933 | - * @since 4.0.0 | |
| 934 | - * | |
| 935 | - * @return boolean | |
| 936 | - */ | |
| 937 | - public static function should_load_legacy_scripts(): bool { | |
| 938 | - $load = true; | |
| 939 | - | |
| 940 | - $post_id = get_the_ID(); | |
| 941 | - | |
| 942 | - $is_learning_area = tutor_utils()->is_learning_area(); | |
| 943 | - $is_legacy_learning = tutor_utils()->is_legacy_learning_mode(); | |
| 944 | - $is_dashboard = tutor_utils()->is_dashboard_page(); | |
| 945 | - | |
| 946 | - $page_ids = array( | |
| 947 | - (int) tutor_utils()->get_option( 'student_register_page' ), | |
| 948 | - (int) tutor_utils()->get_option( 'instructor_register_page' ), | |
| 949 | - ); | |
| 950 | - | |
| 951 | - // Ignore loading legacy scripts on specific case. | |
| 952 | - if ( $is_learning_area && ! $is_legacy_learning ) { | |
| 953 | - $load = false; | |
| 954 | - } elseif ( $is_dashboard ) { | |
| 955 | - $load = false; | |
| 956 | - } elseif ( in_array( $post_id, $page_ids, true ) ) { | |
| 957 | - $load = false; | |
| 958 | - } else { | |
| 959 | - // Ignore loading legacy scripts for these shortcodes. | |
| 960 | - $has_shortcode = false; | |
| 961 | - | |
| 962 | - $shortcdes = array( | |
| 963 | - 'tutor_student_registration_form', | |
| 964 | - 'tutor_instructor_registration_form', | |
| 965 | - 'tutor_dashboard', | |
| 966 | - 'tutor_login', | |
| 967 | - ); | |
| 968 | - | |
| 969 | - $post_content = get_the_content(); | |
| 970 | - | |
| 971 | - foreach ( $shortcdes as $shortcde ) { | |
| 972 | - $has_shortcode = has_shortcode( $post_content, $shortcde ); | |
| 973 | - if ( $has_shortcode ) { | |
| 974 | - $load = false; | |
| 975 | - break; | |
| 976 | - } | |
| 977 | - } | |
| 978 | - } | |
| 979 | - | |
| 980 | - return apply_filters( 'tutor_should_load_legacy_scripts', $load ); | |
| 981 | - } | |
| 982 | - | |
| 983 | - /** | |
| 984 | - * Add custom meta data to the head section. | |
| 985 | - * | |
| 986 | - * Outputs a viewport meta tag to improve mobile responsiveness. | |
| 987 | - * | |
| 988 | - * @since 4.0.0 | |
| 989 | - * | |
| 990 | - * @return void | |
| 991 | - */ | |
| 992 | - public function add_custom_data() { | |
| 993 | - if ( tutor_utils()->is_dashboard_page() || tutor_utils()->is_learning_area() ) { | |
| 994 | - echo '<meta name="viewport" content="width=device-width, initial-scale=1" />' . "\n"; | |
| 995 | - } | |
| 996 | - } | |
| 997 | - | |
| 998 | - /** | |
| 999 | - * Add preload to CSS | |
| 1000 | - * | |
| 1001 | - * @param string $html HTML. | |
| 1002 | - * @param string $handle Handle. | |
| 1003 | - * | |
| 1004 | - * @since 4.0.0 | |
| 1005 | - * | |
| 1006 | - * @return string | |
| 1007 | - */ | |
| 1008 | - public function add_preload_to_css( $html, $handle ) { | |
| 1009 | - if ( 'tutor-google-fonts' === $handle ) { | |
| 1010 | - $html = str_replace( | |
| 1011 | - "rel='stylesheet'", | |
| 1012 | - "rel='preload' as='style' onload=\"this.onload=null;this.rel='stylesheet'\"", | |
| 1013 | - $html | |
| 1014 | - ); | |
| 1015 | - } | |
| 1016 | - return $html; | |
| 1017 | 639 | } |
| 1018 | 640 | } |