PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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 / admin / settings / class-lp-settings-addons.php

class-lp-settings-addons.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.8, at inc/admin/settings/class-lp-settings-addons.php

96 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class LP_Settings_Addons
4 *
5 * @author ThimPress
6 * @package LearnPress/Admin/Classes/Settings
7 * @version 1.0.0
8 */
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Shared settings tab for LearnPress add-ons.
14 */
15 class LP_Settings_Addons extends LP_Abstract_Settings_Page {
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->id = 'addons';
21 $this->text = esc_html__( 'Addons', 'learnpress' );
22
23 parent::__construct();
24
25 add_filter( 'learn-press/admin/submenu-has-sections', array( $this, 'force_section_nav' ), 10, 3 );
26 }
27
28 /**
29 * Always show the section navigation for the Addons tab, even with a single
30 * add-on section, so each add-on reads as a distinct section like Payments.
31 *
32 * @param bool $has_sections Current decision (>1 section).
33 * @param array<string, mixed> $sections Sections for the active tab.
34 * @param string $active_tab Active settings tab id.
35 *
36 * @return bool
37 */
38 public function force_section_nav( $has_sections, $sections, $active_tab ) {
39 if ( $this->id === $active_tab && ! empty( $sections ) ) {
40 return true;
41 }
42
43 return $has_sections;
44 }
45
46 /**
47 * Sections contributed by active add-ons.
48 *
49 * @return array<string, string>
50 */
51 public function get_sections() {
52 $sections = apply_filters( 'learn-press/settings/addons/sections', array() );
53
54 return is_array( $sections ) ? $sections : array();
55 }
56
57 /**
58 * Whether any add-on registered a settings section.
59 *
60 * @return bool
61 */
62 public function has_sections(): bool {
63 return ! empty( $this->get_sections() );
64 }
65
66 /**
67 * Field dispatch via add-on filters.
68 *
69 * @param string|array $section Section key or keys.
70 * @param string $tab Tab key.
71 *
72 * @return array<int, array<string, mixed>>
73 */
74 public function get_settings( $section = '', $tab = '' ) {
75 if ( ! $section ) {
76 $section = array_keys( $this->get_sections() );
77 }
78
79 settype( $section, 'array' );
80
81 $return = array();
82
83 foreach ( $section as $sec ) {
84 $fields = apply_filters( "learn-press/settings/addons/fields-{$sec}", array() );
85
86 if ( $fields && is_array( $fields ) ) {
87 $return = array_merge( $return, $fields );
88 }
89 }
90
91 return $return;
92 }
93 }
94
95 return new LP_Settings_Addons();
96