this filter modifies the answer of the api route wp/v2/taxonomies when gutenberg request it.
it relies on the http header Referer which is set by the client. then, there is no security checks, it’s only a cosmetic customisation.
add_filter("rest_prepare_taxonomy", function ($response, $taxonomy, $request) {
if ("bundles" === $taxonomy->name) {
// searching the post id
preg_match(
"#wp-admin/post\.php\?post=(\d*)&action=edit#"
, $_SERVER["HTTP_REFERER"]
, $found
);
if (isset($found[1])) {
$id_post = $found[1];
$post = get_post($id_post);
$author_can_assign_bundles = user_can(
$post->post_author
, $taxonomy->cap->assign_terms
, ["post" => $post]
);
if (!$author_can_assign_bundles) {
// remove all post types associated with bundles
// in this rest answer
$response->data["types"] = [];
}
}
}
return $response;
}, 10, 3);