/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/e2e-test-utils-playwright/src/request-utils/blocks.ts
55 строк
1 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import type { RequestUtils } from './index'; type CreateBlockPayload = { date?: string; date_gmt?: string; slug?: string; title: string; status: 'publish' | 'future' | 'draft' | 'pending' | 'private'; content?: string; meta?: unknown; wp_pattern_category?: number[]; }; /** * Delete all blocks using REST API. * * @see https://developer.wordpress.org/rest-api/reference/blocks/#list-editor-blocks * @param this */ export async function deleteAllBlocks( this: RequestUtils ) { // List all blocks. // https://developer.wordpress.org/rest-api/reference/blocks/#list-editor-blocks const blocks = await this.rest( { path: '/wp/v2/blocks', params: { per_page: 100, // All possible statuses. status: 'publish,future,draft,pending,private,trash', }, } ); // Delete blocks. // https://developer.wordpress.org/rest-api/reference/blocks/#delete-a-editor-block // "/wp/v2/posts" not yet supports batch requests. await this.batchRest( blocks.map( ( block: { id: number } ) => ( { method: 'DELETE', path: `/wp/v2/blocks/${ block.id }?force=true`, } ) ) ); } /** * Creates a new block using the REST API. * * @see https://developer.wordpress.org/rest-api/reference/blocks/#create-a-editor-block. * @param this * @param payload Block payload. */ export async function createBlock( this: RequestUtils, payload: CreateBlockPayload ) { return this.createRecord( 'blocks', { ...payload } ); }