set_data example

do_action( 'rest_delete_revision', $result$request );

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

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

    /** * Determines the allowed query_vars for a get_items() response and prepares * them for WP_Query. * * @since 5.0.0 * * @param array $prepared_args Optional. Prepared WP_Query arguments. Default empty array. * @param WP_REST_Request $request Optional. Full details about the request. * @return array Items query arguments. */
array( 'status' => rest_authorization_required_code() )
            );
        }

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

        // If we're forcing, then delete permanently.         if ( $force ) {
            $previous = $this->prepare_item_for_response( $post$request );
            $result   = wp_delete_post( $id, true );
            $response = new WP_REST_Response();
            $response->set_data(
                array(
                    'deleted'  => true,
                    'previous' => $previous->get_data(),
                )
            );
        } else {
            // If we don't support trashing for this type, error out.             if ( ! $supports_trash ) {
                return new WP_Error(
                    'rest_trash_not_supported',
                    /* translators: %s: force=true */
                    
$result = wp_delete_user( $id$reassign );

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

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

        /** * Fires immediately after a user is deleted via the REST API. * * @since 4.7.0 * * @param WP_User $user The user data. * @param WP_REST_Response $response The response returned from the API. * @param WP_REST_Request $request The request sent to the API. */
$id    = $template->wp_id;
        $force = (bool) $request['force'];

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

        // If we're forcing, then delete permanently.         if ( $force ) {
            $previous = $this->prepare_item_for_response( $template$request );
            $result   = wp_delete_post( $id, true );
            $response = new WP_REST_Response();
            $response->set_data(
                array(
                    'deleted'  => true,
                    'previous' => $previous->get_data(),
                )
            );
        } else {
            // Otherwise, only trash if we haven't already.             if ( 'trash' === $template->status ) {
                return new WP_Error(
                    'rest_template_already_trashed',
                    __( 'The template has already been deleted.' ),
                    
if ( $widget_object ) {
                /* * WP_Widget sets `updated = true` after an update to prevent more than one widget * from being saved per request. This isn't what we want in the REST API, though, * as we support batch requests. */
                $widget_object->updated = false;
            }

            wp_assign_widget_to_sidebar( $widget_id, '' );

            $response->set_data(
                array(
                    'deleted'  => true,
                    'previous' => $response->get_data(),
                )
            );
        } else {
            wp_assign_widget_to_sidebar( $widget_id, 'wp_inactive_widgets' );

            $response = $this->prepare_item_for_response(
                array(
                    'sidebar_id' => 'wp_inactive_widgets',
                    
/** * Constructor. * * @since 4.4.0 * * @param mixed $data Response data. Default null. * @param int $status Optional. HTTP status code. Default 200. * @param array $headers Optional. HTTP header map. Default empty array. */
    public function __construct( $data = null, $status = 200, $headers = array() ) {
        $this->set_data( $data );
        $this->set_status( $status );
        $this->set_headers( $headers );
    }

    /** * Retrieves headers associated with the response. * * @since 4.4.0 * * @return array Map of header name to header value. */
    
$retval = wp_delete_term( $term->term_id, $term->taxonomy );

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

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

        /** * Fires after a single term is deleted via the REST API. * * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug. * * Possible hook names include: * * - `rest_delete_category` * - `rest_delete_post_tag` * * @since 4.7.0 * * @param WP_Term $term The deleted term. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. */

        $supports_trash = apply_filters( 'rest_comment_trashable', ( EMPTY_TRASH_DAYS > 0 )$comment );

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

        if ( $force ) {
            $previous = $this->prepare_item_for_response( $comment$request );
            $result   = wp_delete_comment( $comment->comment_ID, true );
            $response = new WP_REST_Response();
            $response->set_data(
                array(
                    'deleted'  => true,
                    'previous' => $previous->get_data(),
                )
            );
        } else {
            // If this type doesn't support trashing, error out.             if ( ! $supports_trash ) {
                return new WP_Error(
                    'rest_trash_not_supported',
                    /* translators: %s: force=true */
                    
            unset( $args[0] );

            $request->set_url_params( $args );
            $request->set_attributes( $endpoint );
        }

        $data = $handler->get_data_for_route( $route$endpoints, 'help' );
        $response->set_matched_route( $route );
        break;
    }

    $response->set_data( $data );
    return $response;
}

/** * Sends the "Allow" header to state all methods that can be sent to the current route. * * @since 4.4.0 * * @param WP_REST_Response $response Current response being served. * @param WP_REST_Server $server ResponseHandler instance (usually WP_REST_Server). * @param WP_REST_Request $request The request that was used to make current response. * @return WP_REST_Response Response to be served, with "Allow" header if route has allowed methods. */


        $previous = $this->prepare_item_for_response( get_post( $request['id'] )$request );

        $result = wp_delete_post( $request['id'], true );

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

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

        /** * Fires immediately after a single menu item is deleted via the REST API. * * @since 5.9.0 * * @param object $nav_menu_item Inserted or updated menu item object. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request Request object. */
$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;
    }

    
Home | Imprint | This part of the site doesn't use cookies.