-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.php
More file actions
145 lines (123 loc) · 4.57 KB
/
theme.php
File metadata and controls
145 lines (123 loc) · 4.57 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* Base theme
* @package WDH
* @subpackage Theme
*
*/
require_once(dirname(__FILE__) . '/constants.php');
require_once(WDH_LIB_DIR . '/settings.php');
require_once(WDH_LIB_DIR . '/options.php');
/**
* Base theme to inherit from
*
* @author ericjuden <eric@ericjuden.com>
*/
class WDH_Theme {
var $theme_slug = 'wdh'; // Set a default
var $options;
var $network_theme_options;
var $settings_manager;
/**
* Constructor
*/
function __construct($theme_slug, $theme_options_name = ''){
$this->theme_slug = $theme_slug;
$this->settings_manager = new WDH_Settings_Manager($this->theme_slug, $theme_options_name);
if($theme_options_name != ''){
$this->options = new WDH_Options_Manager($theme_options_name, $this->settings_manager);
}
$this->define_theme_settings();
add_action('admin_init', array($this, 'admin_init'));
add_action('admin_menu', array($this, 'admin_menu'));
add_action('after_setup_theme', array($this, 'after_setup_theme'));
}
function add_settings_data(){
$this->settings_manager->prepare();
if(!empty($this->settings_manager->tabs)){
foreach($this->settings_manager->tabs as $tab){
// Add Settings Sections
foreach($tab->sections as $section){
add_settings_section($section->id, $section->title, array($section, 'maybe_render'), $this->options->option_name . '_' . $tab->id);
// Add controls
foreach($section->controls as $control){
add_settings_field($control->id, $control->title, array($control, 'render_content'), $this->options->option_name . '_' . $tab->id, $section->id, array());
}
}
// Register setting for the current tab
register_setting($this->options->option_name . '_' . $tab->id, $this->options->option_name . '_' . $tab->id);//, array($tab, 'sanitize_options'));
}
} else {
foreach($this->settings_manager->sections as $section){
add_settings_section($section->id, $section->title, array($section, 'maybe_render'), $this->options->option_name);
// Add controls
foreach($section->controls as $control){
add_settings_field($control->id, $control->title, array($control, 'render_content'), $this->options->option_name, $section->id, array());
}
}
// Register setting for page
register_setting($this->options->option_name, $this->options->option_name);
}
}
function admin_init(){
$this->add_settings_data();
}
function admin_menu(){
// Do we have any theme options for a page to be created?
if(!empty($this->settings_manager->sections)){
add_theme_page(__('Theme Settings'), __('Theme Settings'), 'edit_theme_options', $this->options->option_name, array($this, 'theme_settings'));
}
}
function after_setup_theme(){
}
function define_theme_settings(){
// override me
}
function theme_settings(){
// Security checkpoint
if(!current_user_can('edit_theme_options')){
wp_die(__('You do not have sufficient permissions to access this page.'));
}
// Display theme options
?>
<div class="wrap">
<div id="icon-themes" class="icon32"></div>
<h2><?php _e('Theme Options'); ?></h2>
<?php settings_errors(); ?>
<?php if(array_key_exists('saved', $_REQUEST) && $_REQUEST['saved']){ ?><div id="message" class="updated fade"><p><strong><?php _e('Settings saved.'); ?></strong></p></div><?php } ?>
<form method="post" action="options.php">
<?php if(!empty($this->settings_manager->tabs)){ ?>
<?php
$current_tab = false;
$current_tab_id = '';
if(isset($_GET['tab'])){
$current_tab_id = $_GET['tab'];
}
?>
<h2 class="nav-tab-wrapper">
<?php $i = 0;?>
<?php foreach($this->settings_manager->tabs as $tab){ ?>
<?php if($current_tab_id == '' && $i == 0){ ?>
<?php $current_tab = $tab; ?>
<?php $current_tab_id = $tab->id; ?>
<?php } elseif($current_tab_id == $tab->id){ ?>
<?php $current_tab = $tab; ?>
<?php $current_tab_id = $tab->id; ?>
<?php } ?>
<a href="?page=<?php echo $this->options->option_name; ?>&tab=<?php echo $tab->id; ?>" class="nav-tab<?php echo ($current_tab_id == $tab->id) ? ' nav-tab-active' : ''; ?>"><?php echo $tab->title; ?></a>
<?php $i++; ?>
<?php } ?>
</h2>
<?php settings_fields($this->options->option_name . "_" . $current_tab->id); ?>
<?php do_settings_sections($this->options->option_name . "_" . $current_tab->id); ?>
<?php } else { ?>
<?php settings_fields($this->options->option_name); ?>
<?php do_settings_sections($this->options->option_name); ?>
<?php } ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
}
?>