| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | * Template for displaying content of single course. |
| 4 | 4 | * |
| 5 | 5 | * @author ThimPress |
| 6 | 6 | * @package LearnPress/Templates |
| 7 | - * @version 4.0.0 | |
| 7 | + * @version 4.0.1 | |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | defined( 'ABSPATH' ) || exit; |
| 11 | 11 | |
| @@ -11,10 +11,10 @@ | ||
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Header for page |
| 14 | 14 | */ |
| 15 | -if ( empty( $is_block_theme ) ) { | |
| 16 | - get_header( 'course' ); | |
| 15 | +if ( ! wp_is_block_theme() ) { | |
| 16 | + do_action( 'learn-press/template-header' ); | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * @since 3.0.0 |
| @@ -21,12 +21,41 @@ | ||
| 21 | 21 | */ |
| 22 | 22 | do_action( 'learn-press/before-main-content' ); |
| 23 | 23 | do_action( 'learn-press/before-main-content-single-course' ); |
| 24 | 24 | |
| 25 | -while ( have_posts() ) { | |
| 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() ) { | |
| 26 | 55 | the_post(); |
| 27 | 56 | learn_press_get_template( 'content-single-course' ); |
| 28 | -} | |
| 57 | +}*/ | |
| 29 | 58 | |
| 30 | 59 | /** |
| 31 | 60 | * @since 3.0.0 |
| 32 | 61 | */ |
| @@ -40,7 +69,7 @@ | ||
| 40 | 69 | |
| 41 | 70 | /** |
| 42 | 71 | * Footer for page |
| 43 | 72 | */ |
| 44 | -if ( empty( $is_block_theme ) ) { | |
| 45 | - get_footer( 'course' ); | |
| 73 | +if ( ! wp_is_block_theme() ) { | |
| 74 | + do_action( 'learn-press/template-footer' ); | |
| 46 | 75 | } |