forked from gambitph/Titan-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-admin-tab.php
61 lines (47 loc) · 1.75 KB
/
class-admin-tab.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class TitanFrameworkAdminTab {
private $defaultSettings = array(
'name' => '', // Name of the tab
'id' => '', // Unique ID of the tab
'title' => '', // Title to display in the admin panel when tab is active
);
public $options = array();
public $settings;
public $owner;
function __construct( $settings, $owner ) {
$this->owner = $owner;
$this->settings = array_merge( $this->defaultSettings, $settings );
if ( empty( $this->settings['title'] ) && ! empty( $this->settings['name'] ) ) {
$this->settings['title'] = $this->settings['name'];
}
if ( ! empty( $this->settings['title'] ) && empty( $this->settings['name'] ) ) {
$this->settings['name'] = $this->settings['title'];
}
if ( empty( $this->settings['id'] ) ) {
$this->settings['id'] = str_replace( ' ', '-', trim( strtolower( $this->settings['name'] ) ) );
}
}
public function isActiveTab() {
return $this->settings['id'] == $this->owner->getActiveTab()->settings['id'];
}
public function createOption( $settings ) {
if ( ! apply_filters( 'tf_create_option_continue_' . $this->owner->owner->optionNamespace, true, $settings ) ) {
return null;
}
$obj = TitanFrameworkOption::factory( $settings, $this );
$this->options[] = $obj;
do_action( 'tf_create_option_' . $this->owner->owner->optionNamespace, $obj );
return $obj;
}
public function displayTab() {
?>
<a href="?page=<?php echo $this->owner->settings['id'] ?>&tab=<?php echo $this->settings['id'] ?>" class="nav-tab <?php echo $this->isActiveTab() ? "nav-tab-active" : '' ?>"><?php echo $this->settings['name'] ?></a>
<?php
}
public function displayOptions() {
foreach ( $this->options as $option ) {
$option->display();
}
}
}