-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme-options.php
312 lines (255 loc) · 12.4 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
<?php
add_action( 'admin_init', 'theme_options_init' );
add_action( 'admin_menu', 'theme_options_add_page' );
/**
* Init plugin options to white list our options
*/
function theme_options_init(){
register_setting( 'sample_options', 'cOptn', 'theme_options_validate' );
}
/**
* Load up the menu page
*/
function theme_options_add_page() {
add_theme_page( __( 'Theme Options', 'sampletheme' ), __( 'Theme Options', 'sampletheme' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' );
}
/**
* Create arrays for our select and radio options
*/
$select_options = array(
'0' => array(
'value' => '0',
'label' => __( 'Zero', 'sampletheme' )
),
'1' => array(
'value' => '1',
'label' => __( 'One', 'sampletheme' )
),
'2' => array(
'value' => '2',
'label' => __( 'Two', 'sampletheme' )
),
'3' => array(
'value' => '3',
'label' => __( 'Three', 'sampletheme' )
),
'4' => array(
'value' => '4',
'label' => __( 'Four', 'sampletheme' )
),
'5' => array(
'value' => '3',
'label' => __( 'Five', 'sampletheme' )
)
);
$radio_options = array(
'yes' => array(
'value' => 'yes',
'label' => __( 'Yes', 'sampletheme' )
),
'no' => array(
'value' => 'no',
'label' => __( 'No', 'sampletheme' )
),
'maybe' => array(
'value' => 'maybe',
'label' => __( 'Maybe', 'sampletheme' )
)
);
/**
* Create the options page
*/
function theme_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() . __( ' Options', 'sampletheme' ) . "</h2>"; ?>
<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
<div class="updated fade"><p><strong><?php _e( 'Options saved', 'sampletheme' ); ?></strong></p></div>
<?php endif; ?>
<?php // echo $_SERVER['REQUEST_URI']; ?>
<form id="file-form" enctype="multipart/form-data" action=" <?php bloginfo('siteurl'); ?>/wp-admin/themes.php?page=theme_options" method="POST">
<table class="form-table">
<tr valign="top"><th scope="row"><?php _e( 'Logo Path', 'sampletheme' ); ?></th>
<td>
<p id="async-upload-wrap">
<label for="async-upload">Upload</label>
<input type="file" id="async-upload" name="async-upload"> <input type="submit" value="Upload" name="html-upload">
</p>
<p>
<input type="hidden" name="post_id" id="post_id" value="1199" />
<?php wp_nonce_field('client-file-upload'); ?>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
</p>
<p>
<input type="submit" value="Save all changes" name="save" style="display: none;">
</p>
</td>
</tr></table>
</form>
<?php
if ( isset( $_POST['html-upload'] ) && !empty( $_FILES ) ) {
require_once(ABSPATH . 'wp-admin/includes/admin.php');
$id = media_handle_upload('async-upload', 1199); //post id of Client Files page
unset($_FILES);
if ( is_wp_error($id) ) {
$errors['upload_error'] = $id;
$id = false;
}
if ($errors) {
echo "<p>There was an error uploading your file.</p>";
} else {
echo "<p>Your file has been uploaded.</p>";
//echo $id;
//echo $_FILES['image']['name'][0];
echo wp_get_attachment_image($options['logo'],'100');
}
}
echo wp_get_attachment_image($options['logo'],'100');
?>
<form method="post" action="options.php" >
<?php settings_fields( 'sample_options' ); ?>
<?php $options = get_option( 'cOptn' ); ?>
<table class="form-table">
<tr valign="top"><th scope="row"><?php _e( 'Preview', 'sampletheme' ); ?></th>
<td>
<?php
$options = get_option('cOptn');
$oldId = $options['logo'];
if( $id == NULL){
$id = $oldId;
}
echo wp_get_attachment_image($id,'100');
?>
<input id="cOptn[logo]" class="regular-text" type="text" name="cOptn[logo]" value="<?php esc_attr_e( $id ); ?>" style=" width:1px" />
<label class="description" for="cOptn[logo]"><?php _e( 'Uploaded media Path', 'sampletheme' ); ?></label>
</td>
</tr>
<?php
/**
* A sample textarea option
*/
?>
<tr valign="top"><th scope="row"><?php _e( 'Copyright', 'sampletheme' ); ?></th>
<td>
<textarea id="cOptn[copyright]" class="large-text" cols="50" rows="10" name="cOptn[copyright]"><?php echo esc_textarea( $options['copyright'] ); ?></textarea>
<label class="description" for="cOptn[copyright]"><?php _e( 'Footer Copyright Text', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'twitter_link', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[twitter_link]" class="large-text" type="text" name="cOptn[twitter_link]" value="<?php echo esc_textarea( $options['twitter_link'] ); ?>">
<label class="description" for="cOptn[twitter_link]"><?php _e( 'Please Enter Twitter profile link', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'facebook_link', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[facebook_link]" class="large-text" type="text" name="cOptn[facebook_link]" value="<?php echo esc_textarea( $options['facebook_link'] ); ?>">
<label class="description" for="cOptn[facebook_link]"><?php _e( 'Please Enter Facebook profile link', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'googleplus_link', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[linkedin_link]" class="large-text" type="text" name="cOptn[googleplus_link]" value="<?php echo esc_textarea( $options['googleplus_link'] ); ?>">
<label class="description" for="cOptn[googleplus_link]"><?php _e( 'Please Enter Google Plus link', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'rss_link', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[rss_link]" class="large-text" type="text" name="cOptn[rss_link]" value="<?php echo esc_textarea( $options['rss_link'] ); ?>">
<label class="description" for="cOptn[rss_link]"><?php _e( 'Please Enter Rss link', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'email_link', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[email_link]" class="large-text" type="text" name="cOptn[email_link]" value="<?php echo esc_textarea( $options['email_link'] ); ?>">
<label class="description" for="cOptn[email_link]"><?php _e( 'Please Enter Email profile link', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'header_caption', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[header_caption]" class="large-text" type="text" name="cOptn[header_caption]" value="<?php echo esc_textarea( $options['header_caption'] ); ?>">
<label class="description" for="cOptn[header_caption]"><?php _e( 'Please Enter Your Header Caption', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'flicker_link', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[flicker_link]" class="large-text" type="text" name="cOptn[flicker_link]" value="<?php echo esc_textarea( $options['flicker_link'] ); ?>">
<label class="description" for="cOptn[flicker_link]"><?php _e( 'Please Enter Your Flicker Link', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'phone_num', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[phone_num]" class="large-text" type="text" name="cOptn[phone_num]" value="<?php echo esc_textarea( $options['phone_num'] ); ?>">
<label class="description" for="cOptn[phone_num]"><?php _e( 'Please Enter Phone Number', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'fax_num', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[fax_num]" class="large-text" type="text" name="cOptn[fax_num]" value="<?php echo esc_textarea( $options['fax_num'] ); ?>">
<label class="description" for="cOptn[fax_num]"><?php _e( 'Please Enter Fax', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'email', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[email]" class="large-text" type="text" name="cOptn[email]" value="<?php echo esc_textarea( $options['email'] ); ?>">
<label class="description" for="cOptn[email]"><?php _e( 'Please Enter Your Email Address', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'youtube', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[youtube]" class="large-text" type="text" name="cOptn[youtube]" value="<?php echo esc_textarea( $options['youtube'] ); ?>">
<label class="description" for="cOptn[youtube]"><?php _e( 'Please Enter Your youtube', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Call_us', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[Call_us]" class="large-text" type="text" name="cOptn[Call_us]" value="<?php echo esc_textarea( $options['Call_us'] ); ?>">
<label class="description" for="cOptn[Call_us]"><?php _e( 'Please Enter Your Call us', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Chat_with_us', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[Chat_with_us]" class="large-text" type="text" name="cOptn[Chat_with_us]" value="<?php echo esc_textarea( $options['Chat_with_us'] ); ?>">
<label class="description" for="cOptn[Chat_with_us]"><?php _e( 'Please Enter Your Chat with us', 'sampletheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'linkedin', 'sampletheme' ); ?></th>
<td>
<input id="cOptn[linkedin]" class="large-text" type="text" name="cOptn[linkedin]" value="<?php echo esc_textarea( $options['linkedin'] ); ?>">
<label class="description" for="cOptn[linkedin]"><?php _e( 'Please Enter Your Linkedin', 'sampletheme' ); ?></label>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'sampletheme' ); ?>" />
</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;
// Our checkbox value is either 0 or 1
if ( ! isset( $input['option1'] ) )
$input['option1'] = null;
$input['option1'] = ( $input['option1'] == 1 ? 1 : 0 );
// Say our text option must be safe text with no HTML tags
$input['sometext'] = wp_filter_nohtml_kses( $input['sometext'] );
// 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;
}