PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 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 All 140 releases
← All changes | inc/admin/sub-menus/abstract-submenu.php +503 -481 4.1.7 → 4.4.9 View file →
@@ -1,481 +1,503 @@
1 -<?php
2 -defined( 'ABSPATH' ) || exit();
3 -
4 -/**
5 - * Class LP_Abstract_Submenu
6 - *
7 - * @since 3.0.0
8 - */
9 -abstract class LP_Abstract_Submenu {
10 - /**
11 - * Menu slug
12 - *
13 - * @var string
14 - */
15 - protected $id = '';
16 -
17 - /**
18 - * Menu title
19 - *
20 - * @var string
21 - */
22 - protected $menu_title = '';
23 -
24 - /**
25 - * Page title
26 - *
27 - * @var string
28 - */
29 - protected $page_title = '';
30 -
31 - /**
32 - * Priority
33 - *
34 - * @var int
35 - */
36 - protected $priority = 10;
37 -
38 - /**
39 - * Capability
40 - *
41 - * @var string
42 - */
43 - protected $capability = 'manage_options';
44 -
45 - /**
46 - * Menu icon
47 - *
48 - * @var string
49 - */
50 - protected $icon = '';
51 -
52 - /**
53 - * Callback (may not be used)
54 - *
55 - * @var bool
56 - */
57 - protected $callback = false;
58 -
59 - /**
60 - * Heading tabs
61 - *
62 - * @var array
63 - */
64 - protected $tabs = array();
65 -
66 - /**
67 - * Tab's sections
68 - *
69 - * @var array
70 - */
71 - protected $sections = array();
72 -
73 - /**
74 - * Current page
75 - *
76 - * @var bool
77 - */
78 - protected $page = false;
79 -
80 - /**
81 - * LP_Abstract_Submenu constructor.
82 - */
83 - public function __construct() {
84 - add_action( 'learn-press/admin/page-content-sections', array( $this, 'output_section_nav' ) );
85 - add_filter( 'admin_body_class', array( $this, 'body_class' ) );
86 -
87 - if ( $this->is_displaying() ) {
88 - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
89 - }
90 - }
91 -
92 - public function enqueue_assets() {
93 - }
94 -
95 - public function is_displaying() {
96 - return $this->get_id() === LP_Request::get_string( 'page' );
97 - }
98 -
99 - /**
100 - * @return string
101 - */
102 - public function get_id() {
103 - return $this->id;
104 - }
105 -
106 - /**
107 - * @param string $id
108 - */
109 - public function set_id( $id ) {
110 - $this->id = $id;
111 - }
112 -
113 - /**
114 - * @return string
115 - */
116 - public function get_menu_title() {
117 - return $this->menu_title;
118 - }
119 -
120 - /**
121 - * @param string $menu_title
122 - */
123 - public function set_menu_title( $menu_title ) {
124 - $this->menu_title = $menu_title;
125 - }
126 -
127 - /**
128 - * @return string
129 - */
130 - public function get_page_title() {
131 - return $this->page_title;
132 - }
133 -
134 - /**
135 - * @param string $page_title
136 - */
137 - public function set_page_title( $page_title ) {
138 - $this->page_title = $page_title;
139 - }
140 -
141 - /**
142 - * @return int|string
143 - */
144 - public function get_priority() {
145 - return $this->priority;
146 - }
147 -
148 - /**
149 - * @param string|int $priority
150 - */
151 - public function set_priority( $priority ) {
152 - $this->priority = $priority;
153 - }
154 -
155 - /**
156 - * @return string
157 - */
158 - public function get_capability() {
159 - return $this->capability;
160 - }
161 -
162 - /**
163 - * @param string $capability
164 - */
165 - public function set_capability( $capability ) {
166 - $this->capability = $capability;
167 - }
168 -
169 - /**
170 - * @return string
171 - */
172 - public function get_icon() {
173 - return $this->icon;
174 - }
175 -
176 - /**
177 - * @param string $icon
178 - */
179 - public function set_icon( $icon ) {
180 - $this->icon = $icon;
181 - }
182 -
183 - /**
184 - * Get heading tabs.
185 - *
186 - * @return mixed|array
187 - */
188 - public function get_tabs() {
189 - return apply_filters( 'learn-press/submenu-' . $this->get_id() . '-heading-tabs', $this->sanitize_tabs( $this->tabs ) );
190 - }
191 -
192 - /**
193 - * Sanitize the tabs.
194 - *
195 - * @param $tabs
196 - *
197 - * @return array
198 - */
199 - public function sanitize_tabs( $tabs ) {
200 - $sanitized_tabs = array();
201 - if ( $tabs ) {
202 - foreach ( $tabs as $tab => $name ) {
203 - // Maybe a tab is name of a class? Try to locate it.
204 - if ( is_string( $name ) && class_exists( $name ) ) {
205 - $objSettings = new $name();
206 - $sanitized_tabs[ $objSettings->id ] = $objSettings;
207 - } else {
208 - $sanitized_tabs[ $tab ] = $name;
209 - }
210 - }
211 - }
212 -
213 - return $sanitized_tabs;
214 - }
215 -
216 - /**
217 - * Get active tab by checking ?tab=tab-name
218 - *
219 - * @return bool|mixed
220 - */
221 - public function get_active_tab() {
222 - $tabs = $this->get_tabs();
223 - if ( ! $tabs ) {
224 - return false;
225 - }
226 - $tab = LP_Helper::sanitize_params_submitted( $_REQUEST['tab'] ?? '' );
227 - if ( empty( $tab ) || empty( $tabs[ $tab ] ) ) {
228 - $tab_keys = array_keys( $tabs );
229 - $tab = reset( $tab_keys );
230 - }
231 -
232 - return $tab;
233 - }
234 -
235 - /**
236 - * @return array|mixed
237 - */
238 - public function has_tabs() {
239 - return $this->get_tabs();
240 - }
241 -
242 - /**
243 - * @return mixed
244 - */
245 - public function get_sections() {
246 - $active_tab = $this->get_active_tab();
247 -
248 - if ( ! empty( $this->tabs[ $active_tab ] ) ) {
249 - if ( is_callable( array( $this->tabs[ $active_tab ], 'get_sections' ) ) ) {
250 - $this->sections = call_user_func( array( $this->tabs[ $active_tab ], 'get_sections' ) );
251 - }
252 - }
253 -
254 - return apply_filters( 'learn-press/submenu-sections', $this->sections );
255 - }
256 -
257 - /**
258 - * Get current page is displaying.
259 - *
260 - * @param bool $prefix
261 - *
262 - * @return bool|mixed|null
263 - */
264 - public function get_active_page( $prefix = true ) {
265 - if ( false === $this->page ) {
266 - $this->page = ! empty( $_REQUEST['page'] ) ? sanitize_text_field( $_REQUEST['page'] ) : null;
267 - }
268 -
269 - return $prefix ? $this->page : str_replace( 'learn-press-', '', $this->page );
270 - }
271 -
272 - /**
273 - * Get active section by checking ?section=tab-name
274 - *
275 - * @return bool|mixed
276 - */
277 - public function get_active_section() {
278 - $sections = $this->get_sections();
279 -
280 - if ( ! $sections ) {
281 - return false;
282 - }
283 -
284 - $section = LP_Helper::sanitize_params_submitted( $_REQUEST['section'] ?? '' );
285 - if ( empty( $section ) || empty( $sections[ $section ] ) ) {
286 - $section_keys = array_keys( $sections );
287 - $section = reset( $section_keys );
288 - }
289 -
290 - return $section;
291 - }
292 -
293 - /**
294 - * Display menu content
295 - */
296 - public function display() {
297 - $tabs = $this->get_tabs();
298 - $active_tab = $this->get_active_tab();
299 - $classes = array( 'wrap', 'lp-submenu-page', $this->get_id() );
300 - ?>
301 -
302 - <div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
303 - <?php do_action( 'learn-press/admin/heading-icon', $active_tab ); ?>
304 -
305 - <h1 class="wp-heading-inline">
306 - <?php echo wp_kses_post( $this->get_menu_title() ); ?>
307 - <?php do_action( 'learn-press/admin/heading-title', $active_tab ); ?>
308 - </h1>
309 -
310 - <?php if ( $tabs ) { ?>
311 - <h2 class="nav-tab-wrapper">
312 - <?php foreach ( $tabs as $tab => $name ) { ?>
313 - <?php
314 - $obj_tab = false;
315 -
316 - if ( is_object( $name ) ) {
317 - $obj_tab = $name;
318 - $name = $obj_tab->text;
319 - $tab = $obj_tab->id;
320 - }
321 -
322 - $active_class = ( $tab == $active_tab ) ? ' nav-tab-active' : '';
323 - $tab_title = apply_filters( 'learn-press/admin/submenu-heading-tab-title', $name, $tab );
324 - ?>
325 -
326 - <?php if ( $active_class ) { ?>
327 - <span class="nav-tab<?php echo esc_attr( $active_class ); ?>"><?php echo esc_html( $tab_title ); ?></span>
328 - <?php } else { ?>
329 - <a class="nav-tab" href="?page=<?php echo esc_attr( $this->id ); ?>&tab=<?php echo esc_attr( $tab ); ?>"><?php echo esc_html( $tab_title ); ?></a>
330 - <?php } ?>
331 - <?php } ?>
332 - </h2>
333 - <?php } ?>
334 -
335 - <?php
336 - $classes = array( 'lp-admin-tabs' );
337 - $sections = $this->get_sections();
338 -
339 - if ( $sections && sizeof( $sections ) > 1 ) {
340 - $classes[] = 'has-sections';
341 - }
342 - ?>
343 -
344 - <form class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>" method="post" enctype="multipart/form-data">
345 - <?php $this->page_content(); ?>
346 - </form>
347 - </div>
348 - <?php
349 - }
350 -
351 - /**
352 - * This function for displaying content of active tab only.
353 - * For displaying content of main page without tab,
354 - * overwrite this function in sub class.
355 - */
356 - public function page_content() {
357 - do_action( 'learn-press/admin/page-content-sections', $this );
358 -
359 - echo '<div class="lp-admin-tab-content">';
360 -
361 - if ( $this->has_tabs() ) {
362 - $page = $this->_get_page();
363 - $tab = $this->get_active_tab();
364 -
365 - do_action( 'learn-press/admin/before-page-content-sections', $page, $tab, $this );
366 -
367 - // If I have a function named 'page_content_TAB_SLUG' then call it.
368 - $callback = array( $this, sprintf( 'page_content_%s', $tab ) );
369 -
370 - if ( is_callable( $callback ) ) {
371 - call_user_func_array( $callback, array() );
372 - } else {
373 - do_action( 'learn-press/admin/page-content-' . $page, $tab );
374 - do_action( 'learn-press/admin/page-content-' . $page . '/' . $tab );
375 - }
376 -
377 - do_action( 'learn-press/admin/after-page-content-sections', $page, $tab, $this );
378 - }
379 -
380 - echo '</div>';
381 - }
382 -
383 - /**
384 - * Output section navigation.
385 - */
386 - public function output_section_nav() {
387 - if ( $this->id !== $this->get_active_page() ) {
388 - return;
389 - }
390 -
391 - $active_section = $this->get_active_section();
392 - $sections = $this->get_sections();
393 -
394 - if ( ! $sections ) {
395 - return;
396 - }
397 - ?>
398 -
399 - <ul class="lp-admin-tab-navs">
400 - <?php foreach ( $sections as $slug => $section ) { ?>
401 - <?php
402 - $active_class = ( $slug == $active_section ) ? ' nav-section-active' : '';
403 - $section_title = apply_filters( 'learn-press/admin/submenu-section-title', $section, $slug );
404 - ?>
405 -
406 - <li class="nav-section<?php echo esc_attr( $active_class ); ?>">
407 - <?php if ( $active_class ) { ?>
408 - <span><?php echo wp_kses_post( $section_title ); ?></span>
409 - <?php } else { ?>
410 - <a href="<?php echo esc_url_raw( remove_query_arg( 'sub-section', add_query_arg( 'section', $slug ) ) ); ?>"><?php echo wp_kses_post( $section_title ); ?></a>
411 - <?php } ?>
412 - </li>
413 - <?php } ?>
414 - </ul>
415 -
416 - <?php
417 - }
418 -
419 - /**
420 - * Display section content
421 - */
422 - public function display_section() {
423 - $section = $this->get_active_section();
424 -
425 - if ( ! $section ) {
426 - return false;
427 - }
428 -
429 - $section_class = $this->sections[ $section ];
430 -
431 - if ( ! $section_class ) {
432 - return false;
433 - }
434 -
435 - do_action( 'learn-press/admin/page-' . $this->_get_page() . '/section-content', $section );
436 -
437 - if ( is_callable( array( $this, 'section_content_' . $section ) ) ) {
438 - call_user_func( array( $this, 'section_content_' . $section ) );
439 - } else {
440 - do_action( 'learn-press/admin/page-' . $this->_get_page() . '/section-content-' . $section );
441 - }
442 -
443 - return true;
444 - }
445 -
446 - /**
447 - * Get this page id without prefix.
448 - *
449 - * @return mixed
450 - */
451 - protected function _get_page() {
452 - return str_replace( 'learn-press-', '', $this->get_id() );
453 - }
454 -
455 - /**
456 - * Append new class to body tag to control our page.
457 - *
458 - * @param $classes
459 - *
460 - * @return array|string
461 - */
462 - public function body_class( $classes ) {
463 - $page = $this->get_active_page( false );
464 -
465 - if ( $page ) {
466 - if ( $classes ) {
467 - $classes = explode( ' ', $classes );
468 - } else {
469 - $classes = array();
470 - }
471 -
472 - $classes[] = 'learnpress';
473 - $classes[] = 'lp-submenu-' . $page;
474 - $classes = array_filter( $classes );
475 - $classes = array_unique( $classes );
476 - $classes = join( ' ', $classes );
477 - }
478 -
479 - return $classes;
480 - }
481 -}
1 +<?php
2 +
3 +use LearnPress\Helpers\Template;
4 +
5 +defined( 'ABSPATH' ) || exit();
6 +
7 +/**
8 + * Class LP_Abstract_Submenu
9 + *
10 + * @since 3.0.0
11 + */
12 +abstract class LP_Abstract_Submenu {
13 + /**
14 + * Menu slug
15 + *
16 + * @var string
17 + */
18 + protected $id = '';
19 +
20 + /**
21 + * Menu title
22 + *
23 + * @var string
24 + */
25 + protected $menu_title = '';
26 +
27 + /**
28 + * Page title
29 + *
30 + * @var string
31 + */
32 + protected $page_title = '';
33 +
34 + /**
35 + * Priority
36 + *
37 + * @var int
38 + */
39 + protected $priority = 10;
40 +
41 + /**
42 + * Capability
43 + *
44 + * @var string
45 + */
46 + protected $capability = 'manage_options';
47 +
48 + /**
49 + * Menu icon
50 + *
51 + * @var string
52 + */
53 + protected $icon = '';
54 +
55 + /**
56 + * Callback (may not be used)
57 + *
58 + * @var bool
59 + */
60 + protected $callback = false;
61 +
62 + /**
63 + * Heading tabs
64 + *
65 + * @var array
66 + */
67 + protected $tabs = array();
68 +
69 + /**
70 + * Tab's sections
71 + *
72 + * @var array
73 + */
74 + protected $sections = array();
75 +
76 + /**
77 + * Current page
78 + *
79 + * @var bool
80 + */
81 + protected $page = false;
82 +
83 + /**
84 + * LP_Abstract_Submenu constructor.
85 + */
86 + public function __construct() {
87 + add_action( 'learn-press/admin/page-content-sections', array( $this, 'output_section_nav' ) );
88 + add_filter( 'admin_body_class', array( $this, 'body_class' ) );
89 +
90 + if ( $this->is_displaying() ) {
91 + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
92 + }
93 + }
94 +
95 + public function enqueue_assets() {
96 + }
97 +
98 + public function is_displaying() {
99 + return $this->get_id() === LP_Request::get_param( 'page' );
100 + }
101 +
102 + /**
103 + * @return string
104 + */
105 + public function get_id() {
106 + return $this->id;
107 + }
108 +
109 + /**
110 + * @param string $id
111 + */
112 + public function set_id( $id ) {
113 + $this->id = $id;
114 + }
115 +
116 + /**
117 + * @return string
118 + */
119 + public function get_menu_title() {
120 + return $this->menu_title;
121 + }
122 +
123 + /**
124 + * @param string $menu_title
125 + */
126 + public function set_menu_title( $menu_title ) {
127 + $this->menu_title = $menu_title;
128 + }
129 +
130 + /**
131 + * @return string
132 + */
133 + public function get_page_title() {
134 + return $this->page_title;
135 + }
136 +
137 + /**
138 + * @param string $page_title
139 + */
140 + public function set_page_title( $page_title ) {
141 + $this->page_title = $page_title;
142 + }
143 +
144 + /**
145 + * @return int|string
146 + */
147 + public function get_priority() {
148 + return $this->priority;
149 + }
150 +
151 + /**
152 + * @param string|int $priority
153 + */
154 + public function set_priority( $priority ) {
155 + $this->priority = $priority;
156 + }
157 +
158 + /**
159 + * @return string
160 + */
161 + public function get_capability() {
162 + return $this->capability;
163 + }
164 +
165 + /**
166 + * @param string $capability
167 + */
168 + public function set_capability( $capability ) {
169 + $this->capability = $capability;
170 + }
171 +
172 + /**
173 + * @return string
174 + */
175 + public function get_icon() {
176 + return $this->icon;
177 + }
178 +
179 + /**
180 + * @param string $icon
181 + */
182 + public function set_icon( $icon ) {
183 + $this->icon = $icon;
184 + }
185 +
186 + /**
187 + * Get heading tabs.
188 + *
189 + * @return mixed|array
190 + */
191 + public function get_tabs() {
192 + return apply_filters( 'learn-press/submenu-' . $this->get_id() . '-heading-tabs', $this->sanitize_tabs( $this->tabs ) );
193 + }
194 +
195 + /**
196 + * Sanitize the tabs.
197 + *
198 + * @param $tabs
199 + *
200 + * @return array
201 + */
202 + public function sanitize_tabs( $tabs ) {
203 + $sanitized_tabs = array();
204 + if ( $tabs ) {
205 + foreach ( $tabs as $tab => $name ) {
206 + // Maybe a tab is name of a class? Try to locate it.
207 + if ( is_string( $name ) && class_exists( $name ) ) {
208 + $objSettings = new $name();
209 + $sanitized_tabs[ $objSettings->id ] = $objSettings;
210 + } else {
211 + $sanitized_tabs[ $tab ] = $name;
212 + }
213 + }
214 + }
215 +
216 + return $sanitized_tabs;
217 + }
218 +
219 + /**
220 + * Get active tab by checking ?tab=tab-name
221 + *
222 + * @return bool|mixed
223 + */
224 + public function get_active_tab() {
225 + $tabs = $this->get_tabs();
226 + if ( ! $tabs ) {
227 + return false;
228 + }
229 + $tab = LP_Helper::sanitize_params_submitted( $_REQUEST['tab'] ?? '' );
230 + if ( empty( $tab ) || empty( $tabs[ $tab ] ) ) {
231 + $tab_keys = array_keys( $tabs );
232 + $tab = reset( $tab_keys );
233 + }
234 +
235 + return $tab;
236 + }
237 +
238 + /**
239 + * @return array|mixed
240 + */
241 + public function has_tabs() {
242 + return $this->get_tabs();
243 + }
244 +
245 + /**
246 + * @return mixed
247 + */
248 + public function get_sections() {
249 + $active_tab = $this->get_active_tab();
250 +
251 + if ( ! empty( $this->tabs[ $active_tab ] ) ) {
252 + if ( is_callable( array( $this->tabs[ $active_tab ], 'get_sections' ) ) ) {
253 + $this->sections = call_user_func( array( $this->tabs[ $active_tab ], 'get_sections' ) );
254 + }
255 + }
256 +
257 + return apply_filters( 'learn-press/submenu-sections', $this->sections );
258 + }
259 +
260 + /**
261 + * Get current page is displaying.
262 + *
263 + * @param bool $prefix
264 + *
265 + * @return bool|mixed|null
266 + */
267 + public function get_active_page( $prefix = true ) {
268 + if ( false === $this->page ) {
269 + $this->page = LP_Request::get_param( 'page' );
270 + }
271 +
272 + return $prefix ? $this->page : str_replace( 'learn-press-', '', $this->page );
273 + }
274 +
275 + /**
276 + * Get active section by checking ?section=tab-name
277 + *
278 + * @return bool|mixed
279 + */
280 + public function get_active_section() {
281 + $sections = $this->get_sections();
282 +
283 + if ( ! $sections ) {
284 + return false;
285 + }
286 +
287 + $section = LP_Helper::sanitize_params_submitted( $_REQUEST['section'] ?? '' );
288 + if ( empty( $section ) || empty( $sections[ $section ] ) ) {
289 + $section_keys = array_keys( $sections );
290 + $section = reset( $section_keys );
291 + }
292 +
293 + return $section;
294 + }
295 +
296 + /**
297 + * Callback return template.
298 + *
299 + * @return bool|array|mixed
300 + */
301 + public function get_callback() {
302 + return $this->callback;
303 + }
304 +
305 + /**
306 + * Display menu content
307 + */
308 + public function display() {
309 + $tabs = $this->get_tabs();
310 + $active_tab = $this->get_active_tab();
311 + $classes = array( 'wrap', 'lp-submenu-page', $this->get_id() );
312 + ?>
313 +
314 + <div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
315 + <?php do_action( 'learn-press/admin/heading-icon', $active_tab ); ?>
316 +
317 + <h1 class="wp-heading-inline">
318 + <?php echo wp_kses_post( $this->get_menu_title() ); ?>
319 + <?php do_action( 'learn-press/admin/heading-title', $active_tab ); ?>
320 + </h1>
321 +
322 + <?php if ( $tabs ) { ?>
323 + <h2 class="nav-tab-wrapper">
324 + <?php foreach ( $tabs as $tab => $name ) { ?>
325 + <?php
326 + $obj_tab = false;
327 +
328 + if ( is_object( $name ) ) {
329 + $obj_tab = $name;
330 + $name = $obj_tab->text;
331 + $tab = $obj_tab->id;
332 + }
333 +
334 + $active_class = ( $tab == $active_tab ) ? ' nav-tab-active' : '';
335 + $tab_title = apply_filters( 'learn-press/admin/submenu-heading-tab-title', $name, $tab );
336 + ?>
337 +
338 + <?php if ( $active_class ) { ?>
339 + <span class="nav-tab<?php echo esc_attr( $active_class ); ?>"><?php echo esc_html( $tab_title ); ?></span>
340 + <?php } else { ?>
341 + <a class="nav-tab" href="?page=<?php echo esc_attr( $this->id ); ?>&tab=<?php echo esc_attr( $tab ); ?>"><?php echo esc_html( $tab_title ); ?></a>
342 + <?php } ?>
343 + <?php } ?>
344 + </h2>
345 + <?php } ?>
346 +
347 + <?php
348 + $classes = array( 'lp-admin-tabs' );
349 + $sections = $this->get_sections();
350 +
351 + $has_sections = $sections && sizeof( $sections ) > 1;
352 + $has_sections = apply_filters( 'learn-press/admin/submenu-has-sections', $has_sections, $sections, $active_tab, $this );
353 +
354 + if ( $has_sections ) {
355 + $classes[] = 'has-sections';
356 + }
357 +
358 + ob_start();
359 + $this->page_content();
360 + $content = ob_get_clean();
361 + if ( 'learn-press-settings' === LP_Request::get_param( 'page' ) ) {
362 + $wrapper = [ sprintf( '<form class="%s" method="post" enctype="multipart/form-data">', esc_attr( implode( ' ', $classes ) ) ) => '</form>' ];
363 + } else {
364 + $wrapper = [ sprintf( '<div class="%s">', esc_attr( implode( ' ', $classes ) ) ) => '</div>' ];
365 + }
366 +
367 + echo Template::instance()->nest_elements( $wrapper, $content );
368 + ?>
369 + </div>
370 + <?php
371 + }
372 +
373 + /**
374 + * This function for displaying content of active tab only.
375 + * For displaying content of main page without tab,
376 + * overwrite this function in subclass.
377 + */
378 + public function page_content() {
379 + do_action( 'learn-press/admin/page-content-sections', $this );
380 +
381 + echo '<div class="lp-admin-tab-content">';
382 +
383 + if ( $this->has_tabs() ) {
384 + $page = $this->_get_page();
385 + $tab = $this->get_active_tab();
386 +
387 + do_action( 'learn-press/admin/before-page-content-sections', $page, $tab, $this );
388 +
389 + // If I have a function named 'page_content_TAB_SLUG' then call it.
390 + $callback = array( $this, sprintf( 'page_content_%s', $tab ) );
391 +
392 + if ( is_callable( $callback ) ) {
393 + call_user_func_array( $callback, array() );
394 + } else {
395 + do_action( 'learn-press/admin/page-content-' . $page, $tab );
396 + do_action( 'learn-press/admin/page-content-' . $page . '/' . $tab );
397 + }
398 +
399 + do_action( 'learn-press/admin/after-page-content-sections', $page, $tab, $this );
400 + }
401 +
402 + echo '</div>';
403 + }
404 +
405 + /**
406 + * Output section navigation.
407 + */
408 + public function output_section_nav() {
409 + if ( $this->id !== $this->get_active_page() ) {
410 + return;
411 + }
412 +
413 + $active_section = $this->get_active_section();
414 + $sections = $this->get_sections();
415 +
416 + if ( ! $sections ) {
417 + return;
418 + }
419 + ?>
420 +
421 + <ul class="lp-admin-tab-navs">
422 + <?php foreach ( $sections as $slug => $section ) { ?>
423 + <?php
424 + $active_class = ( $slug == $active_section ) ? ' nav-section-active' : '';
425 + $section_title = apply_filters( 'learn-press/admin/submenu-section-title', $section, $slug );
426 + ?>
427 +
428 + <li class="nav-section<?php echo esc_attr( $active_class ); ?>">
429 + <?php if ( $active_class ) { ?>
430 + <span><?php echo wp_kses_post( $section_title ); ?></span>
431 + <?php } else { ?>
432 + <a href="<?php echo esc_url_raw( remove_query_arg( 'sub-section', add_query_arg( 'section', $slug ) ) ); ?>"><?php echo wp_kses_post( $section_title ); ?></a>
433 + <?php } ?>
434 + </li>
435 + <?php } ?>
436 + </ul>
437 +
438 + <?php
439 + }
440 +
441 + /**
442 + * Display section content
443 + */
444 + public function display_section() {
445 + $section = $this->get_active_section();
446 +
447 + if ( ! $section ) {
448 + return false;
449 + }
450 +
451 + $section_class = $this->sections[ $section ];
452 +
453 + if ( ! $section_class ) {
454 + return false;
455 + }
456 +
457 + do_action( 'learn-press/admin/page-' . $this->_get_page() . '/section-content', $section );
458 +
459 + if ( is_callable( array( $this, 'section_content_' . $section ) ) ) {
460 + call_user_func( array( $this, 'section_content_' . $section ) );
461 + } else {
462 + do_action( 'learn-press/admin/page-' . $this->_get_page() . '/section-content-' . $section );
463 + }
464 +
465 + return true;
466 + }
467 +
468 + /**
469 + * Get this page id without prefix.
470 + *
471 + * @return mixed
472 + */
473 + protected function _get_page() {
474 + return str_replace( 'learn-press-', '', $this->get_id() );
475 + }
476 +
477 + /**
478 + * Append new class to body tag to control our page.
479 + *
480 + * @param $classes
481 + *
482 + * @return array|string
483 + */
484 + public function body_class( $classes ) {
485 + $page = $this->get_active_page( false );
486 +
487 + if ( $page ) {
488 + if ( $classes ) {
489 + $classes = explode( ' ', $classes );
490 + } else {
491 + $classes = array();
492 + }
493 +
494 + $classes[] = 'learnpress';
495 + $classes[] = 'lp-submenu-' . $page;
496 + $classes = array_filter( $classes );
497 + $classes = array_unique( $classes );
498 + $classes = join( ' ', $classes );
499 + }
500 +
501 + return $classes;
502 + }
503 +}