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/TemplateHooks/CourseBuilder/Lesson/BuilderEditLessonTemplate.php +27 -17 4.3.74.4.8 View file →
@@ -34,8 +34,9 @@
34 34 *
35 35 * @throws Exception
36 36 */
37 37 public function layout( array $data = [] ) {
38 + /** @var UserModel|false $userModel */
38 39 $userModel = $data['userModel'] ?? false;
39 40 if ( ! $userModel || ! $userModel->is_instructor() ) {
40 41 throw new Exception( __( 'You do not have permission to create or edit lessons', 'learnpress' ) );
41 42 }
@@ -44,23 +45,28 @@
44 45 if ( empty( $item_id ) ) {
45 46 throw new Exception( __( 'Invalid lesson ID', 'learnpress' ) );
46 47 }
47 48
48 - if ( ! CourseBuilderAccessPolicy::can_access_tab_post( 'lessons', $item_id ) ) {
49 + /*if ( ! CourseBuilderAccessPolicy::can_access_tab_post( 'lessons', $item_id ) ) {
49 50 throw new Exception( __( "Sorry, you don't have permission to access this content", 'learnpress' ) );
50 - }
51 + }*/
51 52
52 - $is_create_new = $item_id === CourseBuilder::POST_NEW;
53 - $lessonModel = false;
53 + $is_create_new = $item_id === CourseBuilder::POST_NEW;
54 + $lessonPostModel = false;
54 55
55 56 if ( ! $is_create_new ) {
56 - $lessonModel = LessonPostModel::find( (int) $item_id, true );
57 - if ( ! $lessonModel ) {
57 + $lessonPostModel = LessonPostModel::find( (int) $item_id, true );
58 + if ( ! $lessonPostModel ) {
58 59 throw new Exception( __( 'Lesson not found', 'learnpress' ) );
59 60 }
61 +
62 + $lessonPostModel->check_capabilities_update_item_course();
63 + } else {
64 + $lessonPostModelNew = new LessonPostModel();
65 + $lessonPostModelNew->check_capabilities_create_item_course();
60 66 }
61 67
62 - $data['lessonModel'] = $lessonModel;
68 + $data['lessonModel'] = $lessonPostModel;
63 69
64 70 $section = [
65 71 'wrap' => sprintf(
66 72 '<div class="lp-cb-content" data-post-id="%1$s">',
@@ -74,21 +80,21 @@
74 80 echo Template::combine_components( $section );
75 81 }
76 82
77 83 public function html_header( array $data = [] ): string {
78 - $userModel = $data['userModel'] ?? false;
84 + $userModel = $data['userModel'] ?? false;
79 85 if ( ! $userModel instanceof UserModel ) {
80 86 return '';
81 87 }
82 88
83 - $wp_user = new WP_User( $userModel );
84 - $lessonModel = $data['lessonModel'] ?? false;
89 + $wp_user = new WP_User( $userModel );
90 + $lessonModel = $data['lessonModel'] ?? false;
85 91 $hide_instructor_access_admin_screen = LP_Settings::is_hide_instructor_access_admin_screen();
86 - $title = $lessonModel ? $lessonModel->get_the_title() : __( 'Add New Lesson', 'learnpress' );
87 - $status = $lessonModel ? sanitize_key( (string) $lessonModel->post_status ) : '';
88 - $status_label = 'future' === $status ? __( 'scheduled', 'learnpress' ) : $status;
89 - $hide_wp_edit_link = $hide_instructor_access_admin_screen && user_can( $wp_user, UserModel::ROLE_INSTRUCTOR );
90 - $main_action_label = $lessonModel && 'publish' === $status ? __( 'Update', 'learnpress' ) : __( 'Publish', 'learnpress' );
92 + $title = $lessonModel ? $lessonModel->get_the_title() : __( 'Add New Lesson', 'learnpress' );
93 + $status = $lessonModel ? sanitize_key( (string) $lessonModel->post_status ) : '';
94 + $status_label = 'future' === $status ? __( 'scheduled', 'learnpress' ) : $status;
95 + $hide_wp_edit_link = $hide_instructor_access_admin_screen && user_can( $wp_user, UserModel::ROLE_INSTRUCTOR );
96 + $main_action_label = $lessonModel && 'publish' === $status ? __( 'Update', 'learnpress' ) : __( 'Publish', 'learnpress' );
91 97
92 98 $section = [
93 99 'header_wrap' => '<div class="lp-cb-header">',
94 100 'header_left' => '<div class="lp-cb-header__left">',
@@ -413,9 +419,9 @@
413 419 $title = ! empty( $lesson_model ) ? $lesson_model->get_the_title() : '';
414 420 $edit = [
415 421 'wrapper' => '<div class="cb-lesson-edit-title">',
416 422 'label' => sprintf( '<label for="title" class="cb-lesson-edit-title__label">%s</label>', __( 'Title', 'learnpress' ) ),
417 - 'input' => sprintf( '<input type="text" name="lesson_title" size="30" value="%s" id="title" class="cb-lesson-edit-title__input">', $title ),
423 + 'input' => sprintf( '<input type="text" name="lesson_title" size="30" value="%s" id="title" class="cb-lesson-edit-title__input">', esc_attr( $title ) ),
418 424 'wrapper_end' => '</div>',
419 425 ];
420 426
421 427 return Template::combine_components( $edit );
@@ -420,10 +426,14 @@
420 426
421 427 return Template::combine_components( $edit );
422 428 }
423 429
430 + /**
431 + * @param LessonPostModel $lesson_model
432 + * @return string
433 + */
424 434 public function edit_desc( $lesson_model ) {
425 - $desc = ! empty( $lesson_model ) ? $lesson_model->get_the_content() : '';
435 + $desc = ! empty( $lesson_model ) ? $lesson_model->post_content : '';
426 436 $editor_id = 'lesson_description_editor';
427 437 $editor_settings = array(
428 438 'textarea_name' => 'lesson_description',
429 439 'textarea_rows' => 10,