Multiple users – only allow them to manage their own terms for custom taxonomy when logged in

Thanks for the AWESOME solution MikeSchinkel 😀

I just did the following updates in the code and it worked like a charm:

add_filter('list_terms_exclusions', 'yoursite_list_terms_exclusions', 10, 2);

function yoursite_list_terms_exclusions( $exclusions ) {
    $currentScreen = get_current_screen();

    if( current_user_can( 'my_custom_capability_assigned_to_specific_users' )
            && !current_user_can( 'manage_options' ) // Show everything to Admin
            && is_object( $currentScreen )
            && $currentScreen->id == 'edit-<my_taxonomy>'
            && $currentScreen->taxonomy == '<my_taxonomy>' ) {
        // Get term_id's array that you want to show as per your requirement
        $terms      = implode( ',', $term_id );
        $exclusions = ( empty( $exclusions ) ? '' : $exclusions ) . ' AND' . ' t.`term_id` IN (' . $terms . ')';
    }
    return $exclusions;
}

Leave a Comment