: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @param {string} attachmentId
* @return {Promise<any>} Processed post response.
const postProcess = attachmentId => {
path: `/wp/v2/media/${attachmentId}/post-process`,
action: 'create-image-subsizes'
if (retries < maxRetries) {
return postProcess(attachmentId);
path: `/wp/v2/media/${attachmentId}?force=true`,
const attachmentId = response.headers.get('x-wp-upload-attachment-id');
if (response.status >= 500 && response.status < 600 && attachmentId) {
return postProcess(attachmentId).catch(() => {
if (options.parse !== false) {
message: (0,external_wp_i18n_namespaceObject.__)('Media upload failed. If this is a photo or a large image, please scale it down and try again.')
return Promise.reject(response);
return parseAndThrowError(response, options.parse);
}).then(response => parseResponseAndNormalizeError(response, options.parse));
/* harmony default export */ const media_upload = (mediaUploadMiddleware);
;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/theme-preview.js
* This appends a `wp_theme_preview` parameter to the REST API request URL if
* the admin URL contains a `theme` GET parameter.
* If the REST API request URL has contained the `wp_theme_preview` parameter as `''`,
* then bypass this middleware.
* @param {Record<string, any>} themePath
* @return {import('../types').APIFetchMiddleware} Preloading middleware.
const createThemePreviewMiddleware = themePath => (options, next) => {
if (typeof options.url === 'string') {
const wpThemePreview = (0,external_wp_url_namespaceObject.getQueryArg)(options.url, 'wp_theme_preview');
if (wpThemePreview === undefined) {
options.url = (0,external_wp_url_namespaceObject.addQueryArgs)(options.url, {
wp_theme_preview: themePath
} else if (wpThemePreview === '') {
options.url = (0,external_wp_url_namespaceObject.removeQueryArgs)(options.url, 'wp_theme_preview');
if (typeof options.path === 'string') {
const wpThemePreview = (0,external_wp_url_namespaceObject.getQueryArg)(options.path, 'wp_theme_preview');
if (wpThemePreview === undefined) {
options.path = (0,external_wp_url_namespaceObject.addQueryArgs)(options.path, {
wp_theme_preview: themePath
} else if (wpThemePreview === '') {
options.path = (0,external_wp_url_namespaceObject.removeQueryArgs)(options.path, 'wp_theme_preview');
/* harmony default export */ const theme_preview = (createThemePreviewMiddleware);
;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/index.js
* Default set of header values which should be sent with every request unless
* explicitly provided through apiFetch options.
* @type {Record<string, string>}
const DEFAULT_HEADERS = {
// The backend uses the Accept header as a condition for considering an
// incoming request as a REST request.
// See: https://core.trac.wordpress.org/ticket/44534
Accept: 'application/json, */*;q=0.1'
* Default set of fetch option values which should be sent with every request
* unless explicitly provided through apiFetch options.
const DEFAULT_OPTIONS = {
/** @typedef {import('./types').APIFetchMiddleware} APIFetchMiddleware */
/** @typedef {import('./types').APIFetchOptions} APIFetchOptions */
* @type {import('./types').APIFetchMiddleware[]}
const middlewares = [user_locale, namespace_endpoint, http_v1, fetch_all_middleware];
* @param {import('./types').APIFetchMiddleware} middleware
function registerMiddleware(middleware) {
middlewares.unshift(middleware);
* Checks the status of a response, throwing the Response as an error if
* it is outside the 200 range.
* @param {Response} response
* @return {Response} The response if the status is in the 200 range.
const checkStatus = response => {
if (response.status >= 200 && response.status < 300) {
/** @typedef {(options: import('./types').APIFetchOptions) => Promise<any>} FetchHandler*/
const defaultFetchHandler = nextOptions => {
// Merge explicitly-provided headers with default values.
// The `data` property is a shorthand for sending a JSON body.
body = JSON.stringify(data);
headers['Content-Type'] = 'application/json';
const responsePromise = window.fetch(
// Fall back to explicitly passing `window.location` which is the behavior if `undefined` is passed.
url || path || window.location.href, {
return responsePromise.then(value => Promise.resolve(value).then(checkStatus).catch(response => parseAndThrowError(response, parse)).then(response => parseResponseAndNormalizeError(response, parse)), err => {
// Re-throw AbortError for the users to handle it themselves.
if (err && err.name === 'AbortError') {
// Otherwise, there is most likely no network connection.
// Unfortunately the message might depend on the browser.
message: (0,external_wp_i18n_namespaceObject.__)('You are probably offline.')
/** @type {FetchHandler} */
let fetchHandler = defaultFetchHandler;
* Defines a custom fetch handler for making the requests that will override
* the default one using window.fetch
* @param {FetchHandler} newFetchHandler The new fetch handler
function setFetchHandler(newFetchHandler) {
fetchHandler = newFetchHandler;
* @param {import('./types').APIFetchOptions} options
* @return {Promise<T>} A promise representing the request processed via the registered middlewares.
function apiFetch(options) {
// creates a nested function chain that calls all middlewares and finally the `fetchHandler`,
// converting `middlewares = [ m1, m2, m3 ]` into:
// opts1 => m1( opts1, opts2 => m2( opts2, opts3 => m3( opts3, fetchHandler ) ) );
const enhancedHandler = middlewares.reduceRight(( /** @type {FetchHandler} */next, middleware) => {
return workingOptions => middleware(workingOptions, next);
return enhancedHandler(options).catch(error => {
if (error.code !== 'rest_cookie_invalid_nonce') {
return Promise.reject(error);
// If the nonce is invalid, refresh it and try again.
.fetch(apiFetch.nonceEndpoint).then(checkStatus).then(data => data.text()).then(text => {
apiFetch.nonceMiddleware.nonce = text;
return apiFetch(options);
apiFetch.use = registerMiddleware;
apiFetch.setFetchHandler = setFetchHandler;
apiFetch.createNonceMiddleware = nonce;
apiFetch.createPreloadingMiddleware = preloading;
apiFetch.createRootURLMiddleware = root_url;
apiFetch.fetchAllMiddleware = fetch_all_middleware;
apiFetch.mediaUploadMiddleware = media_upload;
apiFetch.createThemePreviewMiddleware = theme_preview;
/* harmony default export */ const build_module = (apiFetch);
(window.wp = window.wp || {}).apiFetch = __webpack_exports__["default"];