@wordpress/core-data
Version:
Access to and manipulation of core WordPress entities.
23 lines (20 loc) • 627 B
JavaScript
import { camelCase } from 'change-case';
import apiFetch from '@wordpress/api-fetch';
export { default as __experimentalFetchLinkSuggestions } from './__experimental-fetch-link-suggestions';
export { default as __experimentalFetchUrlData } from './__experimental-fetch-url-data';
export async function fetchBlockPatterns() {
const restPatterns = await apiFetch( {
path: '/wp/v2/block-patterns/patterns',
} );
if ( ! restPatterns ) {
return [];
}
return restPatterns.map( ( pattern ) =>
Object.fromEntries(
Object.entries( pattern ).map( ( [ key, value ] ) => [
camelCase( key ),
value,
] )
)
);
}