WP_REST_Menus_Controller::handle_auto_add() – Updates the menu’s auto add from a REST request.

You appear to be a bot. Output may be restricted

Description

Updates the menu's auto add from a REST request.

Usage

$bool = WP_REST_Menus_Controller::handle_auto_add( $menu_id, $request );

Parameters

$menu_id
( int ) required – The menu id to update.
$request
( WP_REST_Request ) required – Full details about the request.

Returns

bool True if the auto add setting was successfully updated.

Source

File name: wordpress/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php


Lines:

1 to 30 of 30
  protected function handle_auto_add( $menu_id, $request ) {
    if ( ! isset( $request['auto_add'] ) ) {
      return true;
    }

    $nav_menu_option = (array) get_option( 'nav_menu_options', array( 'auto_add' => array() ) );

    if ( ! isset( $nav_menu_option['auto_add'] ) ) {
      $nav_menu_option['auto_add'] = array();
    }

    $auto_add = $request['auto_add'];

    $i = array_search( $menu_id, $nav_menu_option['auto_add'], true );

    if ( $auto_add && false === $i ) {
      $nav_menu_option['auto_add'][] = $menu_id;
    } elseif ( ! $auto_add && false !== $i ) {
      array_splice( $nav_menu_option['auto_add'], $i, 1 );
    }

    $update = update_option( 'nav_menu_options', $nav_menu_option );

    
/** This action is documented in wp-includes/nav-menu.php */
    do_action( 'wp_update_nav_menu', $menu_id );

    return $update;
  }
 

 View on GitHub View on Trac