Skip to content

Commit

Permalink
= 4.2.0 =
Browse files Browse the repository at this point in the history
~ Modified: method "list_courses", change how call the template.
  • Loading branch information
tungnxt89 committed Dec 14, 2022
1 parent af00d29 commit 7b88ef2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 63 deletions.
61 changes: 3 additions & 58 deletions inc/Helper/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @package LearnPress\Helpers
* @since 1.0.0
* @version 1.0.0
* @version 1.0.1
*/
class Template {
/**
Expand Down Expand Up @@ -67,7 +67,7 @@ public function get_admin_template( string $file_name = '', array $args = array(
*/
public function get_frontend_template( string $file_name = '', array $args = array() ) {
$default_path = LP_PLUGIN_PATH . "templates/{$file_name}";
$folder_name_rewrite = apply_filters( 'learn-press/folder-name-override', LP_PLUGIN_FOLDER_NAME );
$folder_name_rewrite = apply_filters( 'learn_press_template_path', LP_PLUGIN_FOLDER_NAME );

$from_theme_path = get_template_directory() . DIRECTORY_SEPARATOR . $folder_name_rewrite . DIRECTORY_SEPARATOR . $file_name;
$path_load = file_exists( $from_theme_path ) ? $from_theme_path : $default_path;
Expand All @@ -79,61 +79,6 @@ public function get_frontend_template( string $file_name = '', array $args = arr
}
}

/**
* Get frontend template block file
*
* @param string $file_name
* @param array $args
*
* @return string|void
*/
public function get_frontend_template_type_block( string $file_name = '', array $args = array() ) {
$file_name = "block/{$file_name}";
$template = $this->get_frontend_template( $file_name, $args );

if ( ! $this->include ) {
return $template;
}
}

/**
* Get frontend template file
*
* @param string $file_name
* @param array $args
*
* @return string|void
*/
public function get_frontend_template_type_classic( string $file_name = '', array $args = array() ) {
$file_name = "classic/{$file_name}";
$template = $this->get_frontend_template( $file_name, $args );

if ( ! $this->include ) {
return $template;
}
}

/**
* Get frontend group template files
*
* @param array $file_names
* @param array $args
*
* @return void
* @version 1.0.0
* @since 1.0.1
*/
public function get_frontend_templates_type_classic( array $file_names = array(), array $args = array() ) {
foreach ( $file_names as $file_name ) {
$search_extension = strrpos( $file_name, '.php' );
if ( ! $search_extension ) {
$file_name .= '.php';
}

$this->get_frontend_template_type_classic( $file_name, $args );
}
}

/**
* Include path file
*
Expand All @@ -144,7 +89,7 @@ public function get_frontend_templates_type_classic( array $file_names = array()
* @since 1.0.0
* @version 1.0.0
*/
protected function get_template( string $path_file, array $args = array() ) {
public function get_template( string $path_file, array $args = array() ) {
extract( $args );
if ( file_exists( $path_file ) ) {
if ( $this->include ) {
Expand Down
9 changes: 4 additions & 5 deletions inc/rest-api/v1/frontend/class-lp-rest-courses-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,15 @@ public function list_courses( WP_REST_Request $request ): LP_REST_Response {
);
// End Pagination

// For custom template return all list courses no foreach
$template_path = sanitize_file_name( apply_filters( 'lp/api/courses/template', '' ) );
// For custom template
$template_path = apply_filters( 'lp/api/courses/template', '' );
if ( ! empty( $template_path ) ) {
Template::instance()->get_frontend_template( $template_path, compact( 'courses', 'total_pages' ) );
Template::instance()->get_template( $template_path, compact( 'courses', 'total_pages' ) );
} else {
// Todo: tungnx - should rewrite call template
foreach ( $courses as $course ) {
$post = get_post( $course->ID );
setup_postdata( $post );
learn_press_get_template_part( 'content', 'course' );
Template::instance()->get_frontend_template( 'content-course.php' );
}

wp_reset_postdata();
Expand Down

0 comments on commit 7b88ef2

Please sign in to comment.