-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.php
64 lines (52 loc) · 1.86 KB
/
settings.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
<?php
add_action('admin_menu', 'htc_add_admin_menu');
add_action('admin_init', 'htc_settings_init');
function htc_add_admin_menu() {
add_submenu_page('tools.php', 'hirtaxochecklist', 'hierarchical taxonomies checklist', 'manage_options', 'hirtaxochecklist', 'htc_options_page');
}
function htc_settings_init() {
register_setting('htcPage', 'htc_settings');
add_settings_section(
'htc_htcPage_section', __('', 'hirtaxochecklist'), 'htc_settings_section_callback', 'htcPage'
);
add_settings_field(
'htc_select_field_0', __('Please select taxomonies', 'hirtaxochecklist'), 'htc_select_field_0_render', 'htcPage', 'htc_htcPage_section'
);
}
function htc_select_field_0_render() {
$args = array(
'public' => true,
'hierarchical' => 1
// '_builtin' => false
);
$output = 'names'; // 'names' or 'objects'
$operator = 'and'; // 'and' or 'or'
$taxonomies = get_taxonomies($args, $output, $operator);
$options = get_option('htc_settings');
?>
<select name='htc_settings[htc_select_field_0][]' multiple="multiple">
<?php
if ($taxonomies) {
foreach ($taxonomies as $taxonomy) {
?>
<option value='<?php echo $taxonomy ?>' <?php if(isset($options['htc_select_field_0'])) echo in_array($taxonomy, $options['htc_select_field_0']) ? 'selected' : ''; ?> ><?php echo $taxonomy ?></option>
<?php }} ?>
</select>
<?php
}
function htc_settings_section_callback() {
echo __('hold Ctrl buttun for multiple selection', 'hirtaxochecklist');
}
function htc_options_page() {
?>
<form action='options.php' method='post'>
<h2> hierarchical taxomonies checklist checking</h2>
<?php
settings_fields('htcPage');
do_settings_sections('htcPage');
submit_button();
?>
</form>
<?php
}
?>