-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblue-options.php
212 lines (175 loc) · 9.22 KB
/
blue-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
<?php
add_action( 'admin_init', 'blue_options_init' );
add_action( 'admin_menu', 'blue_options_add_page' );
/**
* Init plugin options to white list our options
*/
function blue_options_init(){
register_setting( 'blue_options', 'blue_theme_options', 'blue_theme_options_validate' );
}
/**
* Load up the menu page
*/
function blue_options_add_page() {
add_theme_page( __( 'Theme Options', 'blue review' ), __( 'Theme Options', 'blue review' ), 'edit_theme_options', 'blue_review_theme_options', 'blue_options_do_page' );
}
/**
* Create the options page
*/
function blue_options_do_page() {
global $select_options, $radio_options;
if ( ! isset( $_REQUEST['settings-updated'] ) )
$_REQUEST['settings-updated'] = false;
?>
<div class="wrap">
<?php screen_icon(); echo "<h2>" . get_current_theme() . __( ' Theme Options', 'blue review' ) . "</h2>"; ?>
<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
<div class="updated fade"><p><strong><?php _e( 'Options saved', 'blue review' ); ?></strong></p></div>
<?php endif; ?>
<form method="post" action="options.php">
<?php settings_fields( 'blue_options' ); ?>
<?php $options = get_option( 'blue_theme_options' ); ?>
<table class="form-table">
<?php
/**
* A sample checkbox option
*/
?>
<tr valign="top"><th scope="row"><?php _e( 'Show Facebook icon', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[facebookYN]" name="blue_theme_options[facebookYN]" type="checkbox" value="1" <?php checked( '1', $options['facebookYN'] ); ?> />
<label class="description" for="blue_theme_options[facebookYN]"><?php _e( 'Show Facebook icon in header', 'blue review' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Show Twitter icon', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[twitterYN]" name="blue_theme_options[twitterYN]" type="checkbox" value="1" <?php checked( '1', $options['twitterYN'] ); ?> />
<label class="description" for="blue_theme_options[twitterYN]"><?php _e( 'Show Twitter icon in header', 'blue review' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Show google+ icon', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[gPlusYN]" name="blue_theme_options[gPlusYN]" type="checkbox" value="1" <?php checked( '1', $options['gPlusYN'] ); ?> />
<label class="description" for="blue_theme_options[gPlusYN]"><?php _e( 'Show google+ icon in header', 'blue review' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Show RSS', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[rssYN]" name="blue_theme_options[rssYN]" type="checkbox" value="1" <?php checked( '1', $options['rssYN'] ); ?> />
<label class="description" for="blue_theme_options[rssYN]"><?php _e( 'Show RSS icon in header', 'blue review' ); ?></label>
</td>
</tr>
<?php
/**
* A sample text input option
*/
?>
<tr valign="top"><th scope="row"><?php _e( 'Twitter Handle', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[twitterHandle]" class="regular-text" type="text" name="blue_theme_options[twitterHandle]" value="<?php esc_attr_e( $options['twitterHandle'] ); ?>" />
<label class="description" for="blue_theme_options[twitterHandle]"><?php _e( 'Twitter handle to which header icon should link', 'blue review' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Facebook URL', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[facebookURL]" class="regular-text" type="text" name="blue_theme_options[facebookURL]" value="<?php esc_attr_e( $options['facebookURL'] ); ?>" />
<label class="description" for="blue_theme_options[facebookURL]"><?php _e( 'Facebook profile URL to which icon should link', 'blue review' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'RSS URL', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[rssURL]" class="regular-text" type="text" name="blue_theme_options[rssURL]" value="<?php esc_attr_e( $options['rssURL'] ); ?>" />
<label class="description" for="blue_theme_options[rssURL]"><?php _e( 'URL for the rss icon', 'blue review' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Google Plus', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[gPlus]" class="regular-text" type="text" name="blue_theme_options[gPlus]" value="<?php esc_attr_e( $options['gPlus'] ); ?>" />
<label class="description" for="blue_theme_options[gPlus]"><?php _e( 'google+ profile URL to which icon should link', 'blue review' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Google Calendar', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[gCal]" class="regular-text" type="text" name="blue_theme_options[gCal]" value="<?php esc_attr_e( $options['gCal'] ); ?>" />
<label class="description" for="blue_theme_options[gCal]"><?php _e( 'URL to Google Calendar for events', 'blue review' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Footer Text', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[footText]" class="regular-text" type="text" name="blue_theme_options[footText]" value="<?php esc_attr_e( $options['footText'] ); ?>" />
<label class="description" for="blue_theme_options[footText]"><?php _e( 'Text for footer', 'blue review' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Footer Image URL', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[footImg]" class="regular-text" type="text" name="blue_theme_options[footImg]" value="<?php esc_attr_e( $options['footImg'] ); ?>" />
<label class="description" for="blue_theme_options[footImg]"><?php _e( 'Image for footer', 'blue review' ); ?></label>
</td>
<tr valign="top"><th scope="row"><?php _e( 'Footer Image link URL', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[footImgURL]" class="regular-text" type="text" name="blue_theme_options[footImgURL]" value="<?php esc_attr_e( $options['footImgURL'] ); ?>" />
<label class="description" for="blue_theme_options[footImgURL]"><?php _e( 'Link for footer image', 'blue review' ); ?></label>
</td>
<tr valign="top"><th scope="row"><?php _e( 'Article Disclaimer', 'blue review' ); ?></th>
<td>
<input id="blue_theme_options[disclaimer]" class="regular-text" type="text" name="blue_theme_options[disclaimer]" value="<?php esc_attr_e( $options['disclaimer'] ); ?>" />
<label class="description" for="blue_theme_options[disclaimer]"><?php _e( 'Disclaimer for the end of the article', 'blue review' ); ?></label>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'blue review' ); ?>" />
</p>
</form>
</div>
<?php
}
/**
* Sanitize and validate input. Accepts an array, return a sanitized array.
*/
function blue_theme_options_validate( $input ) {
global $select_options, $radio_options;
// Facebook YN
if ( ! isset( $input['facebookYN'] ) )
$input['facebookYN'] = null;
$input['facebookYN'] = ( $input['facebookYN'] == 1 ? 1 : 0 );
// Twitter YN
if ( ! isset( $input['twitterYN'] ) )
$input['twitterYN'] = null;
$input['twitterYN'] = ( $input['twitterYN'] == 1 ? 1 : 0 );
// RSS YN
if ( ! isset( $input['rssYN'] ) )
$input['rssYN'] = null;
$input['rssYN'] = ( $input['rssYN'] == 1 ? 1 : 0 );
// Facebook User
$input['facebookURL'] = esc_url_raw( $input['facebookURL'] );
// rss url
$input['rssURL'] = esc_url_raw( $input['rssURL'] );
// gPlus User
$input['gPlus'] = esc_url_raw( $input['gPlus'] );
// Twitter User
$input['twitterURL'] = esc_textarea( $input['twitterURL'] );
// GCal link
$input['gCal'] = esc_url_raw( $input['gCal'] );
// foot img link
$input['footImg'] = esc_url_raw( $input['footImg'] );
// foot img link url
$input['footImgURL'] = esc_url_raw( $input['footImgURL'] );
// foot text link
$input['footText'] = wp_kses_post( $input['footText'] );
// discliamer
$input['disclaimer'] = esc_textarea( $input['disclaimer'] );
// // Our select option must actually be in our array of select options
// if ( ! array_key_exists( $input['selectinput'], $select_options ) )
// $input['selectinput'] = null;
//
// // Our radio option must actually be in our array of radio options
// if ( ! isset( $input['radioinput'] ) )
// $input['radioinput'] = null;
// if ( ! array_key_exists( $input['radioinput'], $radio_options ) )
// $input['radioinput'] = null;
//
// // Say our textarea option must be safe text with the allowed tags for posts
// $input['sometextarea'] = wp_filter_post_kses( $input['sometextarea'] );
return $input;
}