PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7
4.4.8 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 All 139 releases
learnpress / inc / templates / abstract-template.php

abstract-template.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7, at inc/templates/abstract-template.php

273 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class LP_Template
5 *
6 * @since 3.3.0
7 */
8 class LP_Abstract_Template {
9
10 /**
11 * @var LP_Template
12 */
13 protected static $instance = null;
14
15 /**
16 * LP_Template constructor.
17 */
18 public function __construct() {
19 }
20
21 public function clearfix() {
22 learn_press_get_template( 'global/clearfix' );
23 }
24
25 public function callback( $template, $args = array() ) {
26 return array( new LP_Template_Callback( $template, $args ), 'callback' );
27 }
28
29 public function text( $text, $id = '' ) {
30 return array( new LP_Template_Callback( $text, $id ), 'text' );
31 }
32
33 public function __call( $name, $arguments ) {
34 $log = sprintf( 'Template %s::%s doesn\'t exists.', get_class( $this ), $name );
35 error_log( $log );
36
37 if ( LP_Debug::is_debug() ) {
38 echo sprintf( '<span title="%s" class="learn-press-template-warning"></span>', $log );
39 }
40 }
41
42 /**
43 * Return is callable method of self class.
44 *
45 * @since 3.3.0
46 *
47 * @param string $callback
48 *
49 * @return array
50 */
51 public function func( $callback ) {
52 return array( $this, $callback );
53 }
54
55 /**
56 * Add callable method of self class to a hook of template.
57 *
58 * @param string $name
59 * @param string $callback
60 * @param int $priority
61 * @param int $number_args
62 */
63 public function hook( $name, $callback, $priority = 10, $number_args = 1 ) {
64 add_action( $name, $this->func( $callback ), $priority, $number_args );
65 }
66
67 /**
68 * Remove hooked callable method.
69 *
70 * @param string $tag
71 * @param string $function_to_remove - '*' will remove all methods.
72 * @param int $priority
73 *
74 * Ex: Remove for text: LP()->template( 'course' )->remove( 'learn-press/course-content-summary', array( '<div class="course-detail-info"> <div class="lp-content-area"> <div class="course-info-left">', 'course-info-left-open' ), 10 );
75 */
76 public function remove( $tag, $function_to_remove, $priority = 10 ) {
77 global $wp_filter;
78
79 if ( is_array( $function_to_remove ) ) {
80 if ( empty( $wp_filter[ $tag ] ) ) {
81 return;
82 }
83
84 $callbacks = $wp_filter[ $tag ]->callbacks;
85 if ( ! $callbacks ) {
86 return;
87 }
88
89 $priorities = array_keys( $callbacks );
90
91 foreach ( $priorities as $priority1 ) {
92
93 if ( $priority !== '*' && $priority !== $priority1 ) {
94 continue;
95 }
96
97 if ( empty( $callbacks[ $priority1 ] ) ) {
98 continue;
99 }
100
101 foreach ( $callbacks[ $priority1 ] as $callback ) {
102
103 if ( ! $callback['function'][0] instanceof LP_Template_Callback ) {
104 continue;
105 }
106
107 if ( $callback['function'][0]->get_args() !== $function_to_remove[1] ) {
108 continue;
109 }
110
111 remove_action( $tag, $callback['function'], $priority1 );
112 }
113 }
114
115 return;
116
117 }
118
119 /**
120 * $function_to_remove === '*' will remove all functions hooked into a hook
121 * in all priorities
122 */
123 if ( $function_to_remove === '*' ) {
124 if ( ! empty( $wp_filter[ $tag ] ) ) {
125 unset( $wp_filter[ $tag ] );
126 }
127
128 return;
129 }
130
131 /**
132 * $priority === '*' will remove all functions hooked into a hook
133 * in
134 */
135 if ( $priority === '*' ) {
136
137 if ( ! empty( $wp_filter[ $tag ]->callbacks ) ) {
138 $priorities = array_keys( $wp_filter[ $tag ]->callbacks );
139
140 foreach ( $priorities as $priority ) {
141 remove_action( $tag, $this->func( $function_to_remove ), $priority );
142 }
143 }
144
145 return;
146 }
147 remove_action( $tag, $this->func( $function_to_remove ), $priority );
148 }
149
150 /**
151 * Remove callback function.
152 *
153 * @param [type] $tag
154 * @param [type] $function
155 * @param [type] $priority
156 * @return void
157 *
158 * @author Nhamdv <email@email.com>
159 *
160 * Ex: LP()->template( 'course' )->remove_callback( 'learn-press/course-content-summary', 'single-course/title', 10 );
161 *
162 */
163 public static function remove_callback( $tag, $function, $priority ) {
164 global $wp_filter;
165
166 if ( empty( $wp_filter[ $tag ] ) ) {
167 return;
168 }
169
170 $callbacks = $wp_filter[ $tag ]->callbacks;
171
172 if ( ! $callbacks ) {
173 return;
174 }
175
176 $priorities = array_keys( $callbacks );
177
178 foreach ( $priorities as $priority1 ) {
179
180 if ( $priority !== '*' && $priority !== $priority1 ) {
181 continue;
182 }
183
184 if ( empty( $callbacks[ $priority1 ] ) ) {
185 continue;
186 }
187
188 foreach ( $callbacks[ $priority1 ] as $callback ) {
189
190 if ( ! $callback['function'][0] instanceof LP_Template_Callback ) {
191 continue;
192 }
193
194 if ( $callback['function'][1] !== 'callback' ) {
195 continue;
196 }
197
198 if ( $callback['function'][0]->get_template() !== $function ) {
199 continue;
200 }
201
202 remove_action( $tag, $callback['function'], $priority1 );
203 }
204 }
205
206 return;
207 }
208
209 /**
210 * @return LP_Template
211 */
212 public static function instance() {
213 if ( ! self::$instance ) {
214 self::$instance = new self();
215 }
216
217 return self::$instance;
218 }
219 }
220
221
222 class LP_Template_Callback {
223 /**
224 * @var string
225 */
226 protected $template = '';
227
228 /**
229 * @var array
230 */
231 protected $args = array();
232
233 /**
234 * LP_Template_Caller constructor.
235 *
236 * @param $template
237 * @param array $args
238 */
239 public function __construct( $template, $args = array() ) {
240 $this->template = $template;
241 $this->args = $args;
242 }
243
244 /**
245 *
246 */
247 public function callback() {
248 $template_args = array();
249
250 if ( $this->args ) {
251 foreach ( $this->args as $k => $v ) {
252 if ( is_numeric( $k ) && is_string( $v ) ) {
253 $template_args[ $v ] = func_get_arg( $k );
254 }
255 }
256 }
257
258 learn_press_get_template( $this->template, $template_args );
259 }
260
261 public function text() {
262 learn_press_echo_vuejs_write_on_php( $this->template );
263 }
264
265 public function get_args() {
266 return $this->args;
267 }
268
269 public function get_template() {
270 return $this->template;
271 }
272 }
273