-
Notifications
You must be signed in to change notification settings - Fork 2
/
theme-options.php
323 lines (251 loc) · 12.6 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
322
323
<?php
load_theme_textdomain( 'MaterialPress', get_template_directory() . '/languages' );
/* Add submenu to Appearance */
function mp_theme_options_menu() {
add_theme_page( 'MaterialPress', 'MaterialPress', 'manage_options', 'MaterialPress-theme-options', 'MaterialPress_theme_options' );
}
add_action( 'admin_menu', 'mp_theme_options_menu' );
////////////////////////////////////////////////////////////////////
// Add admin.css enqueue
////////////////////////////////////////////////////////////////////
function mp_theme_style() {
wp_enqueue_style('mp-theme', get_template_directory_uri() . '/css/admin.css');
}
add_action('admin_enqueue_scripts', 'mp_theme_style');
////////////////////////////////////////////////////////////////////
// Custom background theme support
////////////////////////////////////////////////////////////////////
$defaults = array(
'default-color' => '',
'default-image' => '',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => ''
);
add_theme_support( 'custom-background', $defaults );
////////////////////////////////////////////////////////////////////
// Custom header theme support
////////////////////////////////////////////////////////////////////
register_default_headers( array(
'wheel' => array(
'url' => '%s/img/deafaultlogo.png',
'thumbnail_url' => '%s/img/deafaultlogo.png',
'description' => __( 'Your Business Name', 'devdmbootstrap' )
))
);
$defaults = array(
'default-image' => get_template_directory_uri() . '/img/deafaultlogo.png',
'width' => 300,
'height' => 100,
'flex-height' => true,
'flex-width' => true,
'default-text-color' => '000',
'header-text' => true,
'uploads' => true,
'wp-head-callback' => '',
'admin-head-callback' => '',
'admin-preview-callback' => 'mp_admin_header_image',
);
add_theme_support( 'custom-header', $defaults );
function mp_admin_header_image() { ?>
<div id="headimg">
<?php
$color = get_header_textcolor();
$image = get_header_image();
if ( $color && $color != 'blank' ) :
$style = ' style="color:#' . $color . '"';
else :
$style = ' style="display:none"';
endif;
?>
<?php if ( $image ) : ?>
<img src="<?php echo esc_url( $image ); ?>" alt="" />
<?php endif; ?>
<div class="mp_header_name_desc">
<h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
<div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
</div>
</div>
<?php }
function custom_header_text_color () {
if ( get_header_textcolor() != 'blank' ) { ?>
<style>
.custom-header-text-color { color: #<?php echo get_header_textcolor(); ?> }
</style>
<?php }
}
add_action ('wp_head', 'custom_header_text_color');
////////////////////////////////////////////////////////////////////
// Register our settings options (the options we want to use)
////////////////////////////////////////////////////////////////////
$mp_options = array(
'author_credits' => true,
'user_comments' => true,
'right_sidebar' => true,
'right_sidebar_width' => 3,
'left_sidebar' => false,
'left_sidebar_width' => 3,
'show_header' => true,
'show_postmeta' => true
);
$mp_sidebar_sizes = array(
'1' => array (
'value' => '1',
'label' => '1'
),
'2' => array (
'value' => '2',
'label' => '2'
),
'3' => array (
'value' => '3',
'label' => '3'
),
'4' => array (
'value' => '4',
'label' => '4'
),
'5' => array (
'value' => '5',
'label' => '5'
)
);
function mp_register_settings() {
register_setting( 'mp_theme_options', 'mp_options', 'mp_validate_options' );
}
add_action ('admin_init', 'mp_register_settings');
$mp_settings = get_option( 'mp_options', $mp_options );
////////////////////////////////////////////////////////////////////
// Validate Options
////////////////////////////////////////////////////////////////////
function mp_validate_options( $input ) {
global $mp_options, $mp_sidebar_sizes;
$settings = get_option( 'mp_options', $mp_options );
$prev = $settings['right_sidebar_width'];
if ( !array_key_exists( $input['right_sidebar_width'], $mp_sidebar_sizes ) ) {
$input['right_sidebar_width'] = $prev;
}
$prev = $settings['left_sidebar_width'];
if ( !array_key_exists( $input['left_sidebar_width'], $mp_sidebar_sizes ) ) {
$input['left_sidebar_width'] = $prev;
}
if ( ! isset( $input['author_credits'] ) ) {
$input['author_credits'] = null;
} else {
$input['author_credits'] = ( $input['author_credits'] == 1 ? 1 : 0 );
}
if ( ! isset( $input['user_comments'] ) ) {
$input['user_comments'] = null;
} else {
$input['user_comments'] = ( $input['user_comments'] == 1 ? 1 : 0 );
}
if ( ! isset( $input['show_header'] ) ) {
$input['show_header'] = null;
} else {
$input['show_header'] = ( $input['show_header'] == 1 ? 1 : 0 );
}
if ( ! isset( $input['right_sidebar'] ) ) {
$input['right_sidebar'] = null;
} else {
$input['right_sidebar'] = ( $input['right_sidebar'] == 1 ? 1 : 0 );
}
if ( ! isset( $input['left_sidebar'] ) ) {
$input['left_sidebar'] = null;
} else {
$input['left_sidebar'] = ( $input['left_sidebar'] == 1 ? 1 : 0 );
}
if ( ! isset( $input['show_postmeta'] ) ) {
$input['show_postmeta'] = null;
} else {
$input['show_postmeta'] = ( $input['show_postmeta'] == 1 ? 1 : 0 );
}
return $input;
}
////////////////////////////////////////////////////////////////////
// Display Options Page
////////////////////////////////////////////////////////////////////
function MaterialPress_theme_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die('You do not have sufficient permissions to access this page.');
}
//get our global options
global $mp_options, $mp_sidebar_sizes, $developer_uri;
//get our logo
$logo = get_template_directory_uri() . '/img/logo.png'; ?>
<div class="wrap">
<div class="icon32" id="icon-options-general"></div>
<h2><a href="<?php echo $developer_uri ?>" target="_blank">MaterialPress</a></h2>
<?php
if ( ! isset( $_REQUEST['settings-updated'] ) )
$_REQUEST['settings-updated'] = false;
?>
<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
<div class='saved'><p><strong><?php _e('Options Saved!','MaterialPress') ;?></strong></p></div>
<?php endif; ?>
<form action="options.php" method="post">
<?php
$settings = get_option( 'mp_options', $mp_options );
settings_fields( 'mp_theme_options' );
?>
<table cellpadding='10'>
<tr valign="top"><th scope="row"><?php _e('Right Sidebar','MaterialPress') ;?></th>
<td>
<input type="checkbox" id="right_sidebar" name="mp_options[right_sidebar]" value="1" <?php checked( true, $settings['right_sidebar'] ); ?> />
<label for="right_sidebar"><?php _e('Show the Right Sidebar','MaterialPress') ;?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('Right Sidebar Size','MaterialPress') ;?></th>
<td>
<?php foreach( $mp_sidebar_sizes as $sizes ) : ?>
<input type="radio" id="<?php echo $sizes['value']; ?>" name="mp_options[right_sidebar_width]" value="<?php echo esc_attr($sizes['value']); ?>" <?php checked( $settings['right_sidebar_width'], $sizes['value'] ); ?> />
<label for="<?php echo $sizes['value']; ?>"><?php echo $sizes['label']; ?></label><br />
<?php endforeach; ?>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('Left Side Bar','MaterialPress') ;?></th>
<td>
<input type="checkbox" id="left_sidebar" name="mp_options[left_sidebar]" value="1" <?php checked( true, $settings['left_sidebar'] ); ?> />
<label for="left_sidebar"><?php _e('Show the Left Sidebar','MaterialPress') ;?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('Left Sidebar Size','MaterialPress') ;?></th>
<td>
<?php foreach( $mp_sidebar_sizes as $sizes ) : ?>
<input type="radio" id="<?php echo $sizes['value']; ?>" name="mp_options[left_sidebar_width]" value="<?php echo esc_attr($sizes['value']); ?>" <?php checked( $settings['left_sidebar_width'], $sizes['value'] ); ?> />
<label for="<?php echo $sizes['value']; ?>"><?php echo $sizes['label']; ?></label><br />
<?php endforeach; ?>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('Show Header','MaterialPress') ;?></th>
<td>
<input type="checkbox" id="show_header" name="mp_options[show_header]" value="1" <?php checked( true, $settings['show_header'] ); ?> />
<label for="show_header"><?php _e('Show The Main Header in the Template (logo/sitename/etc.)','MaterialPress') ;?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('Show Post Meta','MaterialPress') ;?></th>
<td>
<input type="checkbox" id="show_postmeta" name="mp_options[show_postmeta]" value="1" <?php checked( true, $settings['show_postmeta'] ); ?> />
<label for="show_postmeta"><?php _e('Show Post Meta data (author, category, date created)','MaterialPress') ;?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('Give Simon His Credit?','MaterialPress') ;?></th>
<td>
<input type="checkbox" id="author_credits" name="mp_options[author_credits]" value="1" <?php checked( true, $settings['author_credits'] ); ?> />
<label for="author_credits"><?php _e('Show me some love and keep a link to SimonSickle.com in your footer.','MaterialPress') ;?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('Enable User Comments?','MaterialPress') ;?></th>
<td>
<input type="checkbox" id="user_comments" name="mp_options[user_comments]" value="1" <?php checked( true, $settings['user_comments'] ); ?> />
<label for="user_comments"><?php _e('If checked, comments will be shown on all pages/posts.','MaterialPress') ;?></label>
</td>
</tr>
</table>
<p class="submit">
<input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes','MaterialPress'); ?>" />
</p>
</form>
</div>
<?php
}
?>