template( 'course' )->func( 'course_enroll_button' ), 5 );
add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_purchase_button' ), 10 );
add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_external_button' ), 15 );
add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'button_retry' ), 20 );
add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_continue_button' ), 25 );
add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_finish_button' ), 30 );
}
}
if ( ! function_exists( 'learn_press_remove_course_buttons' ) ) {
function learn_press_remove_course_buttons() {
remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_enroll_button' ), 5 );
remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_purchase_button' ), 10 );
//remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_external_button' ), 15 );
remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'button_retry' ), 20 );
remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_continue_button' ), 25 );
remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_finish_button' ), 30 );
}
}
if ( ! function_exists( 'learn_press_get_course_tabs' ) ) {
/**
* Return an array of tabs display in single course page.
*
* @return array
*/
function learn_press_get_course_tabs() {
$course = learn_press_get_course();
$user = learn_press_get_current_user();
$defaults = array();
/**
* Show tab overview if
* 1. Course is preview
* OR
* 2. Course's content not empty
*/
if ( isset( $_GET['preview'] ) || $course ) {
$defaults['overview'] = array(
'title' => esc_html__( 'Overview', 'learnpress' ),
'priority' => 10,
'callback' => LearnPress::instance()->template( 'course' )->callback( 'single-course/tabs/overview.php' ),
);
}
$defaults['curriculum'] = array(
'title' => esc_html__( 'Curriculum', 'learnpress' ),
'priority' => 30,
'callback' => LearnPress::instance()->template( 'course' )->func( 'course_curriculum' ),
);
$defaults['instructor'] = array(
'title' => esc_html__( 'Instructor', 'learnpress' ),
'priority' => 40,
'callback' => LearnPress::instance()->template( 'course' )->callback( 'single-course/tabs/instructor.php' ),
);
if ( $course->get_faqs() ) {
$defaults['faqs'] = array(
'title' => esc_html__( 'FAQs', 'learnpress' ),
'priority' => 50,
'callback' => LearnPress::instance()->template( 'course' )->func( 'faqs' ),
);
}
$tabs = apply_filters( 'learn-press/course-tabs', $defaults );
if ( $tabs ) {
uasort( $tabs, 'learn_press_sort_list_by_priority_callback' );
$request_tab = LP_Helper::sanitize_params_submitted( $_REQUEST['tab'] ?? '' );
$has_active = false;
foreach ( $tabs as $k => $v ) {
$v['id'] = ! empty( $v['id'] ) ? $v['id'] : 'tab-' . $k;
if ( $request_tab === $v['id'] ) {
$v['active'] = true;
$has_active = $k;
} elseif ( isset( $v['active'] ) && $v['active'] ) {
$has_active = true;
}
$tabs[ $k ] = $v;
}
if ( ! $has_active ) {
if ( $course && $user->has_course_status(
$course->get_id(),
array(
'enrolled',
'finished',
)
) && ! empty( $tabs['curriculum'] )
) {
$tabs['curriculum']['active'] = true;
} elseif ( ! empty( $tabs['overview'] ) ) {
$tabs['overview']['active'] = true;
} else {
$keys = array_keys( $tabs );
$first_key = reset( $keys );
$tabs[ $first_key ]['active'] = true;
}
}
}
return $tabs;
}
}
if ( ! function_exists( 'learn_press_content_item_summary_question' ) ) {
function learn_press_content_item_summary_question() {
$quiz = LP_Global::course_item_quiz();
$question = $quiz->get_viewing_question();
if ( $question ) {
$course = learn_press_get_course();
$user = learn_press_get_current_user();
$answered = false;
$course_data = $user->get_course_data( $course->get_id() );
$user_quiz = $course_data->get_item_quiz( $quiz->get_id() );
if ( $user_quiz ) {
$answered = $user_quiz->get_question_answer( $question->get_id() );
$question->show_correct_answers(
$user->has_checked_answer(
$question->get_id(),
$quiz->get_id(),
$course->get_id()
) ? 'yes' : false
);
$question->disable_answers( $user_quiz->get_status() == 'completed' ? 'yes' : false );
}
$question->render( $answered );
}
}
}
if ( ! function_exists( 'learn_press_content_item_body_class' ) ) {
// Add more assets into page that displaying content of an item
add_filter( 'body_class', 'learn_press_content_item_body_class', 10 );
function learn_press_content_item_body_class( $classes ) {
global $lp_course_item;
if ( wp_is_mobile() ) {
$sidebar_toggle_class = 'lp-sidebar-toggle__close';
} else {
$sidebar_toggle_class = learn_press_cookie_get( 'sidebar-toggle' ) ? 'lp-sidebar-toggle__close' : 'lp-sidebar-toggle__open';
}
if ( $lp_course_item ) {
$classes[] = 'course-item-popup';
$classes[] = 'viewing-course-item';
$classes[] = 'viewing-course-item-' . $lp_course_item->get_id();
$classes[] = 'course-item-' . $lp_course_item->get_item_type();
$classes[] = $sidebar_toggle_class;
}
return $classes;
}
}
if ( ! function_exists( 'learn_press_content_item_edit_links' ) ) {
/**
* Add edit links for course item question to admin bar.
*/
function learn_press_content_item_edit_links() {
global $wp_admin_bar, $post, $lp_course_item, $lp_quiz_question;
if ( ! ( ! is_admin() && is_user_logged_in() ) ) {
return;
}
/**
* Edit link for lesson/quiz or any other course's item.
*/
if ( $lp_course_item ) {
$post_type_object = get_post_type_object( $lp_course_item->get_item_type() );
if ( $post_type_object && current_user_can(
'edit_post',
$lp_course_item->get_id()
) && $post_type_object->show_in_admin_bar && get_edit_post_link( $lp_course_item->get_id() ) ) {
$type = get_post_type( $lp_course_item->get_id() );
if ( apply_filters( 'learn-press/edit-admin-bar-button', true, $lp_course_item ) ) {
$wp_admin_bar->add_menu(
array(
'id' => 'edit-' . $type,
'title' => $post_type_object->labels->edit_item,
'href' => get_edit_post_link( $lp_course_item->get_id() ),
)
);
}
}
}
/**
* Edit link for quiz's question.
*/
if ( $lp_quiz_question ) {
$post_type_object = get_post_type_object( $lp_quiz_question->get_item_type() );
$edit_post_link = get_edit_post_link( $lp_quiz_question->get_id() );
if ( $post_type_object && current_user_can(
'edit_post',
$lp_quiz_question->get_id()
) && $post_type_object->show_in_admin_bar && $edit_post_link ) {
$type = get_post_type( $lp_quiz_question->get_id() );
$wp_admin_bar->add_menu(
array(
'id' => 'edit-' . $type,
'title' => $post_type_object->labels->edit_item,
'href' => $edit_post_link,
)
);
}
}
}
}
add_filter( 'admin_bar_menu', 'learn_press_content_item_edit_links', 90 );
if ( ! function_exists( 'learn_press_single_quiz_args' ) ) {
function learn_press_single_quiz_args() {
$args = array();
if ( LP_PAGE_QUIZ !== LP_Page_Controller::page_current() ) {
return $args;
}
$quiz = LP_Global::course_item_quiz();
$course = learn_press_get_course();
if ( $quiz && $course ) {
$user = learn_press_get_current_user();
$course_id = $course->get_id();
$user_quiz = $user->get_item_data( $quiz->get_id(), $course_id );
if ( $user_quiz ) {
$remaining_time = $user_quiz->get_time_remaining();
} else {
$remaining_time = false;
}
$args = array(
'id' => $quiz->get_id(),
//'totalTime' => -1,
//'remainingTime' => $remaining_time ? $remaining_time->get() : $quiz->get_duration()->get(),
'status' => $user->get_item_status( $quiz->get_id(), $course_id ),
'checkNorequizenroll' => $course->is_no_required_enroll(),
'navigationPosition' => LP_Settings::get_option( 'navigation_position', 'yes' ),
);
}
return $args;
}
}
if ( ! function_exists( 'learn_press_single_document_title_parts' ) ) {
/**
* Custom document title depending on LP current page.
* E.g: Single course, profile, etc...
*
* @param array $title
*
* @return array
* @since 3.0.0
*/
function learn_press_single_document_title_parts( $title ) {
if ( learn_press_is_course() ) {
$item = LP_Global::course_item();
if ( $item ) {
$title['title'] = join(
' ',
apply_filters(
'learn-press/document-course-title-parts',
array(
$title['title'],
' → ',
$item->get_title(),
)
)
);
}
} elseif ( learn_press_is_courses() ) {
if ( learn_press_is_search() ) {
$title['title'] = esc_html__( 'Course Search Results', 'learnpress' );
} else {
$title['title'] = esc_html__( 'Courses', 'learnpress' );
}
} elseif ( learn_press_is_profile() ) {
$profile = LP_Profile::instance();
$tab_slug = $profile->get_current_tab();
$tab = $profile->get_tab_at( $tab_slug );
$page_id = learn_press_get_page_id( 'profile' );
if ( $page_id ) {
$page_title = get_the_title( $page_id );
} else {
$page_title = '';
}
if ( $tab ) {
$title['title'] = join(
' ',
apply_filters(
'learn-press/document-profile-title-parts',
array(
$page_title,
'→',
$tab['title'],
)
)
);
}
}
return $title;
}
}
if ( ! function_exists( 'learn_press_course_item_class' ) ) {
function learn_press_course_item_class( $item_id, $course_id = 0, $class = null ) {
switch ( get_post_type( $item_id ) ) {
case 'lp_lesson':
learn_press_course_lesson_class( $item_id, $course_id, $class );
break;
case 'lp_quiz':
learn_press_course_quiz_class( $item_id, $course_id, $class );
break;
}
}
}
if ( ! function_exists( 'learn_press_course_lesson_class' ) ) {
/**
* The class of lesson in course curriculum
*
* @param int $lesson_id
* @param int $course_id
* @param array|string $class
* @param boolean $echo
*
* @return mixed
*/
function learn_press_course_lesson_class( $lesson_id = null, $course_id = 0, $class = null, $echo = true ) {
$user = learn_press_get_current_user();
if ( ! $course_id ) {
$course_id = get_the_ID();
}
$course = learn_press_get_course( $course_id );
if ( ! $course ) {
return '';
}
if ( is_string( $class ) && $class ) {
$class = preg_split( '!\s+!', $class );
} else {
$class = array();
}
$classes = array(
'course-lesson course-item course-item-' . $lesson_id,
);
$user = learn_press_get_current_user();
$status = $user->get_item_status( $lesson_id );
if ( $status ) {
$classes[] = "item-has-status item-{$status}";
}
if ( $lesson_id && $course->is_current_item( $lesson_id ) ) {
$classes[] = 'item-current';
}
if ( learn_press_is_course() ) {
if ( $course->is_free() ) {
$classes[] = 'free-item';
}
}
$lesson = LP_Lesson::get_lesson( $lesson_id );
if ( $lesson && $lesson->is_preview() ) {
$classes[] = 'preview-item';
}
$classes = array_unique( array_merge( $classes, $class ) );
if ( $echo ) {
echo 'class="' . implode( ' ', $classes ) . '"';
}
return $classes;
}
}
if ( ! function_exists( 'learn_press_course_quiz_class' ) ) {
/**
* The class of lesson in course curriculum
*
* @param int $quiz_id
* @param int $course_id
* @param string|array $class
* @param boolean $echo
*
* @return mixed
*/
function learn_press_course_quiz_class( $quiz_id = null, $course_id = 0, $class = null, $echo = true ) {
$user = learn_press_get_current_user();
if ( ! $course_id ) {
$course_id = get_the_ID();
}
if ( is_string( $class ) && $class ) {
$class = preg_split( '!\s+!', $class );
} else {
$class = array();
}
$course = learn_press_get_course( $course_id );
if ( ! $course ) {
return '';
}
$classes = array(
'course-quiz course-item course-item-' . $quiz_id,
);
$status = $user->get_item_status( $quiz_id );
if ( $status ) {
$classes[] = "item-has-status item-{$status}";
}
if ( $quiz_id && $course->is_current_item( $quiz_id ) ) {
$classes[] = 'item-current';
}
/*
if ( $user->can_view_item( $quiz_id, $course_id )->flag ) {
$classes[] = 'viewable';
}*/
if ( $course->is_final_quiz( $quiz_id ) ) {
$classes[] = 'final-quiz';
}
$classes = array_unique( array_merge( $classes, $class ) );
if ( $echo ) {
echo 'class="' . implode( ' ', $classes ) . '"';
}
return $classes;
}
}
if ( ! function_exists( 'learn_press_course_class' ) ) {
/**
* Append new class to course post type
*
* @param $classes
* @param $class
* @param $post_id
*
* @return string
*/
function learn_press_course_class( $classes, $class, $post_id = '' ) {
if ( is_learnpress() ) {
$classes = (array) $classes;
}
if ( $post_id === 0 ) {
$classes[] = 'page type-page';
}
if ( ! $post_id || 'lp_course' !== get_post_type( $post_id ) ) {
return $classes;
}
$classes[] = 'course';
return apply_filters( 'learn_press_course_class', $classes );
}
}
function learn_press_setup_user() {
$GLOBALS['lp_user'] = learn_press_get_current_user();
}
add_action( 'init', 'learn_press_setup_user', 1000 );
/**
* Display a message immediately with out push into queue
*
* @param $message
* @param string $type
*/
function learn_press_display_message( $message, $type = 'success' ) {
$messages = learn_press_session_get( learn_press_session_message_id() );
learn_press_session_set( learn_press_session_message_id(), null );
// add new notice and display
learn_press_add_message( $message, $type );
echo learn_press_get_messages( true );
// store back messages
learn_press_session_set( learn_press_session_message_id(), $messages );
}
/**
* Returns all notices added
*
* @param bool $clear
*
* @return string
*/
function learn_press_get_messages( $clear = false ) {
ob_start();
learn_press_print_messages( $clear );
return ob_get_clean();
}
/**
* Add new message into queue for displaying.
*
* @param string $message
* @param string $type
* @param array $options
* @param int|bool $current_user . @since 3.0.9 - add for current user only
*/
function learn_press_add_message( $message, $type = 'success', $options = array(), $current_user = true ) {
if ( is_string( $options ) ) {
$options = array( 'id' => $options );
}
$options = wp_parse_args(
$options,
array(
'id' => '',
)
);
if ( $current_user ) {
if ( true === $current_user ) {
$current_user = get_current_user_id();
}
}
$key = "messages{$current_user}";
$messages = learn_press_session_get( $key );
if ( empty( $messages[ $type ] ) ) {
$messages[ $type ] = array();
}
$messages[ $type ][ $options['id'] ] = array(
'content' => $message,
'options' => $options,
);
learn_press_session_set( $key, $messages );
}
function learn_press_get_message( $message, $type = 'success' ) {
ob_start();
learn_press_display_message( $message, $type );
$message = ob_get_clean();
return $message;
}
/**
* Remove message added into queue by id and/or type.
*
* @param string $id
* @param string|array $type
*
* @since 3.0.0
*/
function learn_press_remove_message( $id = '', $type = '' ) {
$groups = learn_press_session_get( learn_press_session_message_id() );
if ( ! $groups ) {
return;
}
settype( $type, 'array' );
if ( $id ) {
foreach ( $groups as $message_type => $messages ) {
if ( ! sizeof( $type ) ) {
if ( isset( $groups[ $message_type ][ $id ] ) ) {
unset( $groups[ $message_type ][ $id ] );
}
} elseif ( in_array( $message_type, $type ) ) {
if ( isset( $groups[ $message_type ][ $id ] ) ) {
unset( $groups[ $message_type ][ $id ] );
}
}
}
} elseif ( sizeof( $type ) ) {
foreach ( $type as $t ) {
if ( isset( $groups[ $t ] ) ) {
unset( $groups[ $t ] );
}
}
} else {
$groups = array();
}
learn_press_session_set( learn_press_session_message_id(), $groups );
}
/**
* Print out the message stored in the queue
*
* @param bool
*/
function learn_press_print_messages( $clear = true ) {
$messages = learn_press_session_get( learn_press_session_message_id() );
learn_press_get_template( 'global/message.php', array( 'messages' => $messages ) );
if ( $clear ) {
learn_press_session_set( learn_press_session_message_id(), array() );
}
}
function learn_press_message_count( $type = '' ) {
$count = 0;
$messages = learn_press_session_get( learn_press_session_message_id(), array() );
if ( isset( $messages[ $type ] ) ) {
$count = absint( sizeof( $messages[ $type ] ) );
} elseif ( empty( $type ) ) {
foreach ( $messages as $message ) {
$count += absint( sizeof( $message ) );
}
}
return $count;
}
function learn_press_session_message_id() {
return 'messages' . get_current_user_id();
}
/**
* Displays messages before main content
*/
function _learn_press_print_messages() {
$item = LP_Global::course_item();
if ( ( 'learn_press_before_main_content' == current_action() ) && $item ) {
return;
}
learn_press_print_messages( true );
}
add_action( 'learn_press_before_main_content', '_learn_press_print_messages', 50 );
add_action( 'learn-press/before-course-item-content', '_learn_press_print_messages', 50 );
if ( ! function_exists( 'learn_press_page_title' ) ) {
/**
* learn_press_page_title function.
*
* @param boolean $echo
* @return string
*/
function learn_press_page_title( bool $echo = false ): string {
$page_title = '';
if ( is_search() ) {
// Comment by tungnx
/*$page_title = sprintf( __( 'Search Results for: “%s”', 'learnpress' ), get_search_query() );
if ( get_query_var( 'paged' ) ) {
$page_title .= sprintf( __( ' – Page %s', 'learnpress' ), get_query_var( 'paged' ) );
}*/
} elseif ( is_tax() ) {
$page_title = single_term_title( '', false );
} else {
$courses_page_id = learn_press_get_page_id( 'courses' );
$page_title = get_the_title( $courses_page_id );
}
return apply_filters( 'learn_press_page_title', $page_title );
}
}
/**
* Get template part.
*
* @param string $slug
* @param string $name
*
* @return string
*/
function learn_press_get_template_part( $slug, $name = '' ) {
$template = '';
if ( $name ) {
$template = locate_template(
array(
"{$slug}-{$name}.php",
learn_press_template_path() . "/{$slug}-{$name}.php",
)
);
}
// Get default slug-name.php
if ( ! $template && $name && file_exists( LP_PLUGIN_PATH . "/templates/{$slug}-{$name}.php" ) ) {
$template = LP_PLUGIN_PATH . "/templates/{$slug}-{$name}.php";
}
// If template file doesn't exist, look in yourtheme/slug.php and yourtheme/learnpress/slug.php
if ( ! $template ) {
$template = locate_template( array( "{$slug}.php", learn_press_template_path() . "/{$slug}.php" ) );
}
// override path of child theme in parent theme - Fix for eduma by tuanta
$file_ct_in_pr = apply_filters( 'learn_press_child_in_parrent_template_path', '' );
if ( $file_ct_in_pr && $name ) {
$template_child = locate_template(
array(
"{$slug}-{$name}.php",
'lp-child-path/' . learn_press_template_path() . '/' . $file_ct_in_pr . "/{$slug}-{$name}.php",
)
);
if ( $template_child && file_exists( $template_child ) ) {
$template = $template_child;
}
// check in child theme if have filter learn_press_child_in_parrent_template_path
$check_child_theme = get_stylesheet_directory() . '/' . learn_press_template_path() . "{$slug}-{$name}.php";
if ( $check_child_theme && file_exists( $check_child_theme ) ) {
$template = $check_child_theme;
}
}
// Allow 3rd party plugin filter template file from their plugin
if ( $template ) {
$template = apply_filters( 'learn_press_get_template_part', $template, $slug, $name );
}
if ( $template && file_exists( $template ) ) {
load_template( $template, false );
}
return $template;
}
/**
* Get other templates passing attributes and including the file.
*
* @param string $template_name .
* @param array $args (default: array()) .
* @param string $template_path (default: '').
* @param string $default_path (default: '').
*
* @return void
*/
function learn_press_get_template( $template_name = '', $args = array(), $template_path = '', $default_path = '' ) {
if ( $args && is_array( $args ) ) {
extract( $args );
}
if ( false === strpos( $template_name, '.php' ) ) {
$template_name .= '.php';
}
$located = learn_press_locate_template( $template_name, $template_path, $default_path );
if ( ! file_exists( $located ) ) {
_doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $located ), '2.1' );
$log = sprintf( 'TEMPLATE MISSING: Template %s doesn\'t exists.', $template_name );
error_log( $log );
if ( LP_Debug::is_debug() ) {
echo sprintf( '', $log );
}
return;
}
// Allow 3rd party plugin filter template file from their plugin
$located = apply_filters(
'learn_press_get_template',
$located,
$template_name,
$args,
$template_path,
$default_path
);
if ( $located != '' ) {
do_action( 'learn_press_before_template_part', $template_name, $template_path, $located, $args );
include $located;
do_action( 'learn_press_after_template_part', $template_name, $template_path, $located, $args );
}
}
/**
* Get template content
*
* @param $template_name
* @param array $args
* @param string $template_path
* @param string $default_path
*
* @return string
* @uses learn_press_get_template();
*/
function learn_press_get_template_content( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
ob_start();
learn_press_get_template( $template_name, $args, $template_path, $default_path );
return ob_get_clean();
}
/**
* Locate a template and return the path for inclusion.
*
* @param string $template_name
* @param string $template_path (default: '')
* @param string $default_path (default: '')
*
* @return string
*/
function learn_press_locate_template( $template_name, $template_path = '', $default_path = '' ) {
if ( ! $template_path ) {
$template_path = learn_press_template_path();
}
if ( ! $default_path ) {
$default_path = LP_PLUGIN_PATH . 'templates/';
}
/**
* Disable override templates in theme by default since LP 4.0.0
*/
if ( learn_press_override_templates() ) {
$template = locate_template(
array(
trailingslashit( $template_path ) . $template_name,
$template_name,
)
);
// override path of child theme in parent theme - Fix for eduma by tuanta
$file_ct_in_pr = apply_filters( 'learn_press_child_in_parrent_template_path', '' );
if ( $file_ct_in_pr ) {
$template_child = locate_template(
array(
trailingslashit( 'lp-child-path/' . $template_path . '/' . $file_ct_in_pr ) . $template_name,
$template_name,
)
);
if ( $template_child && file_exists( $template_child ) ) {
$template = $template_child;
}
// check in child theme if have filter learn_press_child_in_parrent_template_path
$check_child_theme = get_stylesheet_directory() . '/' . trailingslashit( $template_path ) . $template_name;
if ( $check_child_theme && file_exists( $check_child_theme ) ) {
$template = $check_child_theme;
}
}
}
if ( ! isset( $template ) || ! $template ) {
$template = trailingslashit( $default_path ) . $template_name;
}
return apply_filters( 'learn_press_locate_template', $template, $template_name, $template_path );
}
/**
* Returns the name of folder contains template files in theme
*
* @param bool
*
* @return string
*/
function learn_press_template_path( $slash = false ) {
return apply_filters( 'learn_press_template_path', 'learnpress', $slash ) . ( $slash ? '/' : '' );
}
/**
* Disable override templates in theme by default
*
* @return bool
* @since 4.0.0
*/
function learn_press_override_templates() {
return apply_filters( 'learn-press/override-templates', false );
}
if ( ! function_exists( 'learn_press_is_404' ) ) {
/**
* Set header is 404
*/
function learn_press_is_404() {
global $wp_query;
if ( ! empty( $_REQUEST['debug-404'] ) ) {
learn_press_debug( debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, $_REQUEST['debug-404'] ) );
}
$wp_query->set_404();
status_header( 404 );
}
}
if ( ! function_exists( 'learn_press_404_page' ) ) {
/**
* Display 404 page
*/
function learn_press_404_page() {
learn_press_is_404();
}
}
if ( ! function_exists( 'learn_press_generate_template_information' ) ) {
function learn_press_generate_template_information( $template_name, $template_path, $located, $args ) {
$debug = learn_press_get_request( 'show-template-location' );
if ( $debug == 'on' ) {
echo '';
}
}
}
if ( ! function_exists( 'learn_press_course_remaining_time' ) ) {
/**
* Show the time remain of a course
*/
function learn_press_course_remaining_time() {
$user = learn_press_get_current_user();
if ( ! $user->has_finished_course( get_the_ID() ) && $text = learn_press_get_course( get_the_ID() )->get_user_duration_html( $user->get_id() ) ) {
learn_press_display_message( $text );
}
}
}
if ( ! function_exists( 'learn_press_item_meta_type' ) ) {
function learn_press_item_meta_type( $course, $item ) {
?>
post_type == 'lp_quiz' ) { ?>
final_quiz == $item->ID ) { ?>
post_type == 'lp_lesson' ) { ?>
ID, '_lp_preview', true ) == 'yes' ) { ?>
get_id();
} elseif ( $user instanceof WP_User ) {
$id = $user->ID;
} elseif ( is_numeric( $user ) ) {
$id = $user;
}
if ( ! isset( $id ) ) {
return '';
}
$info = get_userdata( $id );
return $info ? $info->display_name : '';
}
}
/**
* @deprecated 4.1.6.9
*/
/*if ( ! function_exists( 'learn_press_content_item_comments' ) ) {
function learn_press_content_item_comments() {
$item = LP_Global::course_item();
if ( ! $item ) {
return;
}
if ( ! $item->is_support( 'comments' ) ) {
return;
}
global $post;
$post = get_post( $item->get_id() );
setup_postdata( $post );
if ( ! have_comments() ) {
return;
}
add_filter( 'deprecated_file_trigger_error', '__return_false' );
comments_template();
remove_filter( 'deprecated_file_trigger_error', '__return_false' );
wp_reset_postdata();
}
}*/
function learn_press_course_comments_open( $open, $post_id ) {
$post = get_post( $post_id );
if ( LP_COURSE_CPT == $post->post_type ) {
$open = false;
}
return $open;
}
function learn_press_is_content_item_only() {
return ! empty( $_REQUEST['content-item-only'] );
}
function learn_press_label_html( $label, $type = '' ) {
?>
is_final_quiz( $item->get_id() ) ) {
return;
}
echo '';
}
function learn_press_comments_template_query_args( $comment_args ) {
$post_type = get_post_type( $comment_args['post_id'] );
if ( $post_type == LP_COURSE_CPT ) {
$comment_args['type__not_in'] = 'review';
}
return $comment_args;
}
if ( ! function_exists( 'learn_press_filter_get_comments_number' ) ) {
function learn_press_filter_get_comments_number( $count, $post_id = 0 ) {
global $wpdb;
if ( ! $post_id ) {
$post_id = learn_press_get_course_id();
}
if ( ! $post_id ) {
return $count;
}
if ( get_post_type( $post_id ) == LP_COURSE_CPT ) {
$sql = $wpdb->prepare(
' SELECT count(*) '
. " FROM {$wpdb->comments} "
. ' WHERE comment_post_ID = %d '
. ' AND comment_approved = 1 '
. ' AND comment_type != %s ',
$post_id,
'review'
);
$count = $wpdb->get_var( $sql );
// @since 3.0.0
$count = apply_filters( 'learn-press/course-comments-number', $count, $post_id );
}
return $count;
}
}
/**
* Add custom classes to body tag class name
*
* @param array $classes
*
* @return array
*
* @since 3.0.0
*/
function learn_press_body_classes( $classes ) {
$pages = learn_press_static_page_ids();
if ( $pages ) {
$is_lp_page = false;
settype( $classes, 'array' );
foreach ( $pages as $slug => $id ) {
if ( is_page( $id ) ) {
$classes[] = $slug;
$is_lp_page = true;
}
}
if ( $is_lp_page || is_learnpress() ) {
$classes[] = get_stylesheet();
$classes[] = 'learnpress';
$classes[] = 'learnpress-page';
}
}
return $classes;
}
add_filter( 'body_class', 'learn_press_body_classes', 10 );
/**
* Return true if user is learning a course
*
* @param int $course_id
*
* @return bool
* @since 3.0
* @version 1.0.1
*/
function learn_press_is_learning_course( int $course_id = 0 ): bool {
$is_learning = false;
$user = learn_press_get_current_user();
$course = learn_press_get_course( $course_id );
if ( ! $course ) {
return $is_learning;
}
if ( $user ) {
return $user->has_enrolled_or_finished( $course_id );
}
if ( $course->is_no_required_enroll() ) {
$is_learning = true;
}
return apply_filters( 'lp/is-learning-course', $is_learning, $course_id );
}
/**
* Output custom css from settings
*
* @since 4.0.0
*/
if ( ! function_exists( 'learn_press_print_custom_styles' ) ) {
function learn_press_print_custom_styles() {
$primary_color = LP_Settings::instance()->get( 'primary_color' );
$secondary_color = LP_Settings::instance()->get( 'secondary_color' );
?>
get_post_type() !== LP_LESSON_CPT ) {
return $classes;
}
return $classes;
}
function learn_press_maybe_load_comment_js() {
$item = LP_Global::course_item();
if ( $item ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'learn_press_maybe_load_comment_js' );
/**
* Get list layouts archive course setting
*
* @editor tungnx
* @modify 4.1.3
*/
function learn_press_courses_layouts() {
return apply_filters(
'learnpress/archive-courses-layouts',
[
'grid' => 'Grid',
'list' => 'List',
]
);
}
/**
* Get layout template for archive course page.
*
* @return mixed
* @since 3.3.0
* @editor tungnx
* @modify 4.1.3
*/
function learn_press_get_courses_layout() {
$layout = LP_Request::get_cookie( 'courses-layout' );
if ( ! $layout ) {
$layout = LP_Settings::get_option( 'archive_courses_layout', 'list' );
}
return $layout;
}
function learn_press_register_sidebars() {
register_sidebar(
array(
'name' => esc_html__( 'Course Sidebar', 'learnpress' ),
'id' => 'course-sidebar',
'description' => esc_html__( 'Widgets in this area will be shown in a single course', 'learnpress' ),
'before_widget' => '