PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.3
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.3
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.4.3, at inc/admin/class-lp-admin-assets.php

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