How to not allow users to create new tags, but allow to them to use existing ones

You can hook onto pre_insert_term, check the taxonomy and whether or not the user has the specified role as follows:

function disallow_insert_term($term, $taxonomy) {

    $user = wp_get_current_user();

    if ( $taxonomy === 'post_tag' && in_array('somerole', $user->roles) ) {

        return new WP_Error(
            'disallow_insert_term', 
            __('Your role does not have permission to add terms to this taxonomy')
        );

    }

    return $term;

}

add_filter('pre_insert_term', 'disallow_insert_term', 10, 2);

This will prevent the user inserting new terms but allow them to search and add existing terms to a post.

Beaware that when on the post edit screen a user can enter in a term name that does not exist and press enter or click the add button which will add the term to the DOM however at this point the term is not added to the database until the user publishes or updates the post at which point the term will be disallowed.

Leave a Comment