-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy paththeme-options.php
114 lines (97 loc) · 3.32 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
<?php
/*
* Theme options page
*/
/*
* Get theme options
*/
function dangopress_get_options()
{
$options = get_option('dangopress_options');
$defaults = array(
'cdn_prefix' => '',
'home_meta_descripton' => '',
'beian_str' => '',
'google_webid' => '',
'sitemap_xml' => '',
);
$options = wp_parse_args($options, $defaults);
update_option('dangopress_options', $options);
return $options;
}
/*
* Add theme option to the admin menu
*/
function dangopress_add_admin_menu()
{
add_theme_page('主题设置', '主题选项', 'edit_theme_options', basename(__FILE__),
'dangopress_theme_options');
}
/*
* Display theme options
*/
function dangopress_theme_options()
{
$options = dangopress_get_options();
?>
<h2>dangopress 主题设置</h2><br/>
<?php
if (isset($_POST['update_themeoptions']) && $_POST['update_themeoptions'] == 'true') {
foreach ($_POST as $key => $value) {
if (isset($value) && isset($options[$key]))
$options[$key] = $value;
}
update_option('dangopress_options', $options);
$options = get_option('dangopress_options');
?>
<div id="setting-error-settings_updated" class="updated settings-error">
<p><strong>设置已保存。</strong></p>
</div>
<?php
}
?>
<p>注意: 如果以下某个选项设置为空, 则不会启用该功能。如果当前用户是管理员账号, 不会加载统计代码。</p>
<form method="POST" action="">
<table class="form-table">
<tbody>
<tr>
<th>
<label for="cdn_prefix">文件托管地址</label> (<a target="_blank" href="http://kodango.com/use-oss-in-wordpress">参考</a>)
</th>
<td><input name="cdn_prefix" id="cdn_prefix" type="text" value="<?php echo $options['cdn_prefix']; ?>" class="regular-text code" /></td>
</tr>
<tr>
<th>
<label for="home_meta_descripton">首页 Meta Description</label>
</th>
<td><textarea name="home_meta_descripton" id="home_meta_descripton" rows="5" class="regular-text code"><?php echo $options['home_meta_descripton']; ?></textarea></td>
</tr>
<tr>
<th>
<label for="sitemap_xml">备案号</label>
</th>
<td><input name="beian_str" id="beian_str" type="text" value="<?php echo $options['beian_str']; ?>" class="regular-text code" /></td>
</tr>
<tr>
<th>
<label for="google_webid">Google Analytics Web ID</label> (<a target="_blank" href="https://developers.google.com/analytics/devguides/collection/gajs/">帮助</a>)
</th>
<td><input name="google_webid" id="google_webid" type="text" value="<?php echo $options['google_webid']; ?>" class="regular-text code" /></td>
</tr>
<tr>
<th>
<label for="sitemap_xml">站点地图文件名(如: sitemap.xml)</label>
</th>
<td><input name="sitemap_xml" id="sitemap_xml" type="text" value="<?php echo $options['sitemap_xml']; ?>" class="regular-text code" /></td>
</tr>
</tbody>
</table>
<input type="hidden" name="update_themeoptions" value="true" />
<p class="submit">
<input type="submit" name="submit" id="submit" class="button button-primary" value="保存更改">
</p>
</form>
<?php
}
add_action('admin_menu', 'dangopress_add_admin_menu');
?>