wp_update_image_subsizes example


    if ( ! headers_sent() ) {
        header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id );
    }

    /* * This can still be pretty slow and cause timeout or out of memory errors. * The js that handles the response would need to also handle HTTP 500 errors. */
    wp_update_image_subsizes( $attachment_id );

    if ( ! empty( $_POST['_legacy_support'] ) ) {
        // The old (inline) uploader. Only needs the attachment_id.         $response = array( 'id' => $attachment_id );
    } else {
        // Media modal and Media Library grid view.         $response = wp_prepare_attachment_for_js( $attachment_id );

        if ( ! $response ) {
            wp_send_json_error( array( 'message' => __( 'Upload failed.' ) ) );
        }
    }

    public function post_process_item( $request ) {
        switch ( $request['action'] ) {
            case 'create-image-subsizes':
                require_once ABSPATH . 'wp-admin/includes/image.php';
                wp_update_image_subsizes( $request['id'] );
                break;
        }

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

        return $this->prepare_item_for_response( get_post( $request['id'] )$request );
    }

    /** * Checks if a given request can perform post processing on an attachment. * * @since 5.3.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. */
Home | Imprint | This part of the site doesn't use cookies.