PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.10
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.10
4.4.10 4.4.9.1 4.4.9 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 All 142 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.4.10, at inc/admin/class-lp-admin-assets.php

871 lines 30.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use LearnPress\Helpers\Config;
4 use LearnPress\Helpers\Template;
5 use LearnPress\Models\CourseModel;
6 use LearnPress\Statistics\PeriodResolver;
7
8 /**
9 * Class LP_Admin_Assets
10 *
11 * Manage admin assets
12 */
13 class LP_Admin_Assets extends LP_Abstract_Assets {
14 protected static $_instance;
15
16 /**
17 * LP_Admin_Assets constructor.
18 */
19 protected function __construct() {
20 add_action( 'admin_footer', array( $this, 'add_elements_global' ) );
21 add_action( 'admin_print_scripts', array( $this, 'load_scripts_styles_on_head' ), - 1 );
22 parent::__construct();
23 }
24
25 /**
26 * Add javascript to head
27 * Add style to head
28 *
29 * @return void
30 * @version 1.0.0
31 * @since 4.2.5.6
32 */
33 public function load_scripts_styles_on_head() {
34 LP_Helper::print_inline_script_tag( 'lpDataAdmin', $this->localize_data_global(), array( 'id' => 'lpDataAdmin' ) );
35 LP_Helper::print_inline_script_tag( 'lpData', $this->localize_data_global(), array( 'id' => 'lpData' ) );
36 }
37
38 /**
39 * Localize data for all page backend.
40 *
41 * @return array
42 * @since 4.2.5.6
43 * @version 1.0.2
44 */
45 public function localize_data_global(): array {
46 $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
47
48 ob_start();
49 Template::instance()->get_admin_template( 'search-author-field.php' );
50 $html_search_author_field = ob_get_clean();
51
52 return apply_filters(
53 'learn-press/admin/localize-data-global',
54 array(
55 'site_url' => site_url(),
56 'user_id' => get_current_user_id(),
57 'is_admin' => current_user_can( ADMIN_ROLE ),
58 'theme' => get_stylesheet(),
59 'lp_version' => LP()->version,
60 'lp_rest_url' => get_rest_url(),
61 'lp_rest_load_ajax' => get_rest_url( null, 'lp/v1/load_content_via_ajax/' ), // @deprecated 4.3.0
62 'lpAjaxUrl' => LP_Settings::url_handle_lp_ajax(),
63 'nonce' => wp_create_nonce( 'wp_rest' ),
64 'courses_url' => learn_press_get_page_link( 'courses' ),
65 'urlParams' => lp_archive_skeleton_get_args(),
66 'i18n' => array(
67 'select_page' => esc_html__( 'Select page', 'learnpress' ),
68 'yes' => esc_html__( 'Yes' ),
69 'cancel' => esc_html__( 'Cancel' ),
70 'generate_with_ai' => esc_html__( 'Generate with AI', 'learnpress' ),
71 'confirm_close_ai' => esc_html__( 'Are you sure you want to close? Generate data will stop.', 'learnpress' ),
72 'select_user' => esc_html__( 'Select users', 'learnpress' ),
73 ),
74 'current_screen' => $screen ? $screen->id : '',
75 'show_search_author_field' => empty( $html_search_author_field ) ? 0 : $html_search_author_field,
76 'toast' => array(
77 'gravity' => 'bottom',
78 'position' => 'center',
79 'duration' => 3000,
80 'close' => 1,
81 'stopOnFocus' => 1,
82 'classPrefix' => 'lp-toast',
83 ),
84 'single_instructor_id' => learn_press_get_page_id( 'single_instructor' ),
85 'lpAi' => array(
86 'config' => Config::instance()->get( 'open-ai-modal', 'settings' ),
87 'modelImage' => LP_Settings::get_option( 'open_ai_image_model_type', 'gpt-image-1' ),
88 ),
89 'enable_open_ai' => LP_Settings::get_option( 'enable_open_ai', 'no' ) === 'yes'
90 && ! empty( LP_Settings::get_option( 'open_ai_secret_key', '' ) ),
91 )
92 );
93 }
94
95 /**
96 * Get localize script
97 *
98 * @return array
99 */
100 protected function _get_script_data(): array {
101 $current_screen = get_current_screen();
102
103 return array(
104 'learn-press-global' => learn_press_global_script_params(),
105 /*
106 'learn-press-meta-box-order' => apply_filters(
107 'learn-press/meta-box-order/script-data',
108 array(
109 'i18n_error' => esc_html__( 'Oops! Error.', 'learnpress' ),
110 'i18n_guest' => esc_html__( 'Guest', 'learnpress' ),
111 )
112 ),*/
113 /*
114 'learn-press-update' => apply_filters(
115 'learn-press/upgrade/script-data',
116 array(
117 'i18n_confirm' => esc_html__(
118 'Before taking this action, we strongly recommend you backup your site first before proceeding. If you encounter any problems, please do not hesitate to contact our support team. Are you sure to proceed with the update protocol?',
119 'learnpress'
120 ),
121 )
122 ),*/
123 'lp-admin' => apply_filters(
124 'learn-press/admin/script-data',
125 array(
126 'ajax' => admin_url( 'admin-ajax.php' ),
127 'questionTypes' => learn_press_question_types(),
128 'supportAnswerOptions' => learn_press_get_question_support_answer_options(),
129 'screen' => $current_screen,
130 )
131 ),
132 // Statistics dashboard config → JS global lpAdminStatisticSettings.
133 // REST root + nonce come from lpDataAdmin (already on every admin page).
134 'lp-admin-statistic' => apply_filters(
135 'learn-press/admin/statistics/script-data',
136 array(
137 'restNamespace' => 'lp/v1/statistics',
138 'adminUrl' => admin_url(),
139 // decode: JS renders via textContent, entities would show literally.
140 'currencySymbol' => html_entity_decode( learn_press_get_currency_symbol() ),
141 'completionTarget' => (int) apply_filters( 'learn-press/statistics/completion-target', 70 ),
142 // Completion badge bands: >= green is green, >= yellow is yellow, below is red.
143 'completionBadge' => apply_filters(
144 'learn-press/statistics/completion-badge-thresholds',
145 array(
146 'green' => 60,
147 'yellow' => 40,
148 )
149 ),
150 // Date-range dropdown: per-preset resolved labels ( the server is the
151 // single source of calendar logic — JS never re-derives windows ).
152 'dateRange' => array(
153 'presets' => self::statistics_date_range_presets(),
154 'startOfWeek' => (int) get_option( 'start_of_week', 1 ),
155 'dateFormat' => (string) get_option( 'date_format', 'F j, Y' ),
156 ),
157 'i18n' => array(
158 'loadError' => esc_html__( 'Failed to load statistics data.', 'learnpress' ),
159 'noData' => esc_html__( 'No data for this period.', 'learnpress' ),
160 // Date-range dropdown.
161 'presets' => esc_html__( 'Presets', 'learnpress' ),
162 'custom' => esc_html__( 'Custom', 'learnpress' ),
163 'compareTo' => esc_html__( 'Compare to', 'learnpress' ),
164 'previousPeriod' => esc_html__( 'Previous period', 'learnpress' ),
165 'previousYear' => esc_html__( 'Previous year', 'learnpress' ),
166 'update' => esc_html__( 'Update', 'learnpress' ),
167 'from' => esc_html__( 'From', 'learnpress' ),
168 'to' => esc_html__( 'To', 'learnpress' ),
169 'selectDateRange' => esc_html__( 'Select a date range', 'learnpress' ),
170 'itemsCount' => esc_html__( '%d items', 'learnpress' ),
171 'cappedNotice' => esc_html__( 'Showing the first %d rows. Narrow the period or filters to see the rest.', 'learnpress' ),
172 'vsPrevPeriod' => esc_html__( 'vs previous period', 'learnpress' ),
173 'revenue' => esc_html__( 'Revenue', 'learnpress' ),
174 'enrollments' => esc_html__( 'Enrollments', 'learnpress' ),
175 'aov' => esc_html__( 'Avg. order value: %s', 'learnpress' ),
176 'belowTarget' => esc_html__( '%d below completion target', 'learnpress' ),
177 'failRate' => esc_html__( '%s%% of all orders', 'learnpress' ),
178 'course' => esc_html__( 'Course', 'learnpress' ),
179 'orders' => esc_html__( 'Orders', 'learnpress' ),
180 'aovShort' => esc_html__( 'AOV', 'learnpress' ),
181 'status' => esc_html__( 'Status', 'learnpress' ),
182 'enrolled' => esc_html__( 'Enrolled', 'learnpress' ),
183 'completion' => esc_html__( 'Completion', 'learnpress' ),
184 'instructor' => esc_html__( 'Instructor', 'learnpress' ),
185 'courses' => esc_html__( 'Courses', 'learnpress' ),
186 'topCourses' => esc_html__( 'Top courses', 'learnpress' ),
187 'topSoldCourses' => esc_html__( 'Top sold courses', 'learnpress' ),
188 'healthy' => esc_html__( 'Healthy', 'learnpress' ),
189 'watchCompletion' => esc_html__( 'Watch completion', 'learnpress' ),
190 'highFailedQuizzes' => esc_html__( 'High failed quizzes', 'learnpress' ),
191 'needsFulfillmentReview' => esc_html__( 'Needs fulfillment review', 'learnpress' ),
192 'awaitingPayment' => esc_html__( 'Awaiting payment', 'learnpress' ),
193 'exceptionRate' => esc_html__( '%s%% of all orders', 'learnpress' ),
194 'orderId' => esc_html__( 'Order ID', 'learnpress' ),
195 'student' => esc_html__( 'Student', 'learnpress' ),
196 'issue' => esc_html__( 'Issue', 'learnpress' ),
197 'date' => esc_html__( 'Date', 'learnpress' ),
198 'severity' => esc_html__( 'Severity', 'learnpress' ),
199 'high' => esc_html__( 'High', 'learnpress' ),
200 'medium' => esc_html__( 'Medium', 'learnpress' ),
201 'low' => esc_html__( 'Low', 'learnpress' ),
202 'orderExceptions' => esc_html__( 'Recent order exceptions', 'learnpress' ),
203 'noOrderExceptions' => esc_html__( 'No failed or cancelled orders in this period.', 'learnpress' ),
204 'addedThisPeriod' => esc_html__( '%d added this period', 'learnpress' ),
205 'needsInstructorAction' => esc_html__( 'Needs instructor action', 'learnpress' ),
206 'scheduledReleases' => esc_html__( 'Scheduled releases', 'learnpress' ),
207 'targetPercent' => esc_html__( 'Target: %s%%', 'learnpress' ),
208 'publishedCourses' => esc_html__( 'Published courses', 'learnpress' ),
209 'noCoursePerformance' => esc_html__( 'No course performance data in this period.', 'learnpress' ),
210 'coursePerformance' => esc_html__( 'Course performance', 'learnpress' ),
211 'lessons' => esc_html__( 'Lessons', 'learnpress' ),
212 'quizzes' => esc_html__( 'Quizzes', 'learnpress' ),
213 'assignments' => esc_html__( 'Assignments', 'learnpress' ),
214 'published' => esc_html__( 'Published', 'learnpress' ),
215 'pending' => esc_html__( 'Pending', 'learnpress' ),
216 'future' => esc_html__( 'Future', 'learnpress' ),
217 'drafts' => esc_html__( 'Drafts', 'learnpress' ),
218 'total' => esc_html__( 'Total', 'learnpress' ),
219 'content' => esc_html__( 'Content', 'learnpress' ),
220 'newThisPeriod' => esc_html__( '+%d this period', 'learnpress' ),
221 'activeInPeriod' => esc_html__( '%d active in this period', 'learnpress' ),
222 'activeThisPeriod' => esc_html__( 'active this period', 'learnpress' ),
223 'afterEnrollment' => esc_html__( 'After enrollment', 'learnpress' ),
224 'currentLearners' => esc_html__( 'Current learners', 'learnpress' ),
225 'completionRateSub' => esc_html__( '%s%% completion rate', 'learnpress' ),
226 'registeredUsers' => esc_html__( 'Registered users', 'learnpress' ),
227 'topStudents' => esc_html__( 'Top students', 'learnpress' ),
228 'topCoursesByStudents' => esc_html__( 'Top courses by students', 'learnpress' ),
229 'avgScore' => esc_html__( 'Quiz pass rate', 'learnpress' ),
230 'lastActive' => esc_html__( 'Last active', 'learnpress' ),
231 'startedLabel' => esc_html__( 'Started', 'learnpress' ),
232 'completedLabel' => esc_html__( 'Completed', 'learnpress' ),
233 'activeLast7dShort' => esc_html__( 'Active 7d', 'learnpress' ),
234 'statusActive' => esc_html__( 'Active', 'learnpress' ),
235 'statusAtRisk' => esc_html__( 'At risk', 'learnpress' ),
236 'statusIdle' => esc_html__( 'Idle', 'learnpress' ),
237 // Instructors tab.
238 'ofNetSales' => esc_html__( '%s%% of net sales', 'learnpress' ),
239 'ofTotalInstructors' => esc_html__( '%d total', 'learnpress' ),
240 'students' => esc_html__( 'Students', 'learnpress' ),
241 'sold' => esc_html__( 'Sold', 'learnpress' ),
242 'risk' => esc_html__( 'Risk', 'learnpress' ),
243 'actionRequired' => esc_html__( 'Action required', 'learnpress' ),
244 'riskHigh' => esc_html__( 'High', 'learnpress' ),
245 'riskMedium' => esc_html__( 'Medium', 'learnpress' ),
246 'riskHealthy' => esc_html__( 'Healthy', 'learnpress' ),
247 'instructorPerformance' => esc_html__( 'Instructor performance', 'learnpress' ),
248 'instructorReport' => esc_html__( 'Instructor report', 'learnpress' ),
249 'noInstructorData' => esc_html__( 'No instructor data in this period.', 'learnpress' ),
250 'instructorReportEmpty' => esc_html__( 'This instructor has no courses yet.', 'learnpress' ),
251 'watchlistActions' => array(
252 'review_quiz_difficulty' => esc_html__( 'Review quiz difficulty', 'learnpress' ),
253 'build_curriculum' => esc_html__( 'Build the curriculum', 'learnpress' ),
254 'add_practice_content' => esc_html__( 'Add practice content', 'learnpress' ),
255 'monitor' => esc_html__( 'Monitor', 'learnpress' ),
256 ),
257 ),
258 )
259 ),
260 // @deprecated tag 'learn-press-admin-course-editor' 4.4.2 - no any enqueue js for that.
261 // 'learn-press-admin-course-editor' => $this->get_course_data_for_editor_vue(),
262 );
263 }
264
265 /**
266 * Preset entries for the statistics date-range dropdown.
267 *
268 * UI presets in display order. Labels are resolved server-side so JS never
269 * re-implements calendar logic.
270 *
271 * @return array[] [ { value, name, rangeLabel } ]
272 * @since 4.4.2
273 */
274 private static function statistics_date_range_presets(): array {
275 $presets = array();
276
277 foreach ( PeriodResolver::UI_PRESETS as $preset ) {
278 $presets[] = array(
279 'value' => $preset,
280 'name' => PeriodResolver::preset_name( $preset ),
281 'rangeLabel' => PeriodResolver::range_label_for( PeriodResolver::resolve( $preset ) ),
282 );
283 }
284
285 return $presets;
286 }
287
288 /**
289 * Get default scripts in admin.
290 *
291 * @return mixed
292 */
293 protected function _get_scripts(): array {
294 $lp_admin_js = new LP_Asset_Key(
295 $this->url( 'js/dist/admin/admin' . self::$_min_assets . '.js' ),
296 array( 'wp-i18n', 'lp-utils' ),
297 array(),
298 0,
299 0,
300 '',
301 array( 'strategy' => 'async' )
302 );
303 $lp_admin_js->exclude_screen(
304 array(
305 'plugin-install',
306 'learnpress_page_learn-press-statistics',
307 'learnpress_page_learn-press-addons',
308 )
309 );
310
311 $scripts = apply_filters(
312 'learn-press/admin-default-scripts',
313 array(
314 'lp-load-ajax' => new LP_Asset_Key(
315 self::url( 'js/dist/loadAJAX' . self::$_min_assets . '.js' ),
316 array(),
317 array(),
318 0,
319 0,
320 '',
321 array( 'strategy' => 'async' )
322 ),
323 // need build if change source vue
324 //'vue-libs' => new LP_Asset_Key( $this->url( 'js/vendor/vue/vue_libs.js' ) ),
325 //'select2' => new LP_Asset_Key( $this->url( 'src/js/vendor/select2.full.min.js' ) ),
326 'jquery-tipsy' => new LP_Asset_Key( $this->url( 'src/js/vendor/jquery/jquery-tipsy.js' ) ),
327 'html2pdf' => new LP_Asset_Key( $this->url( 'src/js/vendor/html2pdf.bundle.min.js' ) ),
328 'lp-utils' => new LP_Asset_Key(
329 $this->url( 'js/dist/utils' . self::$_min_assets . '.js' ),
330 array(),
331 array(),
332 1
333 ),
334 /*
335 'jquery-ui-timepicker-addon' => new LP_Asset_Key(
336 $this->url( 'src/js/vendor/jquery/jquery-ui-timepicker-addon.js' ),
337 array( 'jquery-ui-datepicker' )
338 ),*/
339 'lp-addons' => new LP_Asset_Key(
340 $this->url( 'js/dist/admin/addons' . self::$_min_assets . '.js' ),
341 array(),
342 array( 'learnpress_page_learn-press-addons' ),
343 0,
344 0,
345 '',
346 array( 'strategy' => 'async' )
347 ),
348 // 'advanced-list' => new LP_Asset_Key( $this->url( self::$_folder_source . 'js/admin/share/advanced-list' . self::$_min_assets . '.js' ) ),
349 'learn-press-global' => new LP_Asset_Key(
350 $this->url( self::$_folder_source . 'js/global' . self::$_min_assets . '.js' ),
351 array( 'jquery', 'underscore', 'utils', 'jquery-ui-sortable' )
352 ),
353 'lp-admin' => $lp_admin_js,
354 'lp-admin-mcp-api-keys' => new LP_Asset_Key(
355 $this->url( 'js/dist/admin/mcp-api-keys.js' ),
356 [ 'lp-load-ajax' ],
357 [ 'learnpress_page_learn-press-settings' ],
358 0,
359 1,
360 '',
361 array( 'strategy' => 'defer' )
362 ),
363 'lp-admin-webhooks' => new LP_Asset_Key(
364 $this->url( 'js/dist/admin/webhooks.js' ),
365 [ 'lp-load-ajax', 'lp-admin' ],
366 [ 'learnpress_page_learn-press-settings' ],
367 0,
368 1,
369 '',
370 [ 'strategy' => 'defer' ]
371 ),
372 'lp-admin-learnpress' => new LP_Asset_Key(
373 $this->url( 'js/dist/admin/learnpress' . self::$_min_assets . '.js' ),
374 array(
375 'learn-press-global',
376 'wp-color-picker',
377 'jquery-tipsy',
378 'wp-api-fetch',
379 // 'jquery-ui-timepicker-addon',
380 // 'select2'
381 ),
382 array(
383 LP_LESSON_CPT,
384 LP_QUIZ_CPT,
385 LP_COURSE_CPT,
386 // LP_ORDER_CPT,
387 'learnpress_page_learn-press-settings',
388 ),
389 0,
390 1,
391 '',
392 array( 'strategy' => 'defer' )
393 ),
394 'lp-duplicate-post' => new LP_Asset_Key(
395 $this->url( self::$_folder_source . 'js/admin/lp-duplicate-post' . self::$_min_assets . '.js' ),
396 array( 'jquery' ),
397 array(
398 'edit-' . LP_COURSE_CPT,
399 'edit-' . LP_LESSON_CPT,
400 'edit-' . LP_QUESTION_CPT,
401 'edit-' . LP_QUIZ_CPT,
402 ),
403 0,
404 1
405 ),
406 /*
407 'learn-press-admin-course-editor' => new LP_Asset_Key(
408 $this->url( 'js/dist/admin/editor/course' . self::$_min_assets . '.js' ),
409 array( 'vue-libs', 'lp-utils' ),
410 array( LP_COURSE_CPT ),
411 0,
412 0
413 ),*/
414 'lp-admin-courses' => new LP_Asset_Key(
415 $this->url( 'dist/js/admin/admin-courses' . self::$_min_assets . '.js' ),
416 array( 'lp-load-ajax', 'wp-i18n' ),
417 array( 'edit-' . LP_COURSE_CPT ),
418 0,
419 0,
420 '',
421 array( 'strategy' => 'async' )
422 ),
423 'lp-edit-course' => new LP_Asset_Key(
424 $this->url( 'dist/js/admin/edit-course' . self::$_min_assets . '.js' ),
425 array( 'lp-load-ajax' ),
426 array(),
427 1,
428 0,
429 '',
430 array( 'strategy' => 'async' )
431 ),
432 'lp-edit-quiz' => new LP_Asset_Key(
433 $this->url( 'dist/js/admin/edit-quiz' . self::$_min_assets . '.js' ),
434 array( 'lp-load-ajax' ),
435 array(),
436 1,
437 0,
438 '',
439 array( 'strategy' => 'async' )
440 ),
441 'lp-edit-question' => new LP_Asset_Key(
442 $this->url( 'dist/js/admin/edit-question' . self::$_min_assets . '.js' ),
443 array( 'lp-load-ajax' ),
444 array(),
445 1,
446 0,
447 '',
448 array( 'strategy' => 'async' )
449 ),
450 /*
451 'learn-press-admin-quiz-editor' => new LP_Asset_Key(
452 $this->url( 'js/dist/admin/editor/quiz' . self::$_min_assets . '.js' ),
453 array( 'vue-libs', 'lp-utils' ),
454 array( LP_QUIZ_CPT ),
455 0,
456 0
457 ),*/
458 /*
459 'learn-press-admin-question-editor' => new LP_Asset_Key(
460 $this->url( 'js/dist/admin/editor/question' . self::$_min_assets . '.js' ),
461 array( 'vue-libs', 'lodash', 'lp-utils' ),
462 array( LP_QUESTION_CPT ),
463 0,
464 0
465 ),*/
466 /*
467 'learn-press-meta-box-order' => new LP_Asset_Key(
468 $this->url( self::$_folder_source . 'js/admin/partial/meta-box-order' . self::$_min_assets . '.js' ),
469 array(
470 'vue-libs',
471 'advanced-list',
472 //'lp-modal-search-courses',
473 //'lp-modal-search-users',
474 ),
475 array( LP_ORDER_CPT ),
476 0,
477 1
478 ),*/
479 'lp-admin-order' => new LP_Asset_Key(
480 $this->url( 'js/dist/admin/admin-order' . self::$_min_assets . '.js' ),
481 array( 'html2pdf', 'lp-load-ajax' ),
482 array( LP_ORDER_CPT ),
483 0,
484 0,
485 '',
486 array( 'strategy' => 'defer' )
487 ),
488 'lp-admin-orders' => new LP_Asset_Key(
489 $this->url( 'js/dist/admin/admin-orders' . self::$_min_assets . '.js' ),
490 array(),
491 array( 'edit-' . LP_ORDER_CPT ),
492 0,
493 0,
494 '',
495 array( 'strategy' => 'async' )
496 ),
497
498 /*
499 'learn-press-sync-data' => new LP_Asset_Key(
500 $this->url( 'js/dist/admin/pages/sync-data' . self::$_min_assets . '.js' ),
501 array(),
502 array( 'learnpress_page_learn-press-tools' ),
503 0,
504 1
505 ),*/
506 'lp-setup-wizard' => new LP_Asset_Key(
507 $this->url( 'dist/js/admin/setup-wizard' . self::$_min_assets . '.js' ),
508 [],
509 array( 'lp-page-setup' ),
510 0,
511 1
512 ),
513 /*
514 'learn-press-statistic' => new LP_Asset_Key(
515 $this->url( 'js/dist/admin/pages/statistic' . self::$_min_assets . '.js' ),
516 array( 'jquery', 'jquery-ui-datepicker', 'chart' ),
517 array( 'learnpress_page_learn-press-statistics' ),
518 0,
519 1
520 ),*/
521 /*
522 'lp-modal-search-courses' => new LP_Asset_Key(
523 $this->url( self::$_folder_source . 'js/admin/share/modal-search-courses' . self::$_min_assets . '.js' ),
524 array(
525 'vue-libs',
526 'jquery',
527 ),
528 array( LP_ORDER_CPT ),
529 1,
530 1
531 ),*/
532 /*
533 'lp-modal-search-users' => new LP_Asset_Key(
534 $this->url( self::$_folder_source . 'js/admin/share/modal-search-users' . self::$_min_assets . '.js' ),
535 array( 'jquery' ),
536 array( LP_ORDER_CPT ),
537 1,
538 1
539 ),*/
540 'lp-tools-course-tab' => new LP_Asset_Key(
541 $this->url( 'js/dist/admin/pages/tools' . self::$_min_assets . '.js' ),
542 [],
543 array( 'learnpress_page_learn-press-tools' ),
544 0,
545 1,
546 '',
547 array( 'strategy' => 'defer' )
548 ),
549 /*
550 'lp-dashboard' => new LP_Asset_Key(
551 self::url( 'js/dist/admin/pages/dashboard' . self::$_min_assets . '.js' ),
552 [],
553 array( 'dashboard' ),
554 0,
555 1
556 ),*/
557 'lp-widgets-admin' => new LP_Asset_Key(
558 self::url( 'js/dist/admin/pages/widgets' . self::$_min_assets . '.js' ),
559 array(
560 'wp-url',
561 'wp-api-fetch',
562 'lodash',
563 //'select2',
564 ),
565 array( 'widgets', 'elementor' ),
566 0,
567 1
568 ),
569 'lp-admin-notices' => new LP_Asset_Key(
570 self::url( 'js/dist/admin/admin-notices' . self::$_min_assets . '.js' ),
571 array(),
572 array(),
573 1,
574 0,
575 '',
576 array( 'strategy' => 'async' )
577 ),
578 'lp-material' => new LP_Asset_Key(
579 $this->url( 'js/dist/admin/course-material' . self::$_min_assets . '.js' ),
580 array(),
581 array(
582 LP_COURSE_CPT,
583 LP_LESSON_CPT,
584 ),
585 0,
586 1
587 ),
588 'lp-list-students-enrolled' => new LP_Asset_Key(
589 $this->url( 'dist/js/admin/list-students-enrolled' . self::$_min_assets . '.js' ),
590 array( 'lp-load-ajax' ),
591 array( 'learnpress_page_learn-press-students-enrolled' ),
592 0,
593 0,
594 '',
595 array( 'strategy' => 'async' )
596 ),
597 'lp-admin-tools' => new LP_Asset_Key(
598 $this->url( 'dist/js/admin/admin-tools' . self::$_min_assets . '.js' ),
599 array(),
600 array( 'learnpress_page_learn-press-tools' ),
601 0,
602 0,
603 '',
604 array( 'strategy' => 'defer' )
605 ),
606 'lp-themes' => new LP_Asset_Key(
607 $this->url( 'dist/js/admin/lp-themes' . self::$_min_assets . '.js' ),
608 array(),
609 array( 'learnpress_page_learn-press-themes' ),
610 0,
611 0,
612 '',
613 array( 'strategy' => 'async' )
614 ),
615 'lp-admin-statistic' => new LP_Asset_Key(
616 $this->url( 'js/dist/admin/admin-statistic' . self::$_min_assets . '.js' ),
617 array( 'lp-load-ajax' ),
618 array( 'learnpress_page_learn-press-statistics' ),
619 0,
620 0,
621 '',
622 array( 'strategy' => 'defer' )
623 ),
624 )
625 );
626
627 /*
628 $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
629 if ( $screen && $screen->id === 'site-editor' ) {
630 $scripts['editor-check'] = new LP_Asset_Key(
631 self::url( 'js/dist/gutenberg/editor-check' . self::$_min_assets . '.js' ),
632 array(
633 'wp-data',
634 'wp-edit-post',
635 'wp-editor',
636 ),
637 [],
638 0,
639 0,
640 '1.0.0',
641 [ 'strategy' => 'defer' ]
642 );
643 }*/
644
645 return $scripts;
646 }
647
648 /**
649 * Get default styles in admin.
650 *
651 * @return mixed
652 */
653 protected function _get_styles(): array {
654 $is_rtl = is_rtl() ? '-rtl' : '';
655
656 return apply_filters(
657 'learn-press/admin-default-styles',
658 array(
659 /*'select2' => new LP_Asset_Key(
660 $this->url( 'src/css/vendor/select2.min.css' )
661 ),*/
662 /*
663 'font-awesome' => new LP_Asset_Key(
664 $this->url( 'src/css/vendor/font-awesome-5.min.css' )
665 ),*/
666 /*
667 'jquery-ui' => new LP_Asset_Key(
668 $this->url( 'src/css/vendor/jquery-ui/jquery-ui.min.css' )
669 ),
670 'jquery-ui-timepicker' => new LP_Asset_Key(
671 $this->url( 'src/css/vendor/jquery-ui-timepicker-addon.css' )
672 ),*/
673 'jquery-tipsy' => new LP_Asset_Key(
674 $this->url( 'src/css/vendor/jquery.tipsy.css' )
675 ),
676 'learn-press-admin' => new LP_Asset_Key(
677 $this->url( 'css/admin/admin' . $is_rtl . self::$_min_assets . '.css' ),
678 array(
679 'wp-color-picker',
680 'wp-components',
681 // 'select2',
682 // 'jquery-ui',
683 // 'jquery-ui-timepicker',
684 // 'font-awesome',
685 'jquery-tipsy',
686 ),
687 array(),
688 0
689 ),
690 'lp-help-center' => new LP_Asset_Key(
691 $this->url( 'css/admin/help-center' . $is_rtl . self::$_min_assets . '.css' ),
692 array(),
693 array( 'learnpress_page_learn-press-help-center' ),
694 0
695 ),
696 'lp-themes' => new LP_Asset_Key(
697 $this->url( 'css/admin/themes' . $is_rtl . self::$_min_assets . '.css' ),
698 array(),
699 array( 'learnpress_page_learn-press-themes' ),
700 0,
701 0
702 ),
703 'lp-edit-curriculum' => new LP_Asset_Key(
704 $this->url( 'css/edit-curriculum' . $is_rtl . self::$_min_assets . '.css' ),
705 array(),
706 array(),
707 1
708 ),
709 'lp-edit-quiz' => new LP_Asset_Key(
710 $this->url( 'css/edit-quiz' . $is_rtl . self::$_min_assets . '.css' ),
711 array(),
712 array(),
713 1
714 ),
715 'lp-edit-question' => new LP_Asset_Key(
716 $this->url( 'css/edit-question' . $is_rtl . self::$_min_assets . '.css' ),
717 array(),
718 array(),
719 1
720 ),
721 /*'learn-press-statistic' => new LP_Asset_Key(
722 LP_CSS_URL . 'admin/statistic' . $is_rtl . self::$_min_assets . '.css',
723 array(),
724 array( 'learners_page_learn-press-statistics' ),
725 0
726 ),*/
727 'lp-tom-select' => new LP_Asset_Key(
728 $this->url( 'src/css/vendor/tom-select.min.css' ),
729 array(),
730 array(),
731 0
732 ),
733 'lp-setup-wizard' => new LP_Asset_Key(
734 $this->url( 'css/admin/setup-wizard' . $is_rtl . self::$_min_assets . '.css' ),
735 array(),
736 array(),
737 1
738 ),
739 )
740 );
741 }
742
743 /**
744 * Register and enqueue needed js and styles
745 */
746 public function load_scripts() {
747 $screen_id = LP_Admin::instance()->get_screen_id();
748
749 if ( empty( $screen_id ) ) {
750 $screen_id = '';
751 }
752
753 // wp_enqueue_media(); //Todo: tungnx need check why call for that using.
754 $this->handle_js( $screen_id );
755 $this->handle_style( $screen_id );
756
757 do_action( 'learn-press/admin/after-enqueue-scripts' );
758 }
759
760 /**
761 * Show overlay
762 */
763 public function add_elements_global() {
764 echo '<div class="lp-overlay">';
765 apply_filters( 'learnpress/admin/modal-dialog', learn_press_get_template( 'global/lp-modal-overlay' ) );
766 echo '</div>';
767
768 apply_filters( 'learnpress/admin/steps', learn_press_get_template( 'global/lp-group-step' ) );
769
770 // Added notify message when action done.
771 Template::instance()->get_admin_template( 'global/notify-action.php' );
772 }
773
774 /**
775 * Get course data for Vue Editor Course use.
776 *
777 * @return array|mixed|null
778 * @deprecated 4.4.2 - no any enqueue js for that.
779 */
780 /*
781 public function get_course_data_for_editor_vue() {
782 global $post, $pagenow;
783
784 if ( empty( $post ) || ( get_post_type() !== LP_COURSE_CPT ) || ! in_array(
785 $pagenow,
786 array(
787 'post.php',
788 'post-new.php',
789 )
790 ) ) {
791 return array();
792 }
793
794 $course = CourseModel::find( $post->ID, true );
795 if ( $course ) {
796 $course_section_items = $course->get_section_items();
797 } else { // Code old if not found course on the table learnpress_courses.
798 $course = learn_press_get_course( $post->ID );
799 $course_section_items = $course->get_curriculum_raw();
800 }
801 $hidden_sections = get_post_meta( $post->ID, '_admin_hidden_sections', true );
802
803 return apply_filters(
804 'learn-press/admin-localize-course-editor',
805 array(
806 'root' => array(
807 'course_id' => $post->ID,
808 'auto_draft' => get_post_status( $post->ID ) == 'auto-draft',
809 'ajax' => admin_url( 'index.php' ),
810 'disable_curriculum' => false,
811 'action' => 'admin_course_editor',
812 'nonce' => wp_create_nonce( 'learnpress_update_curriculum' ),
813 ),
814 'chooseItems' => array(
815 'types' => learn_press_course_get_support_item_types(),
816 'open' => false,
817 'addedItems' => array(),
818 'items' => array(),
819 ),
820 'i18n' => array(
821 'item' => __( 'item', 'learnpress' ),
822 'new_section_item' => __( 'Create a new', 'learnpress' ),
823 'back' => __( 'Back', 'learnpress' ),
824 'selected_items' => __( 'Selected items', 'learnpress' ),
825 'confirm_remove_item' => __( 'Do you want to remove the "{{ITEM_NAME}}" item from the course?', 'learnpress' ),
826 'confirm_trash_item' => __( 'Do you want to move the "{{ITEM_NAME}}" item to the trash?', 'learnpress' ),
827 'item_labels' => array(
828 'singular' => __( 'Item', 'learnpress' ),
829 'plural' => __( 'Items', 'learnpress' ),
830 ),
831 'notice_sale_price' => __( 'The course sale price must be less than the regular price', 'learnpress' ),
832 'notice_price' => __( 'The course price must be greater than the sale price', 'learnpress' ),
833 'notice_sale_start_date' => __( 'The sale start date must be before the sale end date', 'learnpress' ),
834 'notice_sale_end_date' => __( 'The sale end date must be after the sale start date', 'learnpress' ),
835 'notice_invalid_date' => __( 'Invalid date', 'learnpress' ),
836 ),
837 'sections' => array(
838 'sections' => $course_section_items,
839 'hidden_sections' => ! empty( $hidden_sections ) ? $hidden_sections : array(),
840 'urlEdit' => admin_url( 'post.php?action=edit&post=' ),
841 ),
842 )
843 );
844 }*/
845
846 /**
847 * Instance
848 */
849 public static function instance() {
850 if ( ! is_admin() ) {
851 return null;
852 }
853
854 if ( ! self::$_instance ) {
855 self::$_instance = new self();
856 }
857
858 return self::$_instance;
859 }
860 }
861
862 /**
863 * Shortcut function to get instance of LP_Admin_Assets
864 *
865 * @return LP_Admin_Assets|null
866 * Addon Certificate, Import/Export is using.
867 */
868 function learn_press_admin_assets() {
869 return LP_Admin_Assets::instance();
870 }
871