| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template for displaying content of single course. |
| 4 |
* |
| 5 |
* @author ThimPress |
| 6 |
* @package LearnPress/Templates |
| 7 |
* @version 4.0.1 |
| 8 |
*/ |
| 9 |
|
| 10 |
defined( 'ABSPATH' ) || exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Header for page |
| 14 |
*/ |
| 15 |
if ( ! wp_is_block_theme() ) { |
| 16 |
do_action( 'learn-press/template-header' ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* @since 3.0.0 |
| 21 |
*/ |
| 22 |
do_action( 'learn-press/before-main-content' ); |
| 23 |
do_action( 'learn-press/before-main-content-single-course' ); |
| 24 |
|
| 25 |
// WP 6.4 with Block theme can't detect single course, so code while ( have_posts() ) not run. |
| 26 |
$args = array( |
| 27 |
'name' => get_query_var( LP_COURSE_CPT ), |
| 28 |
'post_type' => LP_COURSE_CPT, |
| 29 |
'numberposts' => 1, |
| 30 |
'post_status' => 'any', |
| 31 |
); |
| 32 |
|
| 33 |
// Fix preview course |
| 34 |
if ( isset( $_REQUEST['preview'] ) && |
| 35 |
( isset( $_REQUEST['p'] ) || isset( $_REQUEST['preview_id'] ) ) ) { |
| 36 |
unset( $args['name'] ); |
| 37 |
$args['include'] = isset( $_REQUEST['p'] ) ? [ (int) $_REQUEST['p'] ] : [ (int) $_REQUEST['preview_id'] ]; |
| 38 |
} |
| 39 |
|
| 40 |
$posts = get_posts( $args ); |
| 41 |
$post = $posts[0] ?? 0; |
| 42 |
|
| 43 |
if ( $post instanceof WP_Post ) { |
| 44 |
if ( $post->post_status !== 'publish' |
| 45 |
&& ( ! current_user_can( ADMIN_ROLE ) && get_current_user_id() != $post->post_author ) ) { |
| 46 |
$template_404 = get_query_template( '404' ); |
| 47 |
if ( $template_404 ) { |
| 48 |
include $template_404; |
| 49 |
} |
| 50 |
} else { |
| 51 |
learn_press_get_template( 'content-single-course' ); |
| 52 |
} |
| 53 |
} |
| 54 |
/*while ( have_posts() ) { |
| 55 |
the_post(); |
| 56 |
learn_press_get_template( 'content-single-course' ); |
| 57 |
}*/ |
| 58 |
|
| 59 |
/** |
| 60 |
* @since 3.0.0 |
| 61 |
*/ |
| 62 |
do_action( 'learn-press/after-main-content-single-course' ); |
| 63 |
do_action( 'learn-press/after-main-content' ); |
| 64 |
|
| 65 |
/** |
| 66 |
* LP sidebar |
| 67 |
*/ |
| 68 |
do_action( 'learn-press/sidebar' ); |
| 69 |
|
| 70 |
/** |
| 71 |
* Footer for page |
| 72 |
*/ |
| 73 |
if ( ! wp_is_block_theme() ) { |
| 74 |
do_action( 'learn-press/template-footer' ); |
| 75 |
} |
| 76 |
|