Resolves the capability required to read the view config for an entity.
Description
Known kinds map to the capability that gates managing that entity’s list: post types use their own edit_posts capability (which honors custom capability_type registrations), taxonomies use manage_terms, and root-level entities use manage_options. A post type or taxonomy that is not registered, or not exposed to the REST API, resolves to null so the request is treated as referencing an unknown entity.
Any other kind falls back to edit_posts. This keeps entities registered through the get_entity_view_config_{$kind}_{$name} filter readable behind a baseline capability.
Parameters
$kindstringrequired- The entity kind (e.g.
postType). $namestringrequired- The entity name (e.g.
page).
Source
protected function get_required_capability( $kind, $name ) {
switch ( $kind ) {
case 'postType':
$post_type = get_post_type_object( $name );
if ( $post_type && $post_type->show_in_rest ) {
return $post_type->cap->edit_posts;
}
return null;
case 'taxonomy':
$taxonomy = get_taxonomy( $name );
if ( $taxonomy && $taxonomy->show_in_rest ) {
return $taxonomy->cap->manage_terms;
}
return null;
case 'root':
return 'manage_options';
}
return 'edit_posts';
}
Changelog
| Version | Description |
|---|---|
| 7.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.