-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnhp-options.php
executable file
·296 lines (238 loc) · 10.5 KB
/
nhp-options.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?php
/*
*
* Require the framework class before doing anything else, so we can use the defined urls and dirs
* Also if running on windows you may have url problems, which can be fixed by defining the framework url first
*
*/
//define('NHP_OPTIONS_URL', site_url('path the options folder'));
if(!class_exists('NHP_Options')){
require_once( dirname( __FILE__ ) . '/options/options.php' );
}
/*
*
* Custom function for filtering the sections array given by theme, good for child themes to override or add to the sections.
* Simply include this function in the child themes functions.php file.
*
* NOTE: the defined constansts for urls, and dir will NOT be available at this point in a child theme, so you must use
* get_template_directory_uri() if you want to use any of the built in icons
*
*/
function add_another_section($sections){
//$sections = array();
$sections[] = array(
'title' => __('A Section added by hook', 'nhp-opts'),
'desc' => __('<p class="description">This is a section created by adding a filter to the sections array, great to allow child themes, to add/remove sections from the options.</p>', 'nhp-opts'),
//all the glyphicons are included in the options folder, so you can hook into them, or link to your own custom ones.
//You dont have to though, leave it blank for default.
'icon' => trailingslashit(get_template_directory_uri()).'options/img/glyphicons/glyphicons_062_attach.png',
//Lets leave this as a blank section, no options just some intro text set above.
'fields' => array()
);
return $sections;
}//function
//add_filter('nhp-opts-sections-twenty_eleven', 'add_another_section');
/*
*
* Custom function for filtering the args array given by theme, good for child themes to override or add to the args array.
*
*/
function change_framework_args($args){
//$args['dev_mode'] = false;
return $args;
}//function
//add_filter('nhp-opts-args-twenty_eleven', 'change_framework_args');
/*
* This is the meat of creating the optons page
*
* Override some of the default values, uncomment the args and change the values
* - no $args are required, but there there to be over ridden if needed.
*
*
*/
function setup_framework_options(){
$args = array();
//Set it to dev mode to view the class settings/info in the form - default is false
$args['dev_mode'] = true;
//google api key MUST BE DEFINED IF YOU WANT TO USE GOOGLE WEBFONTS
//$args['google_api_key'] = '***';
//Remove the default stylesheet? make sure you enqueue another one all the page will look whack!
//$args['stylesheet_override'] = true;
//Add HTML before the form
$args['intro_text'] = __('<p>This is the HTML which can be displayed before the form, it isnt required, but more info is always better. Anything goes in terms of markup here, any HTML.</p>', 'nhp-opts');
//Setup custom links in the footer for share icons
$args['share_icons']['twitter'] = array(
'link' => 'http://twitter.com/lee__mason',
'title' => 'Folow me on Twitter',
'img' => NHP_OPTIONS_URL.'img/glyphicons/glyphicons_322_twitter.png'
);
$args['share_icons']['linked_in'] = array(
'link' => 'http://uk.linkedin.com/pub/lee-mason/38/618/bab',
'title' => 'Find me on LinkedIn',
'img' => NHP_OPTIONS_URL.'img/glyphicons/glyphicons_337_linked_in.png'
);
//Choose to disable the import/export feature
//$args['show_import_export'] = false;
//Choose a custom option name for your theme options, the default is the theme name in lowercase with spaces replaced by underscores
$args['opt_name'] = 'boloday';
//Custom menu icon
//$args['menu_icon'] = '';
//Custom menu title for options page - default is "Options"
$args['menu_title'] = __('Theme Options', 'nhp-opts');
//Custom Page Title for options page - default is "Options"
$args['page_title'] = __('Boloday Theme Options', 'nhp-opts');
//Custom page slug for options page (wp-admin/themes.php?page=***) - default is "nhp_theme_options"
$args['page_slug'] = 'nhp_theme_options';
//Custom page capability - default is set to "manage_options"
//$args['page_cap'] = 'manage_options';
//page type - "menu" (adds a top menu section) or "submenu" (adds a submenu) - default is set to "menu"
//$args['page_type'] = 'submenu';
//parent menu - default is set to "themes.php" (Appearance)
//the list of available parent menus is available here: http://codex.wordpress.org/Function_Reference/add_submenu_page#Parameters
//$args['page_parent'] = 'themes.php';
//custom page location - default 100 - must be unique or will override other items
$args['page_position'] = 27;
//Custom page icon class (used to override the page icon next to heading)
//$args['page_icon'] = 'icon-themes';
//Want to disable the sections showing as a submenu in the admin? uncomment this line
//$args['allow_sub_menu'] = false;
//Set ANY custom page help tabs - displayed using the new help tab API, show in order of definition
$args['help_tabs'][] = array(
'id' => 'nhp-opts-1',
'title' => __('Theme Information 1', 'nhp-opts'),
'content' => __('<p>This is the tab content, HTML is allowed.</p>', 'nhp-opts')
);
$args['help_tabs'][] = array(
'id' => 'nhp-opts-2',
'title' => __('Theme Information 2', 'nhp-opts'),
'content' => __('<p>This is the tab content, HTML is allowed.</p>', 'nhp-opts')
);
//Set the Help Sidebar for the options page - no sidebar by default
$args['help_sidebar'] = __('<p>This is the sidebar content, HTML is allowed.</p>', 'nhp-opts');
$sections = array();
$sections[] = array(
'title' => __('General Settings', 'nhp-opts'),
'desc' => __('<p class="description">Do some hawt stuff like custom logo and colors and stuff. Pretty Hawt!</p>', 'nhp-opts'),
//all the glyphicons are included in the options folder, so you can hook into them, or link to your own custom ones.
//You dont have to though, leave it blank for default.
'icon' => NHP_OPTIONS_URL.'img/glyphicons/glyphicons_062_attach.png',
//Lets leave this as a blank section, no options just some intro text set above.
'fields' => array(
array(
'id' => '1',
'type' => 'upload',
'title' => 'Logo',
'desc' => 'Upload your Logo',
'std' => get_bloginfo('template_url').'/img/logo.png'
),
array(
'id' => '2',
'type' => 'select',
'title' => __('Style', 'nhp-opts'),
'sub_desc' => __('You can choose from a variety of color schemes.', 'nhp-opts'),
'desc' => __('Color schemes change the colors of your blog.', 'nhp-opts'),
'options' => array('style' => 'Default','blue' => 'Blue','orange' => 'Orange', 'dark' => 'Dark', 'green' => 'Green', 'yellow' => 'Yellow'),//Must provide key => value pairs for select options
'std' => 'style'
),
array(
'id' => '3',
'type' => 'select',
'title' => __('Feature Size', 'nhp-opts'),
'sub_desc' => __('Determines the size of the feature (the big images).', 'nhp-opts'),
'desc' => __('Can either span across the whole viewport or be locked to the content width', 'nhp-opts'),
'options' => array('full' => 'Full Width','small' => 'Content Width'),//Must provide key => value pairs for select options
'std' => 'full'
),
array(
'id' => '6',
'type' => 'select',
'title' => 'Homepage Slider Type',
'sub_desc' => 'Specify the type of slider to be displayed on the frontpage',
'desc' => 'Either display a large slider with only features, or a smaller one, with subfeatures',
'options' => array('default' => 'Single Slider', 'multiple' => 'Slider with Subfeatures'),
'std' => 'default'
),
array(
'id' => '4',
'type' => 'text',
'title' => 'Tag for featured posts',
'sub_desc' => 'Please enter a tag',
'desc' => 'The tag chosen here will be used to feed the feature slider on the homepage',
'std' => 'feature'
),
array(
'id' => '5',
'type' => 'text',
'title' => 'Featured Post Limit',
'sub_desc' => 'Number of featured posts to display',
'desc' => 'This determines how many posts will be shown in the slider, defaults to 5',
'std' => '5'
)
)
);
$tabs = array();
if (function_exists('wp_get_theme')){
$theme_data = wp_get_theme();
$theme_uri = $theme_data->get('ThemeURI');
$description = $theme_data->get('Description');
$author = $theme_data->get('Author');
$version = $theme_data->get('Version');
$tags = $theme_data->get('Tags');
}else{
$theme_data = get_theme_data(trailingslashit(get_stylesheet_directory()).'style.css');
$theme_uri = $theme_data['URI'];
$description = $theme_data['Description'];
$author = $theme_data['Author'];
$version = $theme_data['Version'];
$tags = $theme_data['Tags'];
}
$theme_info = '<div class="nhp-opts-section-desc">';
$theme_info .= '<p class="nhp-opts-theme-data description theme-uri">'.__('<strong>Theme URL:</strong> ', 'nhp-opts').'<a href="'.$theme_uri.'" target="_blank">'.$theme_uri.'</a></p>';
$theme_info .= '<p class="nhp-opts-theme-data description theme-author">'.__('<strong>Author:</strong> ', 'nhp-opts').$author.'</p>';
$theme_info .= '<p class="nhp-opts-theme-data description theme-version">'.__('<strong>Version:</strong> ', 'nhp-opts').$version.'</p>';
$theme_info .= '<p class="nhp-opts-theme-data description theme-description">'.$description.'</p>';
$theme_info .= '<p class="nhp-opts-theme-data description theme-tags">'.__('<strong>Tags:</strong> ', 'nhp-opts').implode(', ', $tags).'</p>';
$theme_info .= '</div>';
$tabs['theme_info'] = array(
'icon' => NHP_OPTIONS_URL.'img/glyphicons/glyphicons_195_circle_info.png',
'title' => __('Theme Information', 'nhp-opts'),
'content' => $theme_info
);
global $NHP_Options;
$NHP_Options = new NHP_Options($sections, $args, $tabs);
}//function
add_action('init', 'setup_framework_options', 0);
/*
*
* Custom function for the callback referenced above
*
*/
function my_custom_field($field, $value){
print_r($field);
print_r($value);
}//function
/*
*
* Custom function for the callback validation referenced above
*
*/
function validate_callback_function($field, $value, $existing_value){
$error = false;
$value = 'just testing';
/*
do your validation
if(something){
$value = $value;
}elseif(somthing else){
$error = true;
$value = $existing_value;
$field['msg'] = 'your custom error message';
}
*/
$return['value'] = $value;
if($error == true){
$return['error'] = $field;
}
return $return;
}//function
?>