PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7
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 4.2.1 All 138 releases
learnpress / inc / admin / class-lp-admin-assets.php

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

388 lines 11.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class LP_Admin_Assets
4 *
5 * Manage admin assets
6 */
7
8 class LP_Admin_Assets extends LP_Abstract_Assets {
9 protected static $_instance;
10
11 /**
12 * LP_Admin_Assets constructor.
13 */
14 protected function __construct() {
15 add_action( 'admin_footer', array( $this, 'show_overlay' ) );
16 parent::__construct();
17 }
18
19 /**
20 * Get localize script
21 *
22 * @return array
23 */
24 protected function _get_script_data(): array {
25 $current_screen = get_current_screen();
26
27 return array(
28 'learn-press-global' => learn_press_global_script_params(),
29 'learn-press-meta-box-order' => apply_filters(
30 'learn-press/meta-box-order/script-data',
31 array(
32 'i18n_error' => esc_html__( 'Ooops! Error.', 'learnpress' ),
33 'i18n_guest' => esc_html__( 'Guest', 'learnpress' ),
34 )
35 ),
36 'learn-press-update' => apply_filters(
37 'learn-press/upgrade/script-data',
38 array(
39 'i18n_confirm' => esc_html__(
40 'Before taking this action, we strongly recommend you should backup your site first before proceeding. Should any issues come at hand, do not hesitate to contact our Support team. Are you sure to proceed the update protocol?',
41 'learnpress'
42 ),
43 )
44 ),
45 'lp-admin' => apply_filters(
46 'learn-press/admin/script-data',
47 array(
48 'ajax' => admin_url( 'admin-ajax.php' ),
49 'questionTypes' => learn_press_question_types(),
50 'supportAnswerOptions' => learn_press_get_question_support_answer_options(),
51 'screen' => $current_screen,
52 )
53 ),
54 );
55 }
56
57 /**
58 * Get default scripts in admin.
59 *
60 * @return mixed
61 */
62 protected function _get_scripts(): array {
63 $lp_admin_js = new LP_Asset_Key(
64 $this->url( self::$_folder_source . 'js/admin/admin' . self::$_min_assets . '.js' ),
65 array( 'learn-press-global', 'lp-utils', 'wp-color-picker', 'jspdf', 'vue-libs', 'wp-i18n' ),
66 array(),
67 0,
68 1
69 );
70 $lp_admin_js->exclude_screen( array( 'plugin-install' ) );
71
72 $scripts = apply_filters(
73 'learn-press/admin-default-scripts',
74 array(
75 // need build if change source vue
76 'vue-libs' => new LP_Asset_Key( $this->url( 'js/vendor/vue/vue_libs.js' ) ),
77 'select2' => new LP_Asset_Key( $this->url( 'src/js/vendor/select2.full.min.js' ) ),
78 'jquery-tipsy' => new LP_Asset_Key( $this->url( 'src/js/vendor/jquery/jquery-tipsy.js' ) ),
79 'jspdf' => new LP_Asset_Key( $this->url( 'src/js/vendor/jspdf.min.js' ) ),
80 'chart' => new LP_Asset_Key( $this->url( 'src/js/vendor/chart.min.js' ) ),
81 'dropdown-pages' => new LP_Asset_Key( $this->url( self::$_folder_source . 'js/admin/share/dropdown-pages' . self::$_min_assets . '.js' ) ),
82 'jquery-ui-timepicker-addon' => new LP_Asset_Key(
83 $this->url( 'src/js/vendor/jquery/jquery-ui-timepicker-addon.js' ),
84 array( 'jquery-ui-datepicker' )
85 ),
86 'themes-addons' => new LP_Asset_Key(
87 $this->url( 'js/dist/admin/pages/themes-addons' . self::$_min_assets . '.js' ),
88 array( 'jquery' ),
89 array( 'learnpress_page_learn-press-addons' ),
90 0,
91 1
92 ),
93 'advanced-list' => new LP_Asset_Key( $this->url( self::$_folder_source . 'js/admin/share/advanced-list' . self::$_min_assets . '.js' ) ),
94 'learn-press-global' => new LP_Asset_Key(
95 $this->url( self::$_folder_source . 'js/global' . self::$_min_assets . '.js' ),
96 array( 'jquery', 'underscore', 'utils', 'jquery-ui-sortable', 'select2' ),
97 array( 'learnpress' )
98 ),
99 'lp-utils' => new LP_Asset_Key(
100 $this->url( 'js/dist/utils' . self::$_min_assets . '.js' ),
101 array(),
102 array(),
103 1
104 ),
105 'lp-admin' => $lp_admin_js,
106 'lp-admin-learnpress' => new LP_Asset_Key(
107 $this->url( self::$_folder_source . 'js/admin/learnpress' . self::$_min_assets . '.js' ),
108 array(
109 'learn-press-global',
110 'lp-utils',
111 'wp-color-picker',
112 'jquery-tipsy',
113 'dropdown-pages',
114 'wp-api-fetch',
115 'jquery-ui-timepicker-addon',
116 ),
117 array( LP_LESSON_CPT, LP_QUIZ_CPT, LP_COURSE_CPT, LP_ORDER_CPT, 'learnpress_page_learn-press-settings' ),
118 0,
119 1
120 ),
121 'lp-duplicate-post' => new LP_Asset_Key(
122 $this->url( self::$_folder_source . 'js/admin/lp-duplicate-post' . self::$_min_assets . '.js' ),
123 array( 'jquery' ),
124 array(
125 'edit-' . LP_COURSE_CPT,
126 'edit-' . LP_LESSON_CPT,
127 'edit-' . LP_QUESTION_CPT,
128 'edit-' . LP_QUIZ_CPT,
129 ),
130 0,
131 1
132 ),
133 'learn-press-admin-course-editor' => new LP_Asset_Key(
134 $this->url( 'js/dist/admin/editor/course' . self::$_min_assets . '.js' ),
135 array( 'vue-libs' ),
136 array( LP_COURSE_CPT ),
137 0,
138 0
139 ),
140 'learn-press-admin-quiz-editor' => new LP_Asset_Key(
141 $this->url( 'js/dist/admin/editor/quiz' . self::$_min_assets . '.js' ),
142 array( 'vue-libs' ),
143 array( LP_QUIZ_CPT ),
144 0,
145 0
146 ),
147 'learn-press-admin-question-editor' => new LP_Asset_Key(
148 $this->url( 'js/dist/admin/editor/question' . self::$_min_assets . '.js' ),
149 array( 'vue-libs', 'lodash' ),
150 array( LP_QUESTION_CPT ),
151 0,
152 0
153 ),
154 'learn-press-meta-box-order' => new LP_Asset_Key(
155 $this->url( self::$_folder_source . 'js/admin/partial/meta-box-order' . self::$_min_assets . '.js' ),
156 array(
157 'vue-libs',
158 'advanced-list',
159 'lp-modal-search-courses',
160 'lp-modal-search-users',
161 ),
162 array( LP_ORDER_CPT ),
163 0,
164 1
165 ),
166 'learn-press-sync-data' => new LP_Asset_Key(
167 $this->url( 'js/dist/admin/pages/sync-data' . self::$_min_assets . '.js' ),
168 array(),
169 array( 'learnpress_page_learn-press-tools' ),
170 0,
171 1
172 ),
173 'lp-setup' => new LP_Asset_Key(
174 $this->url( 'js/dist/admin/pages/setup' . self::$_min_assets . '.js' ),
175 array( 'jquery', 'lp-utils', 'dropdown-pages' ),
176 array( 'lp-page-setup' ),
177 0,
178 1
179 ),
180 'learn-press-statistic' => new LP_Asset_Key(
181 $this->url( 'js/dist/admin/pages/statistic' . self::$_min_assets . '.js' ),
182 array( 'jquery', 'jquery-ui-datepicker', 'chart' ),
183 array( 'learnpress_page_learn-press-statistics' ),
184 0,
185 1
186 ),
187 'lp-advertisement' => new LP_Asset_Key(
188 $this->url( self::$_folder_source . 'js/admin/share/advertisement' . self::$_min_assets . '.js' ),
189 array(),
190 array(
191 'edit-' . LP_COURSE_CPT,
192 'edit-' . LP_QUESTION_CPT,
193 'edit-' . LP_LESSON_CPT,
194 'edit-' . LP_ORDER_CPT,
195 'edit-' . LP_QUIZ_CPT,
196 'learnpress_page_learn-press-settings',
197 'learnpress_page_learn-press-tools',
198 'learnpress_page_learn-press-statistics',
199 ),
200 0,
201 1
202 ),
203 'lp-modal-search-courses' => new LP_Asset_Key(
204 $this->url( self::$_folder_source . 'js/admin/share/modal-search-courses' . self::$_min_assets . '.js' ),
205 array(
206 'vue-libs',
207 'jquery',
208 ),
209 array( LP_ORDER_CPT ),
210 1,
211 1
212 ),
213 'lp-admin-tabs' => new LP_Asset_Key(
214 $this->url( self::$_folder_source . 'js/admin/share/admin-tabs' . self::$_min_assets . '.js' ),
215 array( 'jquery' ),
216 array( LP_COURSE_CPT ),
217 0,
218 1
219 ),
220 'lp-admin-notice' => new LP_Asset_Key(
221 $this->url( self::$_folder_source . 'js/admin/share/admin-notice' . self::$_min_assets . '.js' ),
222 array( 'jquery' ),
223 array(),
224 0,
225 1
226 ),
227 'lp-modal-search-users' => new LP_Asset_Key(
228 $this->url( self::$_folder_source . 'js/admin/share/modal-search-users' . self::$_min_assets . '.js' ),
229 array( 'jquery' ),
230 array( LP_ORDER_CPT ),
231 1,
232 1
233 ),
234 'lp-tools-course-tab' => new LP_Asset_Key(
235 $this->url( 'js/dist/admin/pages/tools' . self::$_min_assets . '.js' ),
236 array(
237 'jquery',
238 'wp-element',
239 'wp-compose',
240 'wp-components',
241 'wp-data',
242 'wp-hooks',
243 'wp-api-fetch',
244 'lodash',
245 'vue-libs',
246
247 ),
248 array( 'learnpress_page_learn-press-tools' ),
249 0,
250 1
251 ),
252 'lp-dashboard' => new LP_Asset_Key(
253 self::url( 'js/dist/admin/pages/dashboard' . self::$_min_assets . '.js' ),
254 array(
255 'jquery',
256 'wp-element',
257 'wp-compose',
258 'wp-data',
259 'wp-hooks',
260 'wp-api-fetch',
261 'lodash',
262 ),
263 array( 'dashboard' ),
264 0,
265 1
266 ),
267 'lp-widgets-admin' => new LP_Asset_Key(
268 self::url( 'js/dist/admin/pages/widgets' . self::$_min_assets . '.js' ),
269 array(
270 'wp-url',
271 'wp-api-fetch',
272 'lodash',
273 ),
274 array( 'widgets', 'elementor' ),
275 0,
276 1
277 ),
278 )
279 );
280
281 return $scripts;
282 }
283
284 /**
285 * Get default styles in admin.
286 *
287 * @return mixed
288 */
289 protected function _get_styles(): array {
290 $is_rtl = is_rtl() ? '-rtl' : '';
291
292 return apply_filters(
293 'learn-press/admin-default-styles',
294 array(
295 'select2' => new LP_Asset_Key(
296 $this->url( 'src/css/vendor/select2.min.css' )
297 ),
298 'font-awesome' => new LP_Asset_Key(
299 $this->url( 'src/css/vendor/font-awesome-5.min.css' )
300 ),
301 'jquery-ui' => new LP_Asset_Key(
302 $this->url( 'src/css/vendor/jquery-ui/jquery-ui.min.css' )
303 ),
304 'jquery-ui-timepicker' => new LP_Asset_Key(
305 $this->url( 'src/css/vendor/jquery-ui-timepicker-addon.css' )
306 ),
307 'jquery-tipsy' => new LP_Asset_Key(
308 $this->url( 'src/css/vendor/jquery.tipsy.css' )
309 ),
310 'learn-press-admin' => new LP_Asset_Key(
311 $this->url( 'css/admin/admin' . $is_rtl . self::$_min_assets . '.css' ),
312 array( 'wp-color-picker', 'wp-components', 'select2', 'jquery-ui', 'jquery-ui-timepicker', 'font-awesome', 'jquery-tipsy' ),
313 array(),
314 0
315 ),
316 'learn-press-statistic' => new LP_Asset_Key(
317 LP_CSS_URL . 'admin/statistic' . $is_rtl . self::$_min_assets . '.css',
318 array(),
319 array( 'learners_page_learn-press-statistics' ),
320 0
321 ),
322 )
323 );
324 }
325
326 /**
327 * Register and enqueue needed js and styles
328 */
329 public function load_scripts() {
330 $screen_id = LP_Admin::instance()->get_screen_id();
331
332 if ( empty( $screen_id ) ) {
333 return;
334 }
335 wp_enqueue_media();
336
337 $this->handle_js( $screen_id );
338
339 $this->handle_style( $screen_id );
340
341 do_action( 'learn-press/admin/after-enqueue-scripts' );
342 }
343
344 /**
345 * Register and enqueue a custom stylesheet in the WordPress admin.
346 *
347 * @author
348 */
349 public function wpdocs_enqueue_custom_admin_style() {
350 wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' );
351 wp_enqueue_style( 'custom_wp_admin_css' );
352 }
353
354 /**
355 * Show overlay
356 */
357 public function show_overlay() {
358 echo '<div class="lp-overlay">';
359 apply_filters( 'learnpress/admin/modal-dialog', learn_press_get_template( 'global/lp-modal-overlay' ) );
360 echo '</div>';
361
362 apply_filters( 'learnpress/admin/steps', learn_press_get_template( 'global/lp-group-step' ) );
363 }
364
365 public static function instance() {
366 if ( ! is_admin() ) {
367 return null;
368 }
369
370 if ( ! self::$_instance ) {
371 self::$_instance = new self();
372 }
373
374 return self::$_instance;
375 }
376 }
377
378 /**
379 * Shortcut function to get instance of LP_Admin_Assets
380 *
381 * @return LP_Admin_Assets|null
382 */
383 function learn_press_admin_assets() {
384 return LP_Admin_Assets::instance();
385 }
386
387 learn_press_admin_assets();
388