post_type, 'normal', 'high' );
}
public function metabox( $post_id ) {
$tabs = apply_filters(
'lp_course_data_settings_tabs',
array(
'general' => array(
'label' => esc_html__( 'General', 'learnpress' ),
'target' => 'general_course_data',
'icon' => 'dashicons-admin-tools',
'priority' => 10,
'content' => $this->general( $post_id ),
),
'price' => array(
'label' => esc_html__( 'Pricing', 'learnpress' ),
'target' => 'price_course_data',
'icon' => 'dashicons-cart',
'priority' => 20,
'content' => $this->lp_price( $post_id ),
),
'extra' => array(
'label' => esc_html__( 'Extra Information', 'learnpress' ),
'target' => 'extra_course_data',
'icon' => 'dashicons-excerpt-view',
'priority' => 30,
'content' => $this->extra( $post_id ),
),
'assessment' => array(
'label' => esc_html__( 'Assessment', 'learnpress' ),
'target' => 'assessment_course_data',
'icon' => 'dashicons-awards',
'priority' => 40,
'content' => $this->assessment( $post_id ),
),
'author' => array(
'label' => esc_html__( 'Author', 'learnpress' ),
'target' => 'author_course_data',
'icon' => 'dashicons-businessman',
'priority' => 50,
'content' => $this->author( $post_id ),
),
)
);
$tabs = apply_filters( 'learnpress/course/metabox/tabs', $tabs, $post_id );
uasort( $tabs, array( __CLASS__, 'data_tabs_sort' ) );
return $tabs;
}
public function general( $thepostid ) {
$repurchase_option_desc = sprintf( '1. %s', __( 'Reset course progress: The course progress and results of student will be removed.' ) );
$repurchase_option_desc .= '
' . sprintf( '2. %s', __( 'Keep course progress: The course progress and results of student will remain.' ) );
$repurchase_option_desc .= '
' . sprintf( '3. %s', __( 'Open popup: The student can decide whether their course progress will be reset with the confirm popup.' ) );
return apply_filters(
'lp/course/meta-box/fields/general',
array(
'_lp_duration' => new LP_Meta_Box_Duration_Field(
esc_html__( 'Duration', 'learnpress' ),
esc_html__( 'Set to 0 for the lifetime access.', 'learnpress' ),
'10',
array(
'default_time' => 'week',
'custom_attributes' => array(
'min' => '0',
'step' => '1',
),
)
),
'_lp_block_expire_duration' => new LP_Meta_Box_Checkbox_Field(
esc_html__( 'Block content', 'learnpress' ),
esc_html__( 'When the duration expires, the course is blocked.', 'learnpress' ),
'no'
),
'_lp_block_finished' => new LP_Meta_Box_Checkbox_Field(
'',
esc_html__( 'Block the course after the student finished this course.', 'learnpress' ),
'yes'
),
'_lp_allow_course_repurchase' => new LP_Meta_Box_Checkbox_Field(
__( 'Allow Repurchase', 'learnpress' ),
esc_html__( 'Allow users to repurchase this course after it has been finished or blocked (Do not apply to free courses).', 'learnpress' ),
'no'
),
'_lp_course_repurchase_option' => new LP_Meta_Box_Select_Field(
esc_html__( 'Repurchase action', 'learnpress' ),
$repurchase_option_desc,
'reset',
array(
'options' => array(
'reset' => esc_html__( 'Reset course progress', 'learnpress' ),
'keep' => esc_html__( 'Keep course progress', 'learnpress' ),
'popup' => esc_html__( 'Open popup', 'learnpress' ),
),
'show' => array( '_lp_allow_course_repurchase', '=', 'yes' ), // use 'show' or 'hide'
)
),
'_lp_level' => new LP_Meta_Box_Select_Field(
esc_html__( 'Level', 'learnpress' ),
esc_html__( 'Choose a difficulty level.', 'learnpress' ),
'',
array(
'options' => lp_course_level(),
)
),
'_lp_students' => new LP_Meta_Box_Text_Field(
esc_html__( 'Fake Students Enrolled', 'learnpress' ),
esc_html__( 'How many students have taken this course?', 'learnpress' ),
0,
array(
'type_input' => 'number',
'custom_attributes' => array(
'min' => '0',
'step' => '1',
),
'style' => 'width: 70px;',
)
),
'_lp_max_students' => new LP_Meta_Box_Text_Field(
esc_html__( 'Max student', 'learnpress' ),
esc_html__( 'The maximum number of students that can join a course. Set 0 for unlimited.', 'learnpress' ),
0,
array(
'type_input' => 'number',
'custom_attributes' => array(
'min' => '0',
'step' => '1',
),
'style' => 'width: 70px;',
)
),
'_lp_retake_count' => new LP_Meta_Box_Text_Field(
esc_html__( 'Re-take Course', 'learnpress' ),
esc_html__( 'The number of times a user can learn again from this course. To disable, set to 0.', 'learnpress' ),
0,
array(
'type_input' => 'number',
'custom_attributes' => array(
'min' => '0',
'step' => '1',
),
'style' => 'width: 70px;',
)
),
'_lp_has_finish' => new LP_Meta_Box_Checkbox_Field(
esc_html__( 'Finish button', 'learnpress' ),
esc_html__( 'Allow showing the finish button when the student has completed all items but has not passed the course assessment yet.', 'learnpress' ),
'yes'
),
'_lp_featured' => new LP_Meta_Box_Checkbox_Field(
esc_html__( 'Featured list', 'learnpress' ),
esc_html__( 'Add the course to the Featured List.', 'learnpress' ),
'no'
),
'_lp_featured_review' => new LP_Meta_Box_Textarea_Field(
esc_html__( 'Featured review', 'learnpress' ),
esc_html__( 'A good review to promote the course.', 'learnpress' )
),
'_lp_external_link_buy_course' => new LP_Meta_Box_Text_Field(
esc_html__( 'External link', 'learnpress' ),
esc_html__( 'Normally used for offline classes. Ex: link to a contact page. Format: https://google.com', 'learnpress' ),
'',
array(
'desc_tip' => 'You can apply for case: user register form.
You accept for user can learn courses by add manual order on backend',
)
),
)
);
}
/**
* Setting course price
*
* @param $post_id
*
* @author tungnx
* @since 4.1.5
* @version 1.0.0
* @return array
*/
public function lp_price( $post_id ): array {
$key_exists = LP_Database::getInstance()->check_key_postmeta_exists( $post_id, '_lp_regular_price' );
$price = get_post_meta( $post_id, '_lp_price', true );
$regular_price = $key_exists ? get_post_meta( $post_id, '_lp_regular_price', true ) : $price;
$sale_price = get_post_meta( $post_id, '_lp_sale_price', true );
return apply_filters(
'lp/course/meta-box/fields/price',
array(
'_lp_regular_price' => new LP_Meta_Box_Text_Field(
esc_html__( 'Regular price', 'learnpress' ),
sprintf( __( 'Set a regular price (%s). Leave it blank for Free.', 'learnpress' ), learn_press_get_currency() ),
$regular_price,
array(
'type_input' => 'text',
'custom_attributes' => array(
'min' => '0',
'step' => '0.01',
),
'style' => 'width: 70px;',
'class' => 'lp_meta_box_regular_price',
)
),
'_lp_sale_price' => new LP_Meta_Box_Text_Field(
esc_html__( 'Sale price', 'learnpress' ),
'' . esc_html__( 'Schedule', 'learnpress' ) . '',
$sale_price,
array(
'type_input' => 'text',
'custom_attributes' => array(
'min' => '0',
'step' => '0.01',
),
'style' => 'width: 70px;',
'class' => 'lp_meta_box_sale_price',
)
),
'_lp_sale_start' => new LP_Meta_Box_Date_Field(
esc_html__( 'Sale start dates', 'learnpress' ),
'',
'',
array(
'wrapper_class' => 'lp_sale_start_dates_fields',
'placeholder' => _x( 'From…', 'placeholder', 'learnpress' ),
)
),
'_lp_sale_end' => new LP_Meta_Box_Date_Field(
esc_html__( 'Sale end dates', 'learnpress' ),
'',
'',
array(
'wrapper_class' => 'lp_sale_end_dates_fields',
'placeholder' => _x( 'To…', 'placeholder', 'learnpress' ),
'cancel' => true,
)
),
'_lp_no_required_enroll' => new LP_Meta_Box_Checkbox_Field(
esc_html__( 'There is no enrollment requirement', 'learnpress' ),
esc_html__( 'Students can see the content of all course items and take the quiz without logging in.', 'learnpress' ),
'no'
),
)
);
}
public function author( $thepostid ) {
$post = get_post( $thepostid );
$author = $post ? $post->post_author : get_current_user_id();
$options = array();
$role = array( 'administrator', 'lp_teacher' );
$role = apply_filters( 'learn_press_course_author_role_meta_box', $role );
foreach ( $role as $_role ) {
$users_by_role = get_users( array( 'role' => $_role ) );
if ( $users_by_role ) {
foreach ( $users_by_role as $user ) {
$options[ $user->get( 'ID' ) ] = $user->user_login;
}
}
}
return apply_filters(
'lp/course/meta-box/fields/author',
array(
'_lp_course_author' => new LP_Meta_Box_Select_Field(
esc_html__( 'Author', 'learnpress' ),
'',
$author,
array(
'options' => $options,
'style' => 'min-width:200px;',
)
),
)
);
}
public function assessment( $thepostid ) {
$post = get_post( $thepostid );
$course_result_desc = '';
$course_results = get_post_meta( $thepostid, '_lp_course_result', true );
$course_result_desc .= __( 'The method of evaluating a student\'s performance in a course.', 'learnpress' );
if ( $course_results == 'evaluate_final_quiz' && ! get_post_meta( $thepostid, '_lp_final_quiz', true ) ) {
$course_result_desc .= __( '
Note! There is no final quiz in the course. Please add a final quiz.', 'learnpress' );
}
$final_quizz_passing = '';
$course = learn_press_get_course( $thepostid );
if ( $course ) {
$passing_grade = $url = '';
$final_quiz = $course->get_final_quiz();
if ( $final_quiz ) {
$passing_grade = get_post_meta( $final_quiz, '_lp_passing_grade', true );
$url = get_edit_post_link( $final_quiz ) . '#_lp_passing_grade';
$final_quizz_passing = '