PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.2.0
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.2.0
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / Helper / Template.php

Template.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.2.0, at inc/Helper/Template.php

119 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace LearnPress\Helpers;
4
5 /**
6 * Class Template
7 *
8 * @package LearnPress\Helpers
9 * @since 1.0.0
10 * @version 1.0.1
11 */
12 class Template {
13 /**
14 * @var bool
15 */
16 protected $include;
17
18 protected function __construct() {
19
20 }
21
22 /**
23 * Set 1 for include file, 0 for not
24 * Set 1 for separate template is block, 0 for not | use "wp_is_block_theme" function
25 *
26 * @param bool $include
27 *
28 * @return self
29 */
30 public static function instance( bool $include = true ): Template {
31 $self = new self();
32 $self->include = $include;
33
34 return $self;
35 }
36
37 /**
38 * Get template admin file
39 *
40 * @param string $file_name
41 * @param array $args
42 *
43 * @return void|string
44 * @since 1.0.0
45 * @version 1.0.0
46 */
47 public function get_admin_template( string $file_name = '', array $args = array() ) {
48 $file_name = str_replace( '.php', '', $file_name );
49 $path_file = LP_PLUGIN_PATH . "inc/admin/views/{$file_name}.php";
50
51 $template = $this->get_template( $path_file, $args );
52
53 if ( ! $this->include ) {
54 return $template;
55 }
56 }
57
58 /**
59 * Get template frontend file
60 *
61 * @param string $file_name
62 * @param array $args
63 *
64 * @return void|string
65 * @since 1.0.0
66 * @version 1.0.0
67 */
68 public function get_frontend_template( string $file_name = '', array $args = array() ) {
69 $default_path = LP_PLUGIN_PATH . "templates/{$file_name}";
70 $folder_name_rewrite = learn_press_template_path();
71 $from_theme_path = sprintf(
72 '%s/%s/%s',
73 get_template_directory(),
74 $folder_name_rewrite,
75 $file_name
76 );
77 $path_load = file_exists( $from_theme_path ) ? $from_theme_path : $default_path;
78 $template = $this->get_template( $path_load, $args );
79 if ( ! $this->include ) {
80 return $template;
81 }
82 }
83
84 /**
85 * Include path file
86 *
87 * @param string $path_file
88 * @param array $args
89 *
90 * @return string|void
91 * @since 1.0.0
92 * @version 1.0.0
93 */
94 public function get_template( string $path_file, array $args = array() ) {
95 try {
96 extract( $args );
97
98 // Check path file not extension, will add extension .php
99 if ( ! preg_match( '/\.php$/', $path_file ) ) {
100 $path_file .= '.php';
101 }
102
103 if ( realpath( $path_file ) ) {
104 if ( $this->include ) {
105 include $path_file;
106 } else {
107 return $path_file;
108 }
109 } else {
110 printf( esc_html__( 'Path file %s not exists', 'realpress' ), $path_file );
111 echo '<br>';
112 }
113 } catch ( \Throwable $e ) {
114 error_log( $e->getMessage() );
115 }
116 }
117 }
118
119