Created
December 15, 2016 17:00
-
-
Save richjenks/8353b0e43d339ff931743f05c716c1a4 to your computer and use it in GitHub Desktop.
Changes the taxonomy checkboxes into radios so only one can be selected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Changes the taxonomy checkboxes into radios so only one can be selected | |
* | |
* @param string|array $taxonomies Taxonomy(s) to be affected | |
* @param string|array $post_types Post Type(s) to be affected | |
*/ | |
function taxonomy_radios( $taxonomies, $post_types ) { | |
// Ensure params are arrays | |
if ( !is_array( $taxonomies ) ) $taxonomies = [ $taxonomies ]; | |
if ( !is_array( $post_types ) ) $post_types = [ $post_types ]; | |
// Loop through post types | |
foreach ( $post_types as $post_type ) { | |
// If correct post type, add action to output script | |
if ( Posts::get_post_type() === $post_type ) { | |
add_action( 'admin_footer', function() use ( $taxonomies ) { | |
echo '<script>'; | |
foreach ( $taxonomies as $taxonomy ) { | |
echo 'jQuery("[id^=in-'.$taxonomy.']").attr("type", "radio");'; | |
echo 'jQuery("#'.$taxonomy.'-tabs").hide();'; | |
} | |
echo '</script>'; | |
} ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment