WP_REST_View_Config_Controller::get_required_capability
Resolves the capability required to read the view config for an entity.
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.
Method of the class: WP_REST_View_Config_Controller{}
No Hooks.
Returns
string|null. Capability required to read the config, or null if the entity is not registered.
Usage
// protected - for code of main (parent) or child class $result = $this->get_required_capability( $kind, $name );
- $kind(string) (required)
- The entity kind (e.g.
postType). - $name(string) (required)
- The entity name (e.g.
page).
Changelog
| Since 7.1.0 | Introduced. |
WP_REST_View_Config_Controller::get_required_capability() WP REST View Config Controller::get required capability code WP 7.1.5
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';
}