Allow user only create specific tags

Question

I am using an editorial wordpress theme that has a frontend post editor for a user (contributor) to create a post. The editor is giving permission to the user to choose category for the article and to add tags.

How can i allow the user to only be able to add the tags that i want. For examlpe ‘exodus’ ‘holidays’ . Dont need to create any msg for the user. Just allow to register in the database only those specific tags.

I found something very similur in this post and it works fine from the backend post editor, but from the front it doesn’t.

function disallow_insert_term($term, $taxonomy) {

$user = wp_get_current_user();

if ( $taxonomy === 'post_tag' && in_array('contributor', $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);

*(Note that the contributor can not publish, only send for approval an article. But when i publish the article i don’t get any tags.)

So basically i am searching for a filter the allows only specific tags to be added to the database when a user starts typing tags.

0
, , , Honoluluman 4 years 2020-03-25T12:50:56-05:00 0 Answers 115 views 0

Leave an answer

Browse
Browse