wppaste
WordPress

WP_REST_Menu_Items_Controller

Since
5.9.0
Source
wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php:17
Core class to access nav items 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 · 9

Every hook that fires from inside WP_REST_Menu_Items_Controller, in the order it appears in the class, grouped by the method that fires it.

Methods · 15

Source code

class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller { 	/**	 * Gets the nav menu item, if the ID is valid.	 *	 * @since 5.9.0	 *	 * @param int $id Supplied ID.	 * @return object|WP_Error Post object if ID is valid, WP_Error otherwise.	 */	protected function get_nav_menu_item( $id ) {		$post = $this->get_post( $id );		if ( is_wp_error( $post ) ) {			return $post;		} 		return wp_setup_nav_menu_item( $post );	} 	/**	 * Checks if a given request has access to read menu items.	 *	 * @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, WP_Error object otherwise.	 */	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 given request has access to read a menu item if they have access to edit them.	 *	 * @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 for the item, WP_Error object or false otherwise.	 */	public function get_item_permissions_check( $request ) {		$permission_check = parent::get_item_permissions_check( $request ); 		if ( true !== $permission_check ) {			return $permission_check;		} 		return $this->check_has_read_only_access( $request );	} 	/**	 * 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 request has read access for the item, WP_Error object otherwise.	 */	protected function check_has_read_only_access( $request ) {		/**		 * Filters whether the current user has read access to menu items via the REST API.		 *		 * @since 6.8.0		 *		 * @param bool               $read_only_access Whether the current user has read access to menu items		 *                                             via the REST API.		 * @param WP_REST_Request    $request          Full details about the request.		 * @param WP_REST_Controller $controller       The current instance of the controller.		 */		$read_only_access = apply_filters( 'rest_menu_read_access', false, $request, $this );		if ( $read_only_access ) {			return true;		}

Changelog

Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-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.