I was wondering if there was a way to prevent the addition of new categories into a taxonomy, essentially 'locking' the taxonomy.
I'm programatically registering a taxonomy and filling it with terms via functions.php and would like it so you cannot add anymore into it.
The Vision, REALIZED...
Heres how my solution ended up looking, and it works great! THANKS to everyone who helped. Upvotes all over the place up in your face!
// some stuff happens before this...
$labels = array(
'name' => _x( 'Attendees', 'taxonomy general name' ),
'singular_name' => _x( 'Attendee', 'taxonomy singular name' ),
'search_items' => __( 'Search Attendees' ),
'all_items' => __( 'All Attendees' ),
'edit_item' => __( 'Edit Attendee' ),
'update_item' => __( 'Update Attendee' ),
'add_new_item' => __( 'Add New Attendee' ),
'new_item_name' => __( 'New Attendee Name' ),
'menu_name' => __( 'Attendees' )
);
$rewrite = array(
'slug' => 'attendee'
);
$capabilities = array(
'manage_terms' => 'nobody',
'edit_terms' => 'nobody',
'delete_terms' => 'nobody',
'assign_terms' => 'nobody'
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => 'attendee',
'rewrite' => $rewrite,
'capabilities' => $capabilities
);
register_taxonomy('attendees', 'meetings', $args);
}
add_action( 'init', 'todo_create_taxonomies', 1);
function todo_register_attendees() {
$users = get_users();
foreach ( $users as $user ) {
wp_insert_term( $user->display_name, 'attendees', array('description'=> $user->display_name, 'slug' => $user->user_nicename) );
$lockdown[] = $user->user_nicename;
}
$terms = get_terms('attendees', array('get' => 'all') );
foreach ($terms as $term) {
if ( !in_array($term->slug, $lockdown) ) {
wp_delete_term( $term->term_id, 'attendees' );
$message = new WP_Error('force_terms', __('Only Registered Users can be Attendees, ' . $term->name . ' has been deleted.'));
if ( is_wp_error($message) ) { ?>
<div id="aphid-error-<?php echo $message->get_error_code(); ?>" class="error aphid-error">
<p><strong><?php echo $message->get_error_message(); ?></strong></p>
</div>
<?php }
}
}
}
add_action( 'admin_notices', 'todo_register_attendees' );