/
theme-options.php
316 lines (273 loc) · 11.2 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
<?php
/** theme-options.php
*
* @return void
*/
function the_bootstrap_theme_options_add_page() {
$theme_page = add_theme_page(
__( 'Theme Options', 'the-bootstrap' ), // Name of page
__( 'Theme Options', 'the-bootstrap' ), // Label in menu
'edit_theme_options', // Capability required
'theme_options', // Menu slug, used to uniquely identify the page
'the_bootstrap_theme_options_render_page' // Function that renders the options page
);
add_action( "admin_print_styles-{$theme_page}", 'the_bootstrap_admin_enqueue_scripts' );
}
add_action( 'admin_menu', 'the_bootstrap_theme_options_add_page' );
/**
.3.0 - 06.04.2012
*
* @return void
*/
function the_bootstrap_admin_enqueue_scripts( $hook_suffix ) {
wp_enqueue_style( 'the-bootstrap-theme-options', get_template_directory_uri() . '/css/theme-options.css', false, _the_bootstrap_version() );
}
/**
* @return void
*/
function the_bootstrap_theme_options_init() {
register_setting(
'the_bootstrap_options', // Options group, see settings_fields() call in the_bootstrap_theme_options_render_page()
'the_bootstrap_theme_options', // Database option, see the_bootstrap_options()
'the_bootstrap_theme_options_validate' // The sanitization callback, see the_bootstrap_theme_options_validate()
);
// Register settings field group
add_settings_section(
'general', // Unique identifier for the settings section
'', // Section title (we don't want one)
'__return_false', // Section callback (we don't want anything)
'theme_options' // Menu slug, used to uniquely identify the page; see the_bootstrap_theme_options_add_page()
);
// Register individual settings fields
add_settings_field( 'layout', __( 'Default Layout', 'the-bootstrap' ), 'the_bootstrap_settings_field_layout', 'theme_options', 'general' );
add_settings_field( 'navbar', __( 'Navigation Bar', 'the-bootstrap' ), 'the_bootstrap_settings_field_checkbox', 'theme_options', 'general', array(
(object) array(
'name' => 'navbar_site_name',
'value' => the_bootstrap_options()->navbar_site_name,
'description' => __( 'Add site name to navigation bar.', 'the-bootstrap' )
),
(object) array(
'name' => 'navbar_searchform',
'value' => the_bootstrap_options()->navbar_searchform,
'description' => __( 'Add searchform to navigation bar.', 'the-bootstrap' )
)
) );
add_settings_field( 'navbar-position', __( 'Navigation Bar Position', 'the-bootstrap' ), 'the_bootstrap_settings_field_radio', 'theme_options', 'general', array(
'name' => 'navbar_position',
'options' => array(
(object) array(
'value' => 'static',
'description' => __( 'Static.', 'the-bootstrap' )
),
(object) array(
'value' => 'navbar-fixed-top',
'description' => __( 'Fixed on top.', 'the-bootstrap' )
),
(object) array(
'value' => 'navbar-fixed-bottom',
'description' => __( 'Fixed at bottom.', 'the-bootstrap' )
),
)
) );
}
add_action( 'admin_init', 'the_bootstrap_theme_options_init' );
/**
* @param string $capability The capability used for the page, which is manage_options by default.
*
* @return string The capability to actually use.
*/
function the_bootstrap_option_page_capability( $capability ) {
return 'edit_theme_options';
}
add_filter( 'option_page_capability_the_bootstrap_options', 'the_bootstrap_option_page_capability' );
/**
* @return void
*/
function the_bootstrap_admin_bar_menu( $wp_admin_bar ) {
if ( current_user_can( 'edit_theme_options' ) AND is_admin_bar_showing() ) {
$wp_admin_bar->add_menu( array(
'title' => __( 'Theme Options', 'the-bootstrap' ),
'href' => add_query_arg( array( 'page' => 'theme_options' ), admin_url( 'themes.php' ) ),
'parent' => 'appearance',
'id' => 'the-bootstrap-theme-options',
) );
}
}
add_action( 'admin_bar_menu', 'the_bootstrap_admin_bar_menu', 61 ); //Appearance Menu used to be added at 60
/**
* @return void
*/
function the_bootstrap_layouts() {
$layout_options = array(
'content-sidebar' => array(
'label' => __( 'Content on left', 'the-bootstrap' ),
'thumbnail' => get_template_directory_uri() . '/img/content-sidebar.png',
),
'sidebar-content' => array(
'label' => __( 'Content on right', 'the-bootstrap' ),
'thumbnail' => get_template_directory_uri() . '/img/sidebar-content.png',
),
);
return apply_filters( 'the_bootstrap_layouts', $layout_options );
}
/**
* @return void
*/
function the_bootstrap_settings_field_layout() {
foreach ( the_bootstrap_layouts() as $value => $layout ) : ?>
<label class="image-radio-option">
<input type="radio" name="the_bootstrap_theme_options[theme_layout]" value="<?php echo esc_attr( $value ); ?>" <?php checked( the_bootstrap_options()->theme_layout, $value ); ?> />
<span class="image-radio-label">
<img src="<?php echo esc_url( $layout['thumbnail'] ); ?>" width="136" height="122" alt="" />
<span class="description"><?php echo $layout['label']; ?></span>
</span>
</label>
<?php endforeach;
}
/**
* @return void
*/
function the_bootstrap_settings_field_checkbox( $options ) {
foreach ( $options as $option ) : ?>
<label for="<?php echo sanitize_title_with_dashes( $option->name ); ?>">
<input type="checkbox" name="the_bootstrap_theme_options[<?php echo esc_attr( $option->name ); ?>]" id="<?php echo sanitize_title_with_dashes( $option->name ); ?>" value="1" <?php checked( $option->value ); ?> />
<?php echo esc_html( $option->description ); ?>
</label><br />
<?php endforeach;
}
/**
* @return void
*/
function the_bootstrap_settings_field_radio( $args ) {
extract( wp_parse_args( $args, array(
'name' => null,
'options' => array(),
) ) );
foreach ( (array) $options as $o ) : ?>
<label for="<?php echo sanitize_title_with_dashes( $o->value ); ?>">
<input type="radio" name="the_bootstrap_theme_options[<?php echo esc_attr( $name ); ?>]" id="<?php echo sanitize_title_with_dashes( $o->value ); ?>" value="<?php echo esc_attr( $o->value ); ?>" <?php checked( $o->value, the_bootstrap_options()->$name ); ?> />
<?php if ( isset( $o->description ) ) echo $o->description; ?>
</label><br />
<?php endforeach;
}
/**
* Renders the Settings page for The Bootstrap.
*
* @return void
*/
function the_bootstrap_theme_options_render_page() {
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php esc_html_e( 'The Bootstrap Theme Options', 'the-bootstrap' ); ?></h2>
<?php settings_errors(); ?>
<div id="poststuff">
<div id="post-body" class="obenland-wp columns-2">
<div id="post-body-content">
<form method="post" action="options.php">
<?php
settings_fields( 'the_bootstrap_options' );
do_settings_sections( 'theme_options' );
submit_button(); ?>
</form>
</div>
<div id="postbox-container-1">
<div id="side-info-column">
<?php do_action( 'the_bootstrap_side_info_column' ); ?>
</div>
</div>
</div>
</div>
</div>
<?php
}
/**
* @return void
*/
function the_bootstrap_theme_options_validate( $input ) {
$output = $defaults = the_bootstrap_get_default_theme_options();
if ( isset( $input['theme_layout'] ) AND array_key_exists( $input['theme_layout'], the_bootstrap_layouts() ) )
$output['theme_layout'] = $input['theme_layout'];
if ( isset( $input['navbar_position'] ) AND in_array( $input['navbar_position'], array('static', 'navbar-fixed-top', 'navbar-fixed-bottom') ) )
$output['navbar_position'] = $input['navbar_position'];
$output['navbar_site_name'] = isset( $input['navbar_site_name'] ) AND $input['navbar_site_name'];
$output['navbar_searchform'] = isset( $input['navbar_searchform'] ) AND $input['navbar_searchform'];
if ( ! get_settings_errors() ) {
add_settings_error( 'the-bootstrap-options', 'settings_updated', sprintf( __( 'Settings saved. <a href="%s">Visit your site</a> to see how it looks.', 'the-bootstrap' ), home_url( '/' ) ), 'updated' );
}
return apply_filters( 'the_bootstrap_theme_options_validate', $output, $input, $defaults );
}
/**
* Displays a box with a donate button and call to action links
*/
function the_bootstrap_donate_box() {
?>
<div id="formatdiv" class="postbox">
<h3 class="hndle"><span><?php esc_html_e( 'Help spread the word!', 'the-bootstrap' ); ?></span></h3>
<div class="inside">
<p><strong><?php printf( _x( 'Want to help make this Theme even better? All donations are used to improve %1$s, so donate $20, $50 or $100 now!', 'Plugin Name', 'the-bootstrap' ), esc_html('The Bootstrap ') ); ?></strong></p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="542W6XT4PLT4L">
<input type="image" src="https://www.paypalobjects.com/<?php echo get_locale(); ?>/i/btn/btn_donate_LG.gif" name="submit" alt="PayPal">
<img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</form>
<p><?php _e( 'Or you could:', 'the-bootstrap' ); ?></p>
<ul>
<li><a href="http://wordpress.org/extend/themes/the-bootstrap"><?php _e( 'Rate the Theme 5★ on WordPress.org', 'the-bootstrap' ); ?></a></li>
<li><a href="http://en.wp.obenland.it/the-bootstrap/"><?php _e( 'Blog about it & link to the Theme page', 'the-bootstrap' ); ?></a></li>
</ul>
</div>
</div>
<?php
}
add_action( 'the_bootstrap_side_info_column', 'the_bootstrap_donate_box', 1 );
/**
* Displays a box with feed items and social media links
* @return void
*/
function the_bootstrap_feed_box() {
$rss_items = _the_bootstrap_fetch_feed( 'http://en.wp.obenland.it/feed/' );
?>
<div id="formatdiv" class="postbox">
<h3 class="hndle"><span><?php esc_html_e( 'News from Konstantin', 'the-bootstrap' ); ?></span></h3>
<div class="inside">
<ul>
<?php if ( ! $rss_items ) : ?>
<li><?php _e( 'No news items, feed might be broken...', 'the-bootstrap' ); ?></li>
<?php else :
foreach ( $rss_items as $item ) :
$url = preg_replace( '/#.*/', '#utm_source=wordpress&utm_medium=sidebannerpostbox&utm_term=rssitem&utm_campaign=the-bootstrap', $item->get_permalink() ); ?>
<li><a class="rsswidget" href="<?php echo esc_url( $url ); ?>"><?php echo esc_html( $item->get_title() ); ?></a></li>
<?php endforeach; endif; ?>
<li class="twitter"><a href="http://twitter.com/obenland"><?php _e( 'Follow Konstantin on Twitter', 'the-bootstrap' ); ?></a></li>
<li class="rss"><a href="http://en.wp.obenland.it/feed/"><?php _e( 'Subscribe via RSS', 'the-bootstrap' ); ?></a></li>
</ul>
</div>
</div>
<?php
}
add_action( 'the_bootstrap_side_info_column', 'the_bootstrap_feed_box' );
/**
* Callback function to get feed items
*/
function _the_bootstrap_fetch_feed( $feed_url ) {
include_once( ABSPATH . WPINC . '/feed.php' );
$rss = fetch_feed( $feed_url );
// Bail if feed doesn't work
if ( is_wp_error( $rss ) ) {
return false;
}
$rss_items = $rss->get_items( 0, $rss->get_item_quantity( 5 ) );
// If the feed was erroneously
if ( ! $rss_items ) {
$md5 = md5( $feed_url );
delete_transient( 'feed_' . $md5 );
delete_transient( 'feed_mod_' . $md5 );
$rss = fetch_feed( $feed_url );
$rss_items = $rss->get_items( 0, $rss->get_item_quantity( 5 ) );
}
return $rss_items;
}
/* End of file theme-options.php */
/* Location: ./wp-content/themes/the-bootstrap/inc/theme-options.php */