PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.6.9.4
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.6.9.4
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / class-lp-assets.php

class-lp-assets.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.6.9.4, at inc/class-lp-assets.php

318 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class LP_Assets
4 *
5 * @author ThimPress
6 * @package LearnPress/Classes
7 * @version 4.0.1
8 */
9
10 defined( 'ABSPATH' ) || exit;
11
12 class LP_Assets extends LP_Abstract_Assets {
13 protected static $_instance;
14
15 /**
16 * Constructor
17 */
18 protected function __construct() {
19 parent::__construct();
20
21 add_action( 'wp_print_footer_scripts', array( $this, 'show_overlay' ) );
22 }
23
24 /**
25 * Get default styles in frontend.
26 *
27 * @return array
28 */
29 protected function _get_styles(): array {
30 $is_rtl = is_rtl() ? '-rtl' : '';
31
32 return apply_filters(
33 'learn-press/frontend-default-styles',
34 array(
35 'font-awesome-5-all' => new LP_Asset_Key(
36 self::url( 'src/css/vendor/font-awesome-5.min.css' ),
37 array(),
38 array()
39 ),
40 'learnpress' => new LP_Asset_Key(
41 self::url( 'css/learnpress' . $is_rtl . self::$_min_assets . '.css' ),
42 array( 'font-awesome-5-all' ),
43 array( LP_PAGE_COURSES, LP_PAGE_SINGLE_COURSE, LP_PAGE_SINGLE_COURSE_CURRICULUM, LP_PAGE_QUIZ, LP_PAGE_QUESTION, LP_PAGE_CHECKOUT, LP_PAGE_BECOME_A_TEACHER, LP_PAGE_PROFILE ),
44 0
45 ),
46 'learnpress-widgets' => new LP_Asset_Key(
47 self::url( 'css/widgets' . $is_rtl . self::$_min_assets . '.css' ),
48 array(),
49 array(),
50 0
51 ),
52 )
53 );
54 }
55
56 /**
57 * Set localize script data
58 *
59 * @return array
60 */
61 public function _get_script_data(): array {
62 $localize_script = [
63 'lp-global' => array(
64 'url' => learn_press_get_current_url(),
65 'siteurl' => site_url(),
66 'ajax' => admin_url( 'admin-ajax.php' ),
67 'courses_url' => learn_press_get_page_link( 'courses' ),
68 'post_id' => get_the_ID(),
69 'user_id' => get_current_user_id(), // use: course-progress.
70 'theme' => get_stylesheet(),
71 'localize' => array(
72 'button_ok' => esc_html__( 'OK', 'learnpress' ),
73 'button_cancel' => esc_html__( 'Cancel', 'learnpress' ),
74 'button_yes' => esc_html__( 'Yes', 'learnpress' ),
75 'button_no' => esc_html__( 'No', 'learnpress' ),
76 ),
77 'lp_rest_url' => get_rest_url(),
78 'nonce' => wp_create_nonce( 'wp_rest' ),
79 'option_enable_popup_confirm_finish' => LP_Settings::get_option( 'enable_popup_confirm_finish', 'yes' ),
80 'is_course_archive' => learn_press_is_courses(),
81 ),
82 'lp-checkout' => array(
83 'ajaxurl' => home_url( '/' ),
84 'user_checkout' => LP()->checkout()->get_checkout_email(),
85 'i18n_processing' => esc_html__( 'Processing', 'learnpress' ),
86 'i18n_redirecting' => esc_html__( 'Redirecting', 'learnpress' ),
87 'i18n_invalid_field' => esc_html__( 'Invalid field', 'learnpress' ),
88 'i18n_unknown_error' => esc_html__( 'Unknown error', 'learnpress' ),
89 'i18n_place_order' => esc_html__( 'Place order', 'learnpress' ),
90 ),
91 'lp-profile-user' => array(
92 'processing' => esc_html__( 'Processing', 'learnpress' ),
93 'redirecting' => esc_html__( 'Redirecting', 'learnpress' ),
94 'avatar_size' => learn_press_get_avatar_thumb_size(),
95 ),
96 //'lp-course' => learn_press_single_course_args(),
97 'lp-quiz' => learn_press_single_quiz_args(),
98 ];
99
100 return apply_filters( 'learnpress/frontend/localize_script', $localize_script );
101
102 }
103
104 /**
105 * Config load scripts
106 *
107 * @return array
108 */
109 public function _get_scripts(): array {
110 $wp_js = array(
111 'jquery',
112 'wp-element',
113 'wp-compose',
114 'wp-data',
115 'wp-hooks',
116 'wp-api-fetch',
117 'lodash',
118 );
119
120 $scripts = apply_filters(
121 'learn-press/frontend-default-scripts',
122 array(
123 'vue-libs' => new LP_Asset_Key(
124 self::url( 'src/js/vendor/vue/vue_libs_special.min.js' )
125 ),
126 'lp-modal' => new LP_Asset_Key(
127 self::url( 'js/dist/frontend/modal' . self::$_min_assets . '.js' ),
128 array( 'jquery' )
129 ),
130 'lp-plugins-all' => new LP_Asset_Key( self::url( 'js/vendor/plugins.all.min.js' ) ),
131 'lp-global' => new LP_Asset_Key(
132 self::url( self::$_folder_source . 'js/global' . self::$_min_assets . '.js' ),
133 array( 'jquery', 'underscore', 'utils' )
134 ),
135 'lp-utils' => new LP_Asset_Key(
136 self::url( 'js/dist/utils' . self::$_min_assets . '.js' ),
137 array( 'jquery' )
138 ),
139 'lp-checkout' => new LP_Asset_Key(
140 self::url( 'js/dist/frontend/checkout' . self::$_min_assets . '.js' ),
141 array( 'lp-global', 'lp-utils', 'wp-api-fetch', 'jquery' ),
142 array( LP_PAGE_CHECKOUT ),
143 0,
144 1
145 ),
146 'lp-data-controls' => new LP_Asset_Key(
147 self::url( 'js/dist/js/data-controls' . self::$_min_assets . '.js' ),
148 array_merge( $wp_js, array( 'lp-global' ) )
149 ),
150 'lp-config' => new LP_Asset_Key(
151 self::url( 'js/dist/frontend/lp-configs' . self::$_min_assets . '.js' ),
152 array_merge( $wp_js, array( 'lp-global' ) )
153 ),
154 // 'lp-lesson' => new LP_Asset_Key( self::url( self::$_folder_source .'js/frontend/lesson' . self::$_min_assets . '.js' ) ),
155 'lp-question-types' => new LP_Asset_Key(
156 self::url( 'js/dist/frontend/question-types' . self::$_min_assets . '.js' ),
157 array_merge( $wp_js, array( 'lp-global' ) ),
158 array(),
159 1,
160 1
161 ),
162 'lp-single-curriculum' => new LP_Asset_Key(
163 self::url( 'js/dist/frontend/single-curriculum' . self::$_min_assets . '.js' ),
164 array_merge(
165 $wp_js,
166 array(
167 'lp-global',
168 'lp-utils',
169 )
170 ),
171 array( LP_PAGE_SINGLE_COURSE_CURRICULUM ),
172 0,
173 1
174 ),
175 'lp-quiz' => new LP_Asset_Key(
176 self::url( 'js/dist/frontend/quiz' . self::$_min_assets . '.js' ),
177 array_merge(
178 $wp_js,
179 array(
180 'wp-i18n',
181 'lp-global',
182 'lp-utils',
183 'lp-data-controls',
184 'lp-question-types',
185 'lp-modal',
186 'lp-config',
187 'lp-single-curriculum',
188 )
189 ),
190 array( LP_PAGE_QUIZ ),
191 0,
192 1
193 ),
194 'lp-single-course' => new LP_Asset_Key(
195 self::url( 'js/dist/frontend/single-course' . self::$_min_assets . '.js' ),
196 array_merge(
197 $wp_js,
198 array(
199 'lp-global',
200 'lp-utils',
201 )
202 ),
203 array( LP_PAGE_SINGLE_COURSE ),
204 0,
205 1
206 ),
207 'lp-courses' => new LP_Asset_Key(
208 self::url( 'js/dist/frontend/courses' . self::$_min_assets . '.js' ),
209 array( 'lp-global', 'lp-utils', 'wp-api-fetch', 'wp-hooks' ),
210 array( LP_PAGE_COURSES ),
211 0,
212 1
213 ),
214 'lp-profile' => new LP_Asset_Key(
215 self::url( 'js/dist/frontend/profile' . self::$_min_assets . '.js' ),
216 array_merge(
217 $wp_js,
218 array( 'wp-i18n', 'lp-utils' )
219 ),
220 array( LP_PAGE_PROFILE ),
221 0,
222 1
223 ),
224 'lp-widgets' => new LP_Asset_Key(
225 self::url( 'js/dist/frontend/widgets' . self::$_min_assets . '.js' ),
226 array_merge(
227 $wp_js,
228 array( 'wp-i18n' )
229 ),
230 array(),
231 1,
232 1
233 ),
234 'lp-become-a-teacher' => new LP_Asset_Key(
235 self::url( 'js/dist/frontend/become-teacher' . self::$_min_assets . '.js' ),
236 array( 'jquery', 'lp-utils' ),
237 array( LP_PAGE_BECOME_A_TEACHER ),
238 0,
239 1
240 ),
241 )
242 );
243
244 // Dequeue script 'smoothPageScroll' on item details, it makes can't scroll, when rewrite page item detail, can check to remove.
245 if ( LP_PAGE_SINGLE_COURSE_CURRICULUM === LP_Page_Controller::page_current() ||
246 LP_PAGE_QUIZ === LP_Page_Controller::page_current() ||
247 LP_PAGE_QUESTION === LP_Page_Controller::page_current() ) {
248 wp_dequeue_script( 'smoothPageScroll' );
249 }
250
251 return $scripts;
252 }
253
254 /**
255 * Load assets
256 *
257 * @author tungnx
258 * @version 1.0.1
259 * @since 3.2.8
260 */
261 public function load_scripts() {
262 $page_current = LP_Page_Controller::page_current();
263 $this->handle_js( $page_current );
264 $this->handle_style( $page_current );
265
266 do_action( 'learn-press/after-enqueue-scripts' );
267 }
268
269 /**
270 * Add lp overlay
271 *
272 * @since 3.2.8
273 * @version 1.0.1
274 * @author tungnx
275 */
276 public function show_overlay() {
277 $page_current = LP_Page_Controller::page_current();
278 if ( ! in_array(
279 $page_current,
280 array( LP_PAGE_SINGLE_COURSE_CURRICULUM, LP_PAGE_SINGLE_COURSE, LP_PAGE_QUIZ )
281 ) ) {
282 return;
283 }
284
285 if ( 'yes' !== LP_Settings::get_option( 'enable_popup_confirm_finish', 'yes' ) ) {
286 return;
287 }
288
289 echo '<div class="lp-overlay">';
290 apply_filters( 'learnpress/modal-dialog', learn_press_get_template( 'global/lp-modal-overlay' ) );
291 echo '</div>';
292 }
293
294 public static function instance() {
295 if ( is_admin() ) {
296 return null;
297 }
298
299 if ( self::$_instance == null ) {
300 self::$_instance = new self();
301 }
302
303 return self::$_instance;
304 }
305 }
306
307 /**
308 * Shortcut function to get instance of LP_Assets
309 *
310 * @return LP_Assets|null
311 */
312 function learn_press_assets() {
313 return LP_Assets::instance();
314 }
315
316 learn_press_assets();
317
318