Skip to content

Commit 0bb9497

Browse files
committed
checkboxes to toggle each taxonomy (not working)
1 parent 0c384e6 commit 0bb9497

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

archive-pages-taxonomy.php

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ function archive_pages_settings_init() {
6161
* includes built_in category, post_tag; excludes post_format
6262
* includes custom taxonomies
6363
**/
64-
65-
//$our_taxonomies = array( 'category', 'post_tag');
66-
6764
$our_taxonomies = get_taxonomies(
6865
array(
6966
'public' => true,
@@ -91,13 +88,20 @@ function archive_pages_settings_init() {
9188
//each taxonomy gets a section
9289
add_settings_section($section_name, $section_heading, '', 'archive-pages');
9390

91+
//checkbox to show/hide this section
92+
//this setting should hide the term pulldowns, AND it should disable term_links filter for this taxonomy even if individual fields are set in
93+
94+
archive_pages_taxonomy_toggle( $taxonomy, $section_name );
95+
96+
//display this if checkbox is checked
9497
archive_pages_settings_fields( $terms, 'name', $section_name);
9598

9699
}//end foreach
97100

98101
}
99102
add_action( 'admin_init', 'archive_pages_settings_init' );
100103

104+
101105
/**
102106
* Render list of all pages.
103107
*
@@ -123,12 +127,44 @@ function archive_pages_filter_archive_titles($args) {
123127
));
124128
}
125129

130+
/**
131+
* create toggle checkbox for each taxonomy
132+
*
133+
* */
134+
function archive_pages_taxonomy_toggle( $taxonomy, $section_name ){
135+
136+
register_setting('archive_pages_settings', 'archive_page_toggle_' . $taxonomy);
137+
138+
add_settings_field(
139+
'archive_page_toggle_'.$taxonomy, //slug-name to identify field
140+
'Set archive pages for '.$taxonomy, //title or label of field
141+
'archive_pages_taxonomy_toggle_callback', //callback
142+
'archive-pages', //settings page
143+
$section_name, //section of settings page
144+
array( )
145+
);
146+
147+
}
148+
149+
/**
150+
* render checkbox for each taxonomy
151+
* @link https://code.tutsplus.com/the-wordpress-settings-api-part-8-validation-sanitisation-and-input-i--wp-25361t
152+
* */
153+
function archive_pages_taxonomy_toggle_callback( ) {
154+
$options = get_option( 'archive-pages' );
155+
156+
$html = '<input type="checkbox" id="checkbox_example" name="sandbox_theme_input_examples[checkbox_example]" />';
157+
126158

159+
$html .= '<label for="checkbox_example">This is an example of a checkbox</label>';
160+
161+
echo $html;
162+
}
127163

128164
/**
129165
* Loop through list of archives and output nice label
130166
*
131-
* @param $archives array - archive list of post types, categories, etc
167+
* @param $archives array - list of terms
132168
* @param $label string - array key to use for label
133169
* @param $section string - section to add fields to
134170
*

0 commit comments

Comments
 (0)