WP_REST_Menus_Controller
- Since
- 5.9.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php:17
Core class used to managed menu terms associated via the REST API.
Compatibility
- WordPress
- since 5.9.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 8
Every hook that fires from inside WP_REST_Menus_Controller, in the order it appears in the class, grouped by the method that fires it.
WP_REST_Menus_Controller::check_has_read_only_access()
- apply_filters( rest_menu_read_access )filter line 88
WP_REST_Menus_Controller::prepare_item_for_response()
- apply_filters( rest_prepare_{$this->taxonomy} )filter line 149
WP_REST_Menus_Controller::create_item()
- do_action( rest_insert_{$this->taxonomy} )action line 246
- do_action( rest_after_insert_{$this->taxonomy} )action line 274
Methods · 15
- get_items_permissions_check()Checks if a request has access to read menus.
- get_item_permissions_check()Checks if a request has access to read or edit the specified menu.
- get_term()Gets the term, if the ID is valid.
- check_has_read_only_access()Checks whether the current user has read permission for the endpoint.
- prepare_item_for_response()Prepares a single term output for response.
- prepare_links()Prepares links for the request.
- prepare_item_for_database()Prepares a single term for create or update.
- create_item()Creates a single term in a taxonomy.
- update_item()Updates a single term from a taxonomy.
- delete_item()Deletes a single term from a taxonomy.
- get_menu_auto_add()Returns the value of a menu's auto_add setting.
- handle_auto_add()Updates the menu's auto add from a REST request.
- get_menu_locations()Returns the names of the locations assigned to the menu.
- handle_locations()Updates the menu's locations from a REST request.
- get_item_schema()Retrieves the term's schema, conforming to JSON Schema.
Source code
class WP_REST_Menus_Controller extends WP_REST_Terms_Controller { /** * Checks if a request has access to read menus. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return bool|WP_Error True if the request has read access, otherwise false or WP_Error object. */ public function get_items_permissions_check( $request ) { $has_permission = parent::get_items_permissions_check( $request ); if ( true !== $has_permission ) { return $has_permission; } return $this->check_has_read_only_access( $request ); } /** * Checks if a request has access to read or edit the specified menu. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access for the item, otherwise WP_Error object. */ public function get_item_permissions_check( $request ) { $has_permission = parent::get_item_permissions_check( $request ); if ( true !== $has_permission ) { return $has_permission; } return $this->check_has_read_only_access( $request ); } /** * Gets the term, if the ID is valid. * * @since 5.9.0 * * @param int $id Supplied ID. * @return WP_Term|WP_Error Term object if ID is valid, WP_Error otherwise. */ protected function get_term( $id ) { $term = parent::get_term( $id ); if ( is_wp_error( $term ) ) { return $term; } $nav_term = wp_get_nav_menu_object( $term ); $nav_term->auto_add = $this->get_menu_auto_add( $nav_term->term_id ); return $nav_term; } /** * Checks whether the current user has read permission for the endpoint. * * This allows for any user that can `edit_theme_options` or edit any REST API available post type. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the current user has permission, WP_Error object otherwise. */ protected function check_has_read_only_access( $request ) { /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php */ $read_only_access = apply_filters( 'rest_menu_read_access', false, $request, $this ); if ( $read_only_access ) { return true; } if ( current_user_can( 'edit_theme_options' ) ) { return true; }Changelog
Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.