WP_REST_Menus_Controller::delete_item() – Deletes a single term from a taxonomy.

You appear to be a bot. Output may be restricted

Description

Deletes a single term from a taxonomy.

Usage

$WP_REST_Response|WP_Error = WP_REST_Menus_Controller::delete_item( $request );

Parameters

$request
( WP_REST_Request ) required – Full details about the request.

Returns

WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.

Source

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


Lines:

1 to 37 of 37
  public function delete_item( $request ) {
    $term = $this->get_term( $request['id'] );
    if ( is_wp_error( $term ) ) {
      return $term;
    }

    // We don't support trashing for terms.
    if ( ! $request['force'] ) {
      /* translators: %s: force=true */
      return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Menus do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) );
    }

    $request->set_param( 'context', 'view' );

    $previous = $this->prepare_item_for_response( $term, $request );

    $result = wp_delete_nav_menu( $term );

    if ( ! $result || is_wp_error( $result ) ) {
      return new WP_Error( 'rest_cannot_delete', __( 'The menu cannot be deleted.' ), array( 'status' => 500 ) );
    }

    $response = new WP_REST_Response();
    $response->set_data(
      array(
        'deleted'  => true,
        'previous' => $previous->get_data(),
      )
    );

    
/** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */
    do_action( "rest_delete_{$this->taxonomy}", $term, $response, $request );

    return $response;
  }
 

 View on GitHub View on Trac