set_status example


    protected function json_error( $code$message$status = null ) {
        if ( $status ) {
            $this->set_status( $status );
        }

        $error = compact( 'code', 'message' );

        return wp_json_encode( $error );
    }

    /** * Gets the encoding options passed to {@see wp_json_encode}. * * @since 6.1.0 * * @param \WP_REST_Request $request The current request object. * * @return int The JSON encode options. */

        do_action( "rest_after_insert_{$this->post_type}", $post$request, true );

        wp_after_insert_post( $post, false, null );

        $response = $this->prepare_item_for_response( $post$request );
        $response = rest_ensure_response( $response );

        $response->set_status( 201 );
        $response->header( 'Location', rest_url( rest_get_route_for_post( $post ) ) );

        return $response;
    }

    /** * Checks if a given request has access to update a post. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. */

        do_action( 'rest_after_insert_application_password', $item$request, true );

        $request->set_param( 'context', 'edit' );
        $response = $this->prepare_item_for_response( $item$request );

        $response->set_status( 201 );
        $response->header( 'Location', $response->get_links()['self'][0]['href'] );

        return $response;
    }

    /** * Checks if a given request has access to update application passwords. * * @since 5.6.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise. */
return $fields_update;
        }

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

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

        $response = $this->prepare_item_for_response( $term$request );
        $response = rest_ensure_response( $response );

        $response->set_status( 201 );
        $response->header( 'Location', rest_url( $this->namespace . '/' . $this->rest_base . '/' . $term->term_id ) );

        return $response;
    }

    /** * Updates a single term from a taxonomy. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */

        do_action( 'rest_after_insert_comment', $comment$request, true );

        $response = $this->prepare_item_for_response( $comment$request );
        $response = rest_ensure_response( $response );

        $response->set_status( 201 );
        $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment_id ) ) );

        return $response;
    }

    /** * Checks if a given REST request has access to update a comment. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has access to update the item, error object otherwise. */
wp_assign_widget_to_sidebar( $widget_id$sidebar_id );

        $request['context'] = 'edit';

        $response = $this->prepare_item_for_response( compact( 'sidebar_id', 'widget_id' )$request );

        if ( is_wp_error( $response ) ) {
            return $response;
        }

        $response->set_status( 201 );

        return $response;
    }

    /** * Checks if a given request has access to update widgets. * * @since 5.8.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. */

        do_action( "rest_after_insert_{$this->taxonomy}", $term$request, true );

        $response = $this->prepare_item_for_response( $term$request );
        $response = rest_ensure_response( $response );

        $response->set_status( 201 );
        $response->header( 'Location', rest_url( $this->namespace . '/' . $this->rest_base . '/' . $term->term_id ) );

        return $response;
    }

    /** * Checks if a request has access to update the specified term. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has access to update the item, false or WP_Error object otherwise. */
$lp_upgrader = new Language_Pack_Upgrader( $skin );

            // Install all applicable language packs for the plugin.             $lp_upgrader->bulk_upgrade( $language_packs );
        }

        $path          = WP_PLUGIN_DIR . '/' . $file;
        $data          = get_plugin_data( $path, false, false );
        $data['_file'] = $file;

        $response = $this->prepare_item_for_response( $data$request );
        $response->set_status( 201 );
        $response->header( 'Location', rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, substr( $file, 0, - 4 ) ) ) );

        return $response;
    }

    /** * Checks if a given request has access to update a specific plugin. * * @since 5.5.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. */

        do_action( 'rest_after_insert_nav_menu_item', $nav_menu_item$request, true );

        $post = get_post( $nav_menu_item_id );
        wp_after_insert_post( $post, false, null );

        $response = $this->prepare_item_for_response( $post$request );
        $response = rest_ensure_response( $response );

        $response->set_status( 201 );
        $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $nav_menu_item_id ) ) );

        return $response;
    }

    /** * Updates a single nav menu item. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */

        do_action( 'rest_after_insert_user', $user$request, true );

        $response = $this->prepare_item_for_response( $user$request );
        $response = rest_ensure_response( $response );

        $response->set_status( 201 );
        $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $user_id ) ) );

        return $response;
    }

    /** * Checks if a given request has access to update a user. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. */
/** * 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. */
    public function get_headers() {
        
        require_once ABSPATH . 'wp-admin/includes/media.php';
        require_once ABSPATH . 'wp-admin/includes/image.php';

        /* * Post-process the upload (create image sub-sizes, make PDF thumbnails, etc.) and insert attachment meta. * At this point the server may run out of resources and post-processing of uploaded images may fail. */
        wp_update_attachment_metadata( $attachment_idwp_generate_attachment_metadata( $attachment_id$file ) );

        $response = $this->prepare_item_for_response( $attachment$request );
        $response = rest_ensure_response( $response );
        $response->set_status( 201 );
        $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $attachment_id ) ) );

        return $response;
    }

    /** * Inserts the attachment post in the database. Does not update the attachment meta. * * @since 5.3.0 * * @param WP_REST_Request $request * @return array|WP_Error */
return $fields_update;
        }

        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
        do_action( "rest_after_insert_{$this->post_type}", $post$request, true );

        wp_after_insert_post( $post, false, null );

        $response = $this->prepare_item_for_response( $template$request );
        $response = rest_ensure_response( $response );

        $response->set_status( 201 );
        $response->header( 'Location', rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $template->id ) ) );

        return $response;
    }

    /** * Checks if a given request has access to delete a single template. * * @since 5.8.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has delete access for the item, WP_Error object otherwise. */
Home | Imprint | This part of the site doesn't use cookies.