PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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
← All changes | inc/admin/class-lp-admin.php +291 -179 4.1.7.3.24.4.8 View file →
@@ -1,14 +1,17 @@
1 1 <?php
2 2 /**
3 3 * @author ThimPress
4 4 * @package LearnPress/Admin/Classes
5 - * @version 1.0.1
5 + * @version 1.0.2
6 6 */
7 -if ( ! defined( 'ABSPATH' ) ) {
8 - exit; // Exit if accessed directly
9 -}
10 7
8 +use LearnPress\Background\LPBackgroundAjax;
9 +use LearnPress\Models\CourseModel;
10 +use LearnPress\TemplateHooks\CourseBuilder\Course\BuilderCourseTemplate;
11 +
12 +defined( 'ABSPATH' ) || exit;
13 +
11 14 if ( ! class_exists( 'LP_Admin' ) ) {
12 15 /**
13 16 * Class LP_Admin
14 17 */
@@ -14,27 +17,31 @@
14 17 */
15 18 class LP_Admin {
16 19 protected static $instance;
17 20
18 - /**
19 - * @var array
20 - */
21 - protected $_static_pages = false;
21 + protected $pages = [];
22 22
23 23 /**
24 24 * Constructor
25 25 */
26 26 protected function __construct() {
27 + $this->pages = [
28 + 'courses' => __( 'Courses', 'learnpress' ),
29 + 'instructors' => __( 'Instructors', 'learnpress' ),
30 + 'single_instructor' => __( 'Single Instructors', 'learnpress' ),
31 + 'profile' => __( 'Profile', 'learnpress' ),
32 + 'checkout' => __( 'Checkout', 'learnpress' ),
33 + 'become_a_teacher' => __( 'Become an Instructor', 'learnpress' ),
34 + ];
27 35 $this->includes();
28 36 add_action( 'delete_user', array( $this, 'delete_user_data' ) );
29 - add_action( 'delete_user_form', array( $this, 'delete_user_form' ) );
30 - add_action( 'wp_ajax_learn_press_rated', array( $this, 'rated' ) );
31 - add_action( 'admin_notices', array( $this, 'admin_notices' ) );
37 + //add_action( 'delete_user_form', array( $this, 'delete_user_form' ) );
38 + add_action( 'all_admin_notices', array( $this, 'admin_notices' ), - 1 );
32 39 add_action( 'admin_enqueue_scripts', array( $this, 'load_modal' ) );
33 40 add_filter( 'admin_body_class', array( $this, 'body_class' ) );
34 - add_filter( 'manage_users_custom_column', array( $this, 'users_custom_column' ), 10, 3 );
35 - add_filter( 'manage_pages_columns', array( $this, 'page_columns_head' ) );
36 - add_filter( 'manage_pages_custom_column', array( $this, 'page_columns_content' ), 10, 2 );
41 + //add_filter( 'manage_users_custom_column', array( $this, 'users_custom_column' ), 10, 3 );
42 + //add_filter( 'manage_pages_columns', array( $this, 'page_columns_head' ) );
43 + //add_filter( 'manage_pages_custom_column', array( $this, 'page_columns_content' ), 10, 2 );
37 44 add_filter( 'views_edit-page', array( $this, 'views_pages' ), 10 );
38 45 add_filter( 'views_users', array( $this, 'views_users' ), 10, 1 );
39 46 add_filter( 'user_row_actions', array( $this, 'user_row_actions' ), 10, 2 );
40 47 add_filter( 'get_pages', array( $this, 'add_empty_page' ), 1000, 2 );
@@ -44,9 +51,9 @@
44 51 LP_Request::register( 'lp-action', array( $this, 'filter_users' ) );
45 52
46 53 add_filter( 'learn-press/modal-search-items-args', array( $this, 'filter_modal_search' ) );
47 54
48 - add_filter(
55 + /*add_filter(
49 56 'learn-press/dismissed-notice-response',
50 57 array(
51 58 $this,
52 59 'on_dismissed_notice_response',
@@ -52,9 +59,9 @@
52 59 'on_dismissed_notice_response',
53 60 ),
54 61 10,
55 62 2
56 - );
63 + );*/
57 64
58 65 // get list items course of user | tungnx
59 66 add_action( 'pre_get_posts', array( $this, 'get_course_items_of_user_backend' ), 10 );
60 67 add_action( 'pre_get_posts', array( $this, 'get_pages_of_lp' ), 10 );
@@ -60,8 +67,28 @@
60 67 add_action( 'pre_get_posts', array( $this, 'get_pages_of_lp' ), 10 );
61 68
62 69 // Set link item course when edit on Backend | tungnx
63 70 add_filter( 'get_sample_permalink_html', array( $this, 'lp_course_set_link_item_backend' ), 10, 5 );
71 +
72 + // Add "Edit with Course Builder" button below title area for courses
73 + add_action( 'edit_form_after_title', array( $this, 'add_course_builder_button' ) );
74 +
75 + /*add_action(
76 + 'admin_init',
77 + function () {
78 + // From LP v4.2.3 temporary run create pages to add page instructors, single instructor for client upgrade LP.
79 + // After a long time, will remove this code.
80 + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
81 + LP_Install::create_pages();
82 + }
83 + }
84 + );*/
85 +
86 + add_filter( 'users_list_table_query_args', [ $this, 'exclude_temp_users' ] );
87 +
88 + // Show label 'LearnPress Page' for page of LearnPress.
89 + //add_filter('post_states_html');
90 + add_filter( 'display_post_states', [ $this, 'show_label_page_type' ], 10, 2 );
64 91 }
65 92
66 93 /**
67 94 * @since 3.2.6
@@ -66,15 +93,16 @@
66 93 /**
67 94 * @since 3.2.6
68 95 */
69 96 public function load_modal() {
70 - if ( in_array( get_post_type(), array( LP_COURSE_CPT, LP_QUIZ_CPT, LP_QUESTION_CPT, LP_ORDER_CPT ) ) ) {
97 + // Now only add item(s) when create new Order is using.
98 + if ( in_array( get_post_type(), array( LP_ORDER_CPT ) ) ) {
71 99 LP_Modal_Search_Items::instance();
72 100 }
73 101
74 - if ( in_array( get_post_type(), array( LP_ORDER_CPT ) ) ) {
102 + /*if ( in_array( get_post_type(), array( LP_ORDER_CPT ) ) ) {
75 103 LP_Modal_Search_Users::instance();
76 - }
104 + }*/
77 105 }
78 106
79 107 /**
80 108 * @param $options
@@ -116,9 +144,9 @@
116 144 if ( $active_plugins ) {
117 145 if ( $search ) {
118 146 foreach ( $search as $k => $v ) {
119 147 if ( in_array( $k, $active_plugins ) ) {
120 - $count_activated ++;
148 + ++ $count_activated;
121 149 }
122 150 }
123 151 }
124 152 }
@@ -174,9 +202,9 @@
174 202 * @param int $id
175 203 *
176 204 * @return bool
177 205 */
178 - protected function _is_wc_page( $id ) {
206 + /*protected function _is_wc_page( $id ) {
179 207 if ( class_exists( 'WooCommerce' ) ) {
180 208 if ( ! class_exists( 'WC_Admin_Post_Types' ) ) {
181 209 include_once dirname( WC_PLUGIN_FILE ) . '/includes/admin/class-wc-admin-post-types.php';
182 210 }
@@ -201,11 +229,11 @@
201 229 }
202 230 }
203 231
204 232 return false;
205 - }
233 + }*/
206 234
207 - public function wc_add_display_post_states( $post_states, $post ) {
235 + /*public function wc_add_display_post_states( $post_states, $post ) {
208 236 if ( wc_get_page_id( 'shop' ) === $post->ID ) {
209 237 $post_states['wc_page_for_shop'] = __( 'Shop Page', 'learnpress' );
210 238 }
211 239
@@ -225,9 +253,9 @@
225 253 $post_states['wc_page_for_terms'] = __( 'Terms and Conditions Page', 'learnpress' );
226 254 }
227 255
228 256 return $post_states;
229 - }
257 + }*/
230 258
231 259 /**
232 260 * Check if a page is set for Paid Membership Pro.
233 261 *
@@ -234,9 +262,9 @@
234 262 * @param int $id
235 263 *
236 264 * @return bool|mixed
237 265 */
238 - protected function _is_pmpro_page( $id ) {
266 + /*protected function _is_pmpro_page( $id ) {
239 267 global $pmpro_pages;
240 268 if ( $pmpro_pages ) {
241 269 $pages = array(
242 270 'account' => __( 'Account', 'learnpress' ),
@@ -255,9 +283,9 @@
255 283 }
256 284 }
257 285
258 286 return false;
259 - }
287 + }*/
260 288
261 289 /**
262 290 * Check if a page is set for Paid Membership Pro.
263 291 *
@@ -264,9 +292,9 @@
264 292 * @param int $id
265 293 *
266 294 * @return bool|mixed
267 295 */
268 - protected function _is_bp_page( $id ) {
296 + /*protected function _is_bp_page( $id ) {
269 297 if ( function_exists( 'buddypress' ) ) {
270 298 $bp_pages = get_option( 'bp-pages' );
271 299 if ( ! $bp_pages ) {
272 300 return false;
@@ -286,56 +314,56 @@
286 314 }
287 315 }
288 316
289 317 return false;
290 - }
318 + }*/
291 319
292 320 /**
293 - * @param string $plugin
321 + * Get pages is publish set by LearnPress.
294 322 *
295 - * @return array|bool
323 + * @return array
296 324 */
297 - protected function _get_static_pages( $plugin = '' ) {
298 - if ( false === $this->_static_pages ) {
299 - $this->_static_pages = array(
300 - 'learnpress' => array(),
301 - 'WooCommerce' => array(),
302 - 'Paid Membership Pro' => array(),
303 - 'BuddyPress' => array(),
304 - );
325 + protected function _get_static_pages(): array {
326 + $static_pages = [];
327 + foreach ( $this->pages as $name => $title ) {
328 + $page_id = learn_press_get_page_id( $name );
305 329
306 - $all_pages = array(
307 - 'courses' => __( 'Courses', 'learnpress' ),
308 - 'profile' => __( 'Profile', 'learnpress' ),
309 - 'checkout' => __( 'Checkout', 'learnpress' ),
310 - 'become_a_teacher' => __( 'Become a Teacher', 'learnpress' ),
311 - );
330 + if ( $page_id && 'publish' === get_post_status( $page_id ) ) {
331 + $static_pages[ $page_id ] = $title;
332 + }
333 + }
312 334
313 - foreach ( $all_pages as $name => $title ) {
314 - $page_id = learn_press_get_page_id( $name );
335 + return $static_pages;
336 + }
315 337
316 - if ( $page_id && 'publish' === get_post_status( $page_id ) ) {
317 - $this->_static_pages['learnpress'][ $page_id ] = $title;
338 + /**
339 + * Show label LearnPress Page for pages set by LearnPress.
340 + *
341 + * @param array $post_states
342 + * @param WP_Post $post
343 + *
344 + * @return array
345 + * @since 4.3.2.6
346 + * @version 1.0.0
347 + */
348 + public function show_label_page_type( $post_states, $post ) {
349 + $post_type = get_post_type( $post );
350 + if ( $post_type !== 'page' ) {
351 + return $post_states;
352 + }
318 353
319 - $for_page = $this->_is_wc_page( $page_id );
320 - if ( $for_page ) {
321 - $this->_static_pages['WooCommerce'][ $page_id ] = $for_page;
322 - }
323 -
324 - $for_page = $this->_is_pmpro_page( $page_id );
325 - if ( $for_page ) {
326 - $this->_static_pages['Paid Membership Pro'][ $page_id ] = $for_page;
327 - }
328 -
329 - $for_page = $this->_is_bp_page( $page_id );
330 - if ( $for_page ) {
331 - $this->_static_pages['BuddyPress'][ $page_id ] = $for_page;
332 - }
333 - }
354 + $page_id_compare = $post->ID;
355 + foreach ( $this->_get_static_pages() as $page_id => $title ) {
356 + if ( $page_id == $page_id_compare ) {
357 + $post_states['lp_page'] = sprintf(
358 + '<span class="is-lp-page">%s</span>',
359 + 'LearnPress ' . $title . ' Page'
360 + );
361 + break;
334 362 }
335 363 }
336 364
337 - return $plugin ? ( ! empty( $this->_static_pages[ $plugin ] ) ? $this->_static_pages[ $plugin ] : false ) : $this->_static_pages;
365 + return $post_states;
338 366 }
339 367
340 368 /**
341 369 * Add new column to WP Pages manage to show what page is assigned to.
@@ -343,9 +371,9 @@
343 371 * @param array $columns
344 372 *
345 373 * @return array
346 374 */
347 - public function page_columns_head( $columns ) {
375 + /*public function page_columns_head( $columns ) {
348 376
349 377 $_columns = $columns;
350 378 $columns = array();
351 379
@@ -356,17 +384,17 @@
356 384 $columns[ $name ] = $text;
357 385 }
358 386
359 387 return $columns;
360 - }
388 + }*/
361 389
362 390 /**
363 391 * Display the page is assigned to LP Page.
364 392 *
365 393 * @param string $column_name
366 - * @param int $post
394 + * @param int $post
367 395 */
368 - public function page_columns_content( $column_name, $post ) {
396 + /*public function page_columns_content( $column_name, $post ) {
369 397 $pages = $this->_get_static_pages();
370 398 switch ( $column_name ) {
371 399 case 'lp-page':
372 400 if ( ! empty( $pages['learnpress'][ $post ] ) ) {
@@ -386,9 +414,9 @@
386 414 );
387 415 }
388 416 }
389 417 }
390 - }
418 + }*/
391 419
392 420 /**
393 421 * @param $actions
394 422 *
@@ -394,15 +422,13 @@
394 422 *
395 423 * @return mixed
396 424 */
397 425 public function views_pages( $actions ) {
398 - $this->_get_static_pages();
426 + $pages = $this->_get_static_pages();
399 427
400 - $pages = $this->_get_static_pages( 'learnpress' );
401 -
402 428 if ( $pages ) {
403 429 $text = sprintf( __( 'LearnPress Pages (%d)', 'learnpress' ), sizeof( $pages ) );
404 - if ( 'yes' !== LP_Request::get( 'lp-page' ) ) {
430 + if ( 'yes' !== LP_Request::get_param( 'lp-page' ) ) {
405 431 $actions['lp-page'] = sprintf(
406 432 '<a href="%s">%s</a>',
407 433 admin_url( 'edit.php?post_type=page&lp-page=yes' ),
408 434 $text
@@ -422,11 +448,15 @@
422 448 *
423 449 * @return mixed
424 450 */
425 451 public function get_pages_of_lp( $q ) {
426 - if ( 'page' == LP_Request::get( 'post_type' ) && 'yes' == LP_Request::get( 'lp-page' ) ) {
427 - $ids = $this->_get_static_pages( 'learnpress' );
452 + if ( ! is_admin() || ! $q->is_main_query() ) {
453 + return $q;
454 + }
428 455
456 + if ( 'page' == LP_Request::get_param( 'post_type' ) && 'yes' == LP_Request::get_param( 'lp-page' ) ) {
457 + $ids = $this->_get_static_pages();
458 +
429 459 if ( ! empty( $ids ) ) {
430 460 $ids = array_keys( $ids );
431 461 $q->set( 'post__in', $ids );
432 462 }
@@ -437,24 +467,27 @@
437 467
438 468 /**
439 469 * Add actions to users list
440 470 *
441 - * @param array $actions
471 + * @param array $actions
442 472 * @param WP_User $user
443 473 *
444 474 * @return mixed
445 475 */
446 476 public function user_row_actions( $actions, $user ) {
447 - $pending_request = LP_User_Factory::get_pending_requests();
448 - if ( LP_Request::get_string( 'lp-action' ) == 'pending-request' && $pending_request ) {
477 + $pending_request = self::get_pending_requests();
478 + if ( LP_Request::get_param( 'lp-action' ) == 'pending-request' && $pending_request ) {
449 479 $actions = array();
480 + $nonce = 'nonce=' . wp_create_nonce( 'lp-action-permit-role-teacher' );
450 481 if ( in_array( $user->ID, $pending_request ) ) {
451 482 $actions['accept'] = sprintf(
452 - '<a href="' . admin_url( 'users.php?lp-action=accept-request&user_id=' . $user->ID ) . '">%s</a>',
483 + '<a href="%s">%s</a>',
484 + admin_url( "users.php?lp-action=accept-request&user_id={$user->ID}&{$nonce}" ),
453 485 _x( 'Accept', 'pending-request', 'learnpress' )
454 486 );
455 487 $actions['delete deny'] = sprintf(
456 - '<a class="submitdelete" href="' . admin_url( 'users.php?lp-action=deny-request&user_id=' . $user->ID ) . '">%s</a>',
488 + '<a class="submitdelete" href="%s">%s</a>',
489 + admin_url( "users.php?lp-action=deny-request&user_id={$user->ID}&{$nonce}" ),
457 490 _x( 'Deny', 'pending-request', 'learnpress' )
458 491 );
459 492 }
460 493 }
@@ -461,9 +494,38 @@
461 494
462 495 return $actions;
463 496 }
464 497
498 + public function exclude_temp_users( $args ) {
499 + if ( LP_Request::get_param( 'lp-action' ) == 'pending-request' ) {
500 + $args['include'] = self::get_pending_requests();
501 + }
502 +
503 + return $args;
504 + }
505 +
465 506 /**
507 + * Get pending requests be come a Teacher.
508 + *
509 + * @return array
510 + */
511 + public static function get_pending_requests() {
512 + global $wpdb;
513 + $query = $wpdb->prepare(
514 + "
515 + SELECT ID
516 + FROM {$wpdb->users} u
517 + INNER JOIN {$wpdb->usermeta} um ON um.user_id = u.ID AND um.meta_key = %s
518 + WHERE um.meta_value = %s
519 + ",
520 + '_requested_become_teacher',
521 + 'yes'
522 + );
523 +
524 + return $wpdb->get_col( $query );
525 + }
526 +
527 + /**
466 528 * Filter user by custom param
467 529 *
468 530 * @param string $action
469 531 */
@@ -471,38 +533,59 @@
471 533 if ( ! current_user_can( 'administrator' ) ) {
472 534 return;
473 535 }
474 536
475 - $user_id = LP_Request::get_int( 'user_id' );
537 + $user_id = LP_Request::get_param( 'user_id', 'int' );
538 + if ( ! $user_id || ! get_user_by( 'id', $user_id ) ) {
539 + return;
540 + }
476 541
477 - if ( ! $user_id || ! get_user_by( 'id', $user_id ) ) {
542 + $nonce = LP_Request::get_param( 'nonce' );
543 + if ( ! wp_verify_nonce( $nonce, 'lp-action-permit-role-teacher' ) ) {
478 544 return;
479 545 }
480 546
481 547 $user_data = get_userdata( $user_id );
548 + if ( in_array( $action, array( 'accept-request', 'deny-request' ) ) ) {
549 + delete_user_meta( $user_id, '_requested_become_teacher' );
550 + }
482 551
483 - if ( in_array( $action, array( 'accept-request', 'deny-request' ) ) ) {
552 + switch ( $action ) {
553 + case 'accept-request':
554 + $be_teacher = new WP_User( $user_id );
555 + $be_teacher->set_role( LP_TEACHER_ROLE );
484 556
485 - delete_user_meta( $user_id, '_requested_become_teacher' );
557 + /**
558 + * Send email to user when admin accept user become a teacher
559 + * @use SendEmailAjax::send_mail_become_a_teacher_accept
560 + */
561 + $data_send = [
562 + 'params' => [ $user_data->user_email ],
563 + 'lp-load-ajax' => 'send_mail_become_a_teacher_accept',
564 + ];
565 + LPBackgroundAjax::handle( $data_send );
486 566
487 - switch ( $action ) {
488 - case 'accept-request':
489 - $be_teacher = new WP_User( $user_id );
490 - $be_teacher->set_role( LP_TEACHER_ROLE );
567 + do_action( 'learn-press/user-become-a-teacher-accept', $user_data->user_email );
568 + wp_redirect( admin_url( 'users.php?lp-action=accepted-request&user_id=' . $user_id ) );
569 + exit();
570 + case 'deny-request':
571 + /**
572 + * Send email to user when admin accept user become a teacher
573 + * @use SendEmailAjax::send_mail_become_a_teacher_deny
574 + */
575 + $data_send = [
576 + 'params' => [ $user_data->user_email ],
577 + 'lp-load-ajax' => 'send_mail_become_a_teacher_deny',
578 + ];
579 + LPBackgroundAjax::handle( $data_send );
491 580
492 - do_action( 'learn-press/user-become-a-teacher-accept', $user_data->user_email );
493 - wp_redirect( admin_url( 'users.php?lp-action=accepted-request&user_id=' . $user_id ) );
494 - exit();
495 - case 'deny-request':
496 - do_action( 'learn-press/user-become-a-teacher-deny', $user_data->user_email );
497 - wp_redirect( admin_url( 'users.php?lp-action=denied-request&user_id=' . $user_id ) );
498 - exit();
499 - }
581 + do_action( 'learn-press/user-become-a-teacher-deny', $user_data->user_email );
582 + wp_redirect( admin_url( 'users.php?lp-action=denied-request&user_id=' . $user_id ) );
583 + exit();
500 584 }
501 585 }
502 586
503 587 public function users_custom_column( $content, $column_name, $user_id ) {
504 -
505 588 }
506 589
507 590 /**
508 591 * Add new view to users views for filtering user by "pending request" of "become a teacher".
@@ -511,12 +594,12 @@
511 594 *
512 595 * @return mixed
513 596 */
514 597 public function views_users( $views ) {
515 - $pending_request = LP_User_Factory::get_pending_requests();
598 + $pending_request = self::get_pending_requests();
516 599
517 600 if ( $pending_request ) {
518 - if ( LP_Request::get_string( 'lp-action' ) == 'pending-request' ) {
601 + if ( LP_Request::get_param( 'lp-action' ) == 'pending-request' ) {
519 602 $class = ' class="current"';
520 603 foreach ( $views as $k => $view ) {
521 604 $views[ $k ] = preg_replace( '!class="current"!', '', $view );
522 605 }
@@ -564,8 +647,16 @@
564 647 /**
565 648 * Display notices on Backend.
566 649 */
567 650 public function admin_notices() {
651 + if ( function_exists( 'get_current_screen' ) ) {
652 + $wp_screen = get_current_screen();
653 + // Not run on course edit screen, it slows, can affect performance edit course.
654 + if ( $wp_screen->id === LP_COURSE_CPT ) {
655 + return;
656 + }
657 + }
658 +
568 659 // Show template file templates override.
569 660 $page = LP_Request::get_param( 'page' );
570 661 $tab = LP_Request::get_param( 'tab' );
571 662 if ( $page == 'learn-press-tools' && $tab == 'templates' ) {
@@ -596,16 +687,8 @@
596 687 learn_press_admin_view( 'admin-notices.php', [], true );
597 688 }
598 689
599 690 /**
600 - * Update option data user rated.
601 - */
602 - public function rated() {
603 - update_option( 'learn_press_message_user_rated', 'yes' );
604 - die();
605 - }
606 -
607 - /**
608 691 * Admin footer add review.
609 692 *
610 693 * @param $footer_text
611 694 *
@@ -630,30 +713,8 @@
630 713 'learnpress'
631 714 ) . '">',
632 715 '</a>'
633 716 );
634 -
635 - ob_start();
636 - ?>
637 -
638 - <script>
639 - jQuery(function ($) {
640 - var $ratingLink = $('a.lp-rating-link').click(function (e) {
641 - $.ajax({
642 - url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
643 - data: {
644 - action: 'learn_press_rated'
645 - },
646 - success: function () {
647 - $ratingLink.parent().html($ratingLink.data('rated'))
648 - }
649 - })
650 - })
651 - })
652 - </script>
653 -
654 - <?php
655 - echo ob_get_clean();
656 717 }
657 718 }
658 719
659 720 return $footer_text;
@@ -658,11 +719,11 @@
658 719
659 720 return $footer_text;
660 721 }
661 722
662 - function delete_user_form() {
723 + /*function delete_user_form() {
663 724 // What should be displayed here?
664 - }
725 + }*/
665 726
666 727 /**
667 728 * Delete records related user being deleted in other tables
668 729 *
@@ -674,15 +735,16 @@
674 735
675 736 /**
676 737 * Send data to join newsletter or dismiss.
677 738 *
678 - * @param array $data
739 + * @param array $data
679 740 * @param string $notice
680 741 *
681 742 * @return array
682 743 * @since 3.0.10
744 + * @deprecated 4.2.3.1
683 745 */
684 - public function on_dismissed_notice_response( $data, $notice ) {
746 + /*public function on_dismissed_notice_response( $data, $notice ) {
685 747 switch ( $notice ) {
686 748 case 'skip-setup-wizard':
687 749 delete_option( 'learn_press_install' );
688 750 break;
@@ -729,9 +791,9 @@
729 791 }
730 792 }
731 793
732 794 return $data;
733 - }
795 + }*/
734 796
735 797 /**
736 798 * Include all classes and functions used for admin
737 799 */
@@ -738,10 +800,18 @@
738 800 public function includes() {
739 801 // Common function used in admin
740 802 include_once 'lp-admin-functions.php';
741 803 include_once 'lp-admin-actions.php';
742 - require_once LP_PLUGIN_PATH . 'inc/background-process/class-lp-background-query-items.php';
743 804 include_once 'class-lp-admin-assets.php';
805 + LP_Admin_Assets::instance();
806 + // For MCP
807 + if ( learn_press_is_mcp_available() ) {
808 + include_once 'class-lp-admin-mcp-api-keys.php';
809 + LP_Admin_MCP_API_Keys::instance();
810 + }
811 + // End MCP
812 + include_once 'class-lp-admin-webhooks.php';
813 + LP_Admin_Webhooks::instance();
744 814 include_once 'class-lp-admin-dashboard.php';
745 815 // include_once 'class-lp-admin-tools.php';
746 816 include_once 'class-lp-admin-ajax.php';
747 817 include_once 'editor/class-lp-admin-editor.php';
@@ -746,19 +816,19 @@
746 816 include_once 'class-lp-admin-ajax.php';
747 817 include_once 'editor/class-lp-admin-editor.php';
748 818 include_once 'class-lp-admin-menu.php';
749 819 include_once 'helpers/class-lp-outdated-template-helper.php';
750 - include_once 'helpers/class-lp-plugins-helper.php';
751 820 include_once 'class-lp-modal-search-items.php';
752 - include_once 'class-lp-modal-search-users.php';
821 + //include_once 'class-lp-modal-search-users.php';
753 822 include_once 'class-lp-setup-wizard.php';
754 823 // include_once 'class-lp-updater.php';
755 - include_once 'class-lp-install-sample-data.php';
756 - include_once 'class-lp-reset-data.php';
824 + // include_once 'class-lp-install-sample-data.php'; // Replaced by LearnPress\Ajax\SampleDataAJAX.
825 + // include_once 'class-lp-reset-data.php'; // Deprecated: replaced by CourseToolsAjax::reset_progress_items_course.
757 826 include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/course/settings.php';
827 + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/course/class-lp-meta-box-course-offline.php';
758 828 include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/quiz/settings.php';
759 829 include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/lesson/settings.php';
760 - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/question/settings.php';
830 + //include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/question/settings.php';
761 831 }
762 832
763 833 /**
764 834 * Get courses, item's courses on Backend page post_type
@@ -769,9 +839,9 @@
769 839 if ( ! $query->is_main_query() ) {
770 840 return;
771 841 }
772 842
773 - global $post_type, $pagenow;
843 + /*global $post_type, $pagenow;
774 844
775 845 if ( current_user_can( ADMIN_ROLE ) ) {
776 846 return;
777 847 }
@@ -786,25 +856,26 @@
786 856 );
787 857
788 858 if ( ! in_array( $post_type, $post_type_valid ) ) {
789 859 return;
790 - }
860 + }*/
791 861
792 862 // $query->set( 'author', get_current_user_id() );
793 863
794 - $query = apply_filters( 'learnpress/get-post-type-lp-on-backend', $query );
864 + // Hook only Co-instructor using.
865 + return apply_filters( 'learnpress/get-post-type-lp-on-backend', $query );
795 866
796 867 //add_filter( 'views_edit-' . $post_type . '', '_learn_press_restrict_view_items', 10 );
797 - remove_filter( 'pre_get_posts', array( $this, 'get_course_items_of_user_backend' ), 10 );
868 + //remove_filter( 'pre_get_posts', array( $this, 'get_course_items_of_user_backend' ), 10 );
798 869 }
799 870
800 871 /**
801 872 * Set link item of course when edit item on Backend
802 873 *
803 - * @param string $post_link
804 - * @param int $post_id
805 - * @param string $new_title
806 - * @param string $new_slug
874 + * @param string $post_link
875 + * @param int $post_id
876 + * @param string $new_title
877 + * @param string $new_slug
807 878 * @param WP_Post|null $post
808 879 *
809 880 * @return string
810 881 * @author tungnx
@@ -811,45 +882,47 @@
811 882 * @since 3.2.7.5
812 883 * @version 4.0.1
813 884 */
814 885 public function lp_course_set_link_item_backend( $post_link = '', $post_id = 0, $new_title = '', $new_slug = '', $post = null ) {
815 - if ( ! in_array( $post->post_type, learn_press_get_course_item_types() ) ) {
816 - return $post_link;
817 - }
818 -
819 886 try {
820 - $course_id_of_item = LP_Course_DB::getInstance()->get_course_by_item_id( $post->ID );
887 + if ( in_array( $post->post_type, CourseModel::item_types_support() ) ) {
888 + $course_id_of_item = LP_Course_DB::getInstance()->get_course_by_item_id( $post->ID );
889 + if ( $course_id_of_item ) {
890 + $course = learn_press_get_course( $course_id_of_item );
891 + if ( $course ) {
892 + $link_item = urldecode( $course->get_item_link( $post->ID ) );
893 + $post_slug = $post->post_name;
894 + $link_item_edit_slug = preg_replace( '/' . $post_slug . '$/', '', $link_item );
821 895
822 - if ( $course_id_of_item ) {
823 - $course = learn_press_get_course( $course_id_of_item );
896 + // For update new slug
897 + if ( $new_slug ) {
898 + $post_slug = $new_slug;
899 + }
900 + $post_slug = urldecode( $post_slug );
824 901
825 - if ( $course ) {
826 - $link_item = $course->get_item_link( $post->ID );
902 + $slug_arr = explode( '/', $link_item_edit_slug );
903 + $count_slug = count( $slug_arr );
904 + unset( $slug_arr[ $count_slug - 2 ] );
905 + $link_item_edit_slug = implode( '/', $slug_arr );
827 906
828 - $post_slug = $post->post_name;
829 - $link_item_edit_slug = preg_replace( '/' . $post_slug . '$/', '', $link_item );
830 -
831 - // For update new slug
832 - if ( $new_slug ) {
833 - $post_slug = $new_slug;
907 + $post_link = '<strong>Permalink: </strong>';
908 + $post_link .= '<span id="sample-permalink">';
909 + $post_link .= '<a href="' . $link_item . '">' . $link_item_edit_slug . '<span id="editable-post-name">' . $post_slug . '</span>/</a>';
910 + $post_link .= '</span>';
911 + $post_link .= '&lrm;<span id="edit-slug-buttons">';
912 + $post_link .= '<button type="button" class="edit-slug button button-small hide-if-no-js" aria-label="Edit permalink">Edit</button>';
913 + $post_link .= '</span>';
914 + $post_link .= '<span id="editable-post-name-full">' . $post_slug . '</span>';
834 915 }
835 -
836 - $post_link = '<strong>Permalink: </strong>';
837 - $post_link .= '<span id="sample-permalink">';
838 - $post_link .= '<a href="' . $link_item . '">' . $link_item_edit_slug . '<span id="editable-post-name">' . $post_slug . '</span>/</a>';
839 - $post_link .= '</span>';
840 - $post_link .= '&lrm;<span id="edit-slug-buttons">';
841 - $post_link .= '<button type="button" class="edit-slug button button-small hide-if-no-js" aria-label="Edit permalink">Edit</button>';
842 - $post_link .= '</span>';
843 - $post_link .= '<span id="editable-post-name-full">' . $post_slug . '</span>';
916 + } else {
917 + $post_link_message = '<span>' . __(
918 + 'Permalink is only available if the item is already assigned to a course.',
919 + 'learnpress'
920 + ) . '</span>';
921 + $post_link = sprintf( '<div id="learn-press-box-edit-slug">%s</div>', $post_link_message );
844 922 }
845 - } else {
846 - // $post_link_preview = sprintf( '<a class="button" href="%s" target="_blank">%s</a>', learn_press_get_preview_url( $post_id ), __( 'Preview', 'learnpress' ) );
847 - $post_link_message = '<span>' . __(
848 - 'Permalink is only available if the item is already assigned to a course.',
849 - 'learnpress'
850 - ) . '</span>';
851 - $post_link = sprintf( '<div id="learn-press-box-edit-slug">%s</div>', $post_link_message );
923 + } elseif ( LP_COURSE_CPT === get_post_type( $post ) ) {
924 + $post_link = LP_Helper::handle_lp_permalink_structure( $post_link, $post );
852 925 }
853 926 } catch ( Throwable $e ) {
854 927 error_log( $e->getMessage() );
855 928 }
@@ -854,8 +927,47 @@
854 927 error_log( $e->getMessage() );
855 928 }
856 929
857 930 return $post_link;
931 + }
932 +
933 + /**
934 + * Add "Edit with Course Builder" button below title area for courses
935 + *
936 + * @param WP_Post $post
937 + *
938 + * @since 4.3.0
939 + */
940 + public function add_course_builder_button( $post ) {
941 + if ( ! $post || LP_COURSE_CPT !== $post->post_type ) {
942 + return;
943 + }
944 +
945 + // Only show for existing courses (not new)
946 + if ( 'auto-draft' === $post->post_status ) {
947 + return;
948 + }
949 +
950 + $course_builder_url = BuilderCourseTemplate::instance()->get_link_edit( $post->ID ) ?? '';
951 + ?>
952 + <div class="lp-edit-with-course-builder" style="margin: 10px 0 20px 0;">
953 + <a href="<?php echo esc_url( $course_builder_url ); ?>" class="button button-primary button-large" style="background: #7067ED; border-color: #7067ED; display: inline-flex; align-items: center; gap: 6px; padding: 0 16px; font-size: 14px; border-radius: 3px; line-height: 3;">
954 + <svg width="26" height="18" viewBox="0 0 69 48" fill="none" xmlns="http://www.w3.org/2000/svg">
955 + <path d="M50.9291 24.84L50.2591 21.69C50.5491 21.47 50.7391 21.11 50.7391 20.71C50.7391 20.03 50.1891 19.48 49.4991 19.48C48.8091 19.48 48.2591 20.03 48.2591 20.71C48.2591 21.11 48.4491 21.46 48.7391 21.69L48.0691 24.84C47.9891 25.21 48.1791 25.56 48.4791 25.56H50.5091C50.8091 25.56 50.9991 25.21 50.9191 24.84H50.9291Z" fill="white"></path>
956 + <path d="M50.8892 13.24H50.0092V20.92H48.9892V13.21L46.2992 13.18C43.3992 8.47 38.1692 5.34 32.2192 5.34C30.8292 5.34 29.4792 5.51 28.1892 5.83L24.9492 2.53C24.7992 2.38 24.8892 2.14 25.0992 2.11L40.7292 0L48.5492 9.68L49.7592 11.17L51.0992 12.83C51.2292 12.99 51.1092 13.24 50.8992 13.23L50.8892 13.24Z" fill="white"></path>
957 + <path d="M44.7392 13.1701L43.1392 17.1401C40.7292 13.1101 36.3092 10.4101 31.2592 10.4101C29.9992 10.4101 28.7892 10.5801 27.6292 10.8901L29.2292 6.93014C30.1992 6.74014 31.1992 6.64014 32.2192 6.64014C37.4092 6.64014 41.9892 9.22014 44.7392 13.1701Z" fill="white"></path>
958 + <path d="M25.4692 23.6899V23.8499C25.4692 23.9599 25.4592 24.0699 25.4592 24.1899C25.4592 24.0199 25.4592 23.8499 25.4692 23.6899Z" fill="white"></path>
959 + <path d="M43.3692 24.2601C43.3692 25.2901 43.2392 26.2901 42.9892 27.2501C42.3892 29.5401 41.1192 31.5601 39.4092 33.1001C37.9992 34.3601 36.2892 35.2901 34.3892 35.7701C33.4492 36.0101 32.4592 36.1401 31.4392 36.1401H27.9692V35.8001C27.9692 35.6601 27.9792 35.5301 27.9992 35.3901C28.2092 33.2201 29.5592 31.3901 31.4492 30.4901C31.6092 30.4101 31.7692 30.3401 31.9292 30.2801C32.1692 30.1901 32.4192 30.1201 32.6692 30.0601C32.7292 30.0501 32.7992 30.0301 32.8592 30.0201C35.4892 29.4101 37.4492 27.0601 37.4492 24.2501C37.4492 21.2701 35.2392 18.8001 32.3592 18.3901C32.0792 18.3501 31.7892 18.3301 31.4992 18.3301C31.2392 18.3301 30.9992 18.3501 30.7492 18.3801C28.2992 18.6901 26.2592 20.4801 25.6492 22.8201C25.5292 23.2901 25.4792 23.7701 25.4792 24.2401V42.7601C25.1492 45.6001 22.8092 47.8301 19.9092 47.9901H19.5592H16.4792C18.3092 46.6501 19.5092 44.5001 19.5092 42.0701V23.7001C19.5092 23.5601 19.5192 23.4301 19.5392 23.3001C19.6292 22.2301 19.8492 21.1901 20.2092 20.2201C20.4592 19.5401 20.7692 18.8801 21.1292 18.2501C21.7592 17.1801 22.5492 16.2201 23.4692 15.4001C24.6192 14.3701 25.9792 13.5601 27.4692 13.0401C28.7092 12.6001 30.0492 12.3701 31.4392 12.3701C32.4792 12.3701 33.4792 12.5001 34.4392 12.7501C36.6892 13.3301 38.6792 14.5401 40.2092 16.1901C40.2592 16.2401 40.3092 16.3001 40.3592 16.3501C40.3592 16.3501 40.3592 16.3501 40.3692 16.3601C41.9592 18.1401 43.0192 20.4101 43.2992 22.9001C43.3293 23.1701 43.3492 23.4501 43.3692 23.7201C43.3692 23.8901 43.3692 24.0601 43.3692 24.2401V24.2601Z" fill="white"></path>
960 + <path d="M25.4692 23.6899V23.8499C25.4692 23.9599 25.4592 24.0699 25.4592 24.1899C25.4592 24.0199 25.4592 23.8499 25.4692 23.6899Z" fill="white"></path>
961 + <path d="M6.13917 42.0799H18.0692C18.0592 45.3499 15.3792 47.9999 12.0892 47.9999H6.11917C2.83917 47.9999 0.16917 45.3499 0.14917 42.0799V12.3799H0.18917C3.46917 12.3799 6.13917 15.0299 6.13917 18.2999V42.0799Z" fill="white"></path>
962 + <path d="M67.6736 23.2845L63.9566 19.5676C63.1998 18.8108 61.9757 18.8108 61.219 19.5676L59.0266 21.7599L65.4812 28.2145L67.6736 26.0222C68.4303 25.2654 68.4303 24.0413 67.6736 23.2845Z" fill="white"></path>
963 + <path d="M45.4722 45.0411L46.3513 45.9203L42.078 46.7883C42.078 46.7883 42.0557 46.3432 41.477 45.7534C40.8983 45.1747 40.442 45.1524 40.442 45.1524L41.3101 40.879L42.1892 41.7582L59.817 24.1305L58.2256 22.5391L40.5979 40.1668L39.2513 46.7883C39.1066 47.4894 39.7298 48.1126 40.4309 47.968L47.0525 46.6214L64.6802 28.9937L63.0888 27.4023L45.4611 45.03L45.4722 45.0411Z" fill="white"></path>
964 + <path d="M60.6182 24.9316L42.9905 42.5594L44.6932 44.2621L62.3209 26.6343L60.6182 24.9316Z" fill="white"></path>
965 + </svg>
966 + <?php esc_html_e( 'Edit with Course Builder', 'learnpress' ); ?>
967 + </a>
968 + </div>
969 + <?php
858 970 }
859 971
860 972 /**
861 973 * @return false|string