forked from davidtcarson/frisco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme-options.php
323 lines (279 loc) · 11.9 KB
/
theme-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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?php
add_action( 'admin_init', 'theme_options_init' );
// add_action( 'admin_menu', 'theme_options_add_page' );
if ( current_user_can( 'edit_theme_options' ) ) {
add_action( 'admin_bar_menu', 'theme_options_nav' );
}
/**
* Init plugin options to white list our options
*/
function theme_options_init(){
register_setting( 'frisco_options', 'frisco_theme_options', 'theme_options_validate' );
}
function frisco_theme_options_add_page() {
$theme_page = add_theme_page(
__( 'Theme Options', 'friscotheme' ), // Name of page
__( 'Theme Options', 'friscotheme' ), // Label in menu
'edit_theme_options', // Capability required
'theme_options', // Menu slug, used to uniquely identify the page
'frisco_theme_options_render_page' // Function that renders the options page
);
if ( ! $theme_page )
return;
add_action( "load-$theme_page", 'frisco_theme_options_help' );
}
add_action( 'admin_menu', 'frisco_theme_options_add_page' );
function frisco_theme_options_help() {
$help = '<p>' . __( 'Some themes provide customization options that are grouped together on a Theme Options screen. If you change themes, options may change or disappear, as they are theme-specific. Your current theme, <strong>Frisco for BuddyPress</strong>, provides the following Theme Options:', 'friscotheme' ) . '</p>' .
'<ol>' .
'<li>' . __( '<strong>Theme Color</strong>: You can choose from several colors or use a custom stylesheet to create your own.', 'friscotheme' ) . '</li>' .
'<li>' . __( '<strong>Google Font</strong>: You can choose a Google Web Font for your site title with just a couple clicks.', 'friscotheme' ) . '</li>' .
'<li>' . __( '<strong>Custom Stylesheet</strong>: If you need to customize the stylesheet (ex. change fonts, colors, etc.), create a file called <code>custom.css</code> and simply check the box to load that stylesheet. This will make your life much easier when you upgrade the theme down the road because your changes will not be overriden.', 'friscotheme' ) . '</li>' .
'<li>' . __( '<strong>Custom Functions</strong>: Similar to the Custom Stylesheet option, you can load your own functions file instead of editing the main functions file. Create a file called <code>functions-custom.php</code> and check the option. Your custom functions file will not be overriden when upgrading the theme.', 'friscotheme' ) . '</li>' .
'</ol>' .
'<p>' . __( 'Remember to click "Save Changes" to save any changes you have made to the theme options.', 'friscotheme' ) . '</p>';
$tips = '<p>' . __( '<strong>USE WIDGETS:</strong> This theme uses the same sidebar and footer widgets available to the BuddyPress default theme. <a href="widgets.php">Use them!</a> If you want to show different widgets on different pages, use the <a href="http://wordpress.org/extend/plugins/widget-logic/">Widget Logic Plugin</a> (<a href="plugin-install.php?tab=search&type=term&s=widget+logic&plugin-search-input=Search+Plugins">link to install</a>) along with some <a href="http://codex.wordpress.org/Conditional_Tags">WordPress conditional tags</a> or <a href="http://codex.buddypress.org/developer-docs/conditional-template-tags/">BuddyPress conditional tags</a>.', 'friscotheme' ) . '</p>' .
'<p>' . __( '<p><strong>GET SUPPORT:</strong> This theme is free and support is not included. But, if you get stuck or if you have any questions, start a new thread in the <a href="http://wordpress.org/support/forum/themes-and-templates">WordPress theme forums</a> or the <a href="http://buddypress.org/community/groups/creating-extending/forum/">BuddyPress theme forums</a>. <em>IMPORTANT:</em> If you post in the WordPress or BuddyPress forums, make sure you add the tag "Frisco" or "Frisco Theme" to the post. This will make it easier for the theme author to become aware of your issue.</p>', 'friscotheme' ) . '</p>' ;
$sidebar = '<p><strong>' . __( 'For more information:', 'friscotheme' ) . '</strong></p>' .
'<p>' . __( '<a href="http://friscotheme.com" target="_blank">Frisco Theme Website</a>', 'friscotheme' ) . '</p>' .
'<p>' . __( '<a href="http://wordpress.org/tags/frisco-for-buddypress" target="_blank">Free Support Forums</a>', 'friscotheme' ) . '</p>' ;
$screen = get_current_screen();
if ( method_exists( $screen, 'add_help_tab' ) ) {
// WordPress 3.3
$screen->add_help_tab( array(
'title' => __( 'Overview', 'friscotheme' ),
'id' => 'theme-options-help-overview',
'content' => $help,
)
);
$screen->add_help_tab( array(
'title' => __( 'Tips', 'friscotheme' ),
'id' => 'theme-options-help-more',
'content' => $tips,
)
);
$screen->set_help_sidebar( $sidebar );
} else {
// WordPress 3.2
get_current_screen()->add_help_tab( $screen, $help . $sidebar );
}
}
// Add theme options navigation to admin bar.
if ( current_user_can( 'edit_theme_options' ) ) {
function theme_options_nav() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'parent' => 'appearance',
'id' => 'theme-options',
'title' => 'Theme Options',
'href' => admin_url('themes.php?page=theme_options')
) );
}
}
/**
* Create arrays for our select and radio options
*/
$select_options = array(
'default' => array(
'value' => 'default',
'label' => __( 'Default', 'friscotheme' )
),
'green' => array(
'value' => 'green',
'label' => __( 'Green', 'friscotheme' )
),
'orange' => array(
'value' => 'orange',
'label' => __( 'Orange', 'friscotheme' )
),
'yellow' => array(
'value' => 'yellow',
'label' => __( 'Yellow', 'friscotheme' )
),
'grey' => array(
'value' => 'grey',
'label' => __( 'Grey', 'friscotheme' )
),
'purple' => array(
'value' => 'purple',
'label' => __( 'Purple', 'friscotheme' )
)
);
$radio_options = array(
'yes' => array(
'value' => 'yes',
'label' => __( 'Yes', 'friscotheme' )
),
'no' => array(
'value' => 'no',
'label' => __( 'No', 'friscotheme' )
),
'maybe' => array(
'value' => 'maybe',
'label' => __( 'Maybe', 'friscotheme' )
)
);
$select_font_options = array(
'Lobster Two' => array(
'value' => 'Lobster Two',
'label' => __( 'Lobster Two', 'friscotheme' )
),
'Quattrocento' => array(
'value' => 'Quattrocento',
'label' => __( 'Quattrocento', 'friscotheme' )
),
'Droid Sans' => array(
'value' => 'Droid Sans',
'label' => __( 'Droid Sans', 'friscotheme' )
),
'PT Sans' => array(
'value' => 'PT Sans',
'label' => __( 'PT Sans', 'friscotheme' )
),
'Yanone Kaffeesatz' => array(
'value' => 'Yanone Kaffeesatz',
'label' => __( 'Yanone Kaffeesatz', 'friscotheme' )
),
'Cabin' => array(
'value' => 'Cabin',
'label' => __( 'Cabin', 'friscotheme' )
),
'Black Ops One' => array(
'value' => 'Black Ops One',
'label' => __( 'Black Ops One', 'friscotheme' )
),
'Nixie One' => array(
'value' => 'Nixie One',
'label' => __( 'Nixie One', 'friscotheme' )
),
'Bangers' => array(
'value' => 'Bangers',
'label' => __( 'Bangers', 'friscotheme' )
),
'Monofett' => array(
'value' => 'Monofett',
'label' => __( 'Monofett', 'friscotheme' )
)
);
/**
* Create the options page
*/
function frisco_theme_options_render_page() {
global $select_options, $radio_options, $select_font_options;
if ( ! isset( $_REQUEST['settings-updated'] ) )
$_REQUEST['settings-updated'] = false;
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2>
<?php _e('Frisco Theme Options', 'friscotheme' ); ?>
</h2>
<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
<div class="updated fade"><p><strong><?php _e( 'Options saved', 'friscotheme' ); ?></strong></p></div>
<?php endif; ?>
<form method="post" action="options.php">
<?php settings_fields( 'frisco_options' ); ?>
<?php $options = get_option( 'frisco_theme_options' ); ?>
<table class="form-table">
<?php
/**
* Color Choices
*/
?>
<tr valign="top" class="frisco-odd"><th scope="row"><?php _e( 'Select Theme Color', 'friscotheme' ); ?></th>
<td>
<select name="frisco_theme_options[themecolor]">
<?php
$selected = $options['themecolor'];
$p = '';
$r = '';
foreach ( $select_options as $option ) {
$label = $option['label'];
if ( $selected == $option['value'] ) // Make default first in list
$p = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
else
$r .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $option['value'] ) . "'>$label</option>";
}
echo $p . $r;
?>
</select>
<label class="description" for="frisco_theme_options[themecolor]"><?php _e( 'Choose a color scheme for your website.', 'friscotheme' ); ?></label>
</td>
</tr>
<?php
/**
* Font Choices
*/
?>
<tr valign="top"><th scope="row"><?php _e( 'Select Google Font', 'friscotheme' ); ?></th>
<td>
<select name="frisco_theme_options[googlefont]">
<?php
$selected = $options['googlefont'];
$p = '';
$r = '';
foreach ( $select_font_options as $option ) {
$label = $option['label'];
if ( $selected == $option['value'] ) // Make default first in list
$p = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
else
$r .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $option['value'] ) . "'>$label</option>";
}
echo $p . $r;
?>
</select>
<label class="description" for="frisco_theme_options[googlefont]"><?php _e( 'Choose a font for the site title.', 'friscotheme' ); ?></label>
</td>
</tr>
<?php
/**
* Use custom.css?
*/
?>
<tr valign="top" class="frisco-odd"><th scope="row"><?php _e( 'Custom Stylesheet', 'friscotheme' ); ?></th>
<td>
<input id="frisco_theme_options[customcss]" name="frisco_theme_options[customcss]" type="checkbox" value="1" <?php checked( '1', $options['customcss'] ); ?> />
<label class="description" for="frisco_theme_options[customcss]"><?php _e( 'Check this box to use a custom stylesheet. Create <code>custom.css</code> in the main theme directory.', 'friscotheme' ); ?></label>
</td>
</tr>
<?php
/**
* Use functions-custom.php?
*/
?>
<tr valign="top"><th scope="row"><?php _e( 'Custom Functions', 'friscotheme' ); ?></th>
<td>
<input id="frisco_theme_options[customphp]" name="frisco_theme_options[customphp]" type="checkbox" value="1" <?php checked( '1', $options['customphp'] ); ?> />
<label class="description" for="frisco_theme_options[customphp]"><?php _e( 'Check this box to use a custom functions file. Create <code>functions-custom.php</code> in the main theme directory.', 'friscotheme' ); ?></label>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'friscotheme' ); ?>" />
</p>
</form>
</div>
<?php
}
/**
* Sanitize and validate input. Accepts an array, return a sanitized array.
*/
function theme_options_validate( $input ) {
global $select_options, $radio_options, $select_font_options;
// Our checkbox value is either 0 or 1
if ( ! isset( $input['customcss'] ) )
$input['customcss'] = null;
$input['customcss'] = ( $input['customcss'] == 1 ? 1 : 0 );
// Our checkbox value is either 0 or 1
if ( ! isset( $input['customphp'] ) )
$input['customphp'] = null;
$input['customphp'] = ( $input['customphp'] == 1 ? 1 : 0 );
// Our select option must actually be in our array of select options
if ( ! array_key_exists( $input['themecolor'], $select_options ) )
$input['themecolor'] = null;
// Our select option must actually be in our array of select options
if ( ! array_key_exists( $input['googlefont'], $select_font_options ) )
$input['googlefont'] = null;
return $input;
}
// adapted from http://planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/