: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if (errorMessages.size === 0) {
errorMessage = (0,external_wp_i18n_namespaceObject.__)('An error occurred while permanently deleting the posts.');
} else if (errorMessages.size === 1) {
errorMessage = (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: an error message */
(0,external_wp_i18n_namespaceObject.__)('An error occurred while permanently deleting the posts: %s'), [...errorMessages][0]);
errorMessage = (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: a list of comma separated error messages */
(0,external_wp_i18n_namespaceObject.__)('Some errors occurred while permanently deleting the posts: %s'), [...errorMessages].join(','));
createErrorNotice(errorMessage, {
}), [createSuccessNotice, createErrorNotice, deleteEntityRecord]);
return useCanUserEligibilityCheckPostType('delete', resource, permanentlyDeletePostAction);
function useRestorePostAction(resource) {
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store);
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_coreData_namespaceObject.store);
const restorePostAction = (0,external_wp_element_namespaceObject.useMemo)(() => ({
label: (0,external_wp_i18n_namespaceObject.__)('Restore'),
return status === 'trash';
async callback(posts, onActionPerformed) {
await Promise.allSettled(posts.map(post => {
return editEntityRecord('postType', post.type, post.id, {
const promiseResult = await Promise.allSettled(posts.map(post => {
return saveEditedEntityRecord('postType', post.type, post.id, {
if (promiseResult.every(({
}) => status === 'fulfilled')) {
if (posts.length === 1) {
successMessage = (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: The number of posts. */
(0,external_wp_i18n_namespaceObject.__)('"%s" has been restored.'), getItemTitle(posts[0]));
} else if (posts[0].type === 'page') {
successMessage = (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: The number of posts. */
(0,external_wp_i18n_namespaceObject.__)('%d pages have been restored.'), posts.length);
successMessage = (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: The number of posts. */
(0,external_wp_i18n_namespaceObject.__)('%d posts have been restored.'), posts.length);
createSuccessNotice(successMessage, {
id: 'restore-post-action'
onActionPerformed(posts);
// If there was at lease one failure.
// If we were trying to move a single post to the trash.
if (promiseResult.length === 1) {
if (promiseResult[0].reason?.message) {
errorMessage = promiseResult[0].reason.message;
errorMessage = (0,external_wp_i18n_namespaceObject.__)('An error occurred while restoring the post.');
// If we were trying to move multiple posts to the trash
const errorMessages = new Set();
const failedPromises = promiseResult.filter(({
}) => status === 'rejected');
for (const failedPromise of failedPromises) {
if (failedPromise.reason?.message) {
errorMessages.add(failedPromise.reason.message);
if (errorMessages.size === 0) {
errorMessage = (0,external_wp_i18n_namespaceObject.__)('An error occurred while restoring the posts.');
} else if (errorMessages.size === 1) {
errorMessage = (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: an error message */
(0,external_wp_i18n_namespaceObject.__)('An error occurred while restoring the posts: %s'), [...errorMessages][0]);
errorMessage = (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: a list of comma separated error messages */
(0,external_wp_i18n_namespaceObject.__)('Some errors occurred while restoring the posts: %s'), [...errorMessages].join(','));
createErrorNotice(errorMessage, {
}), [createSuccessNotice, createErrorNotice, editEntityRecord, saveEditedEntityRecord]);
return useCanUserEligibilityCheckPostType('update', resource, restorePostAction);
label: (0,external_wp_i18n_namespaceObject.__)('View'),
return post.status !== 'trash';
callback(posts, onActionPerformed) {
window.open(post.link, '_blank');
onActionPerformed(posts);
const postRevisionsAction = {
id: 'view-post-revisions',
var _items$0$_links$versi;
const revisionsCount = (_items$0$_links$versi = items[0]._links?.['version-history']?.[0]?.count) !== null && _items$0$_links$versi !== void 0 ? _items$0$_links$versi : 0;
return (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: number of revisions */
(0,external_wp_i18n_namespaceObject.__)('View revisions (%s)'), revisionsCount);
var _post$_links$predeces, _post$_links$version;
if (post.status === 'trash') {
const lastRevisionId = (_post$_links$predeces = post?._links?.['predecessor-version']?.[0]?.id) !== null && _post$_links$predeces !== void 0 ? _post$_links$predeces : null;
const revisionsCount = (_post$_links$version = post?._links?.['version-history']?.[0]?.count) !== null && _post$_links$version !== void 0 ? _post$_links$version : 0;
return lastRevisionId && revisionsCount > 1;
callback(posts, onActionPerformed) {
const href = (0,external_wp_url_namespaceObject.addQueryArgs)('revision.php', {
revision: post?._links?.['predecessor-version']?.[0]?.id
document.location.href = href;
onActionPerformed(posts);
const renamePostAction = {
label: (0,external_wp_i18n_namespaceObject.__)('Rename'),
if (post.status === 'trash') {
// Templates, template parts and patterns have special checks for renaming.
if (![TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE, ...Object.values(actions_PATTERN_TYPES)].includes(post.type)) {
// In the case of templates, we can only rename custom templates.
if (post.type === TEMPLATE_POST_TYPE) {
return isTemplateRemovable(post) && post.is_custom;
// Make necessary checks for template parts and patterns.
const isTemplatePart = post.type === TEMPLATE_PART_POST_TYPE;
const isUserPattern = post.type === actions_PATTERN_TYPES.user;
// In patterns list page we map the templates parts to a different object
// than the one returned from the endpoint. This is why we need to check for
// two props whether is custom or has a theme file.
const isCustomPattern = isUserPattern || isTemplatePart && (post.isCustom || post.source === TEMPLATE_ORIGINS.custom);
const hasThemeFile = isTemplatePart && (post.templatePart?.has_theme_file || post.has_theme_file);
return isCustomPattern && !hasThemeFile;
const originalTitle = (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(typeof item.title === 'string' ? item.title : item.title.rendered);
const [title, setTitle] = (0,external_wp_element_namespaceObject.useState)(() => originalTitle);
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_coreData_namespaceObject.store);
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store);
async function onRename(event) {
await editEntityRecord('postType', item.type, item.id, {
// Update state before saving rerenders the list.
// Persist edited entity.
await saveEditedEntityRecord('postType', item.type, item.id, {
createSuccessNotice((0,external_wp_i18n_namespaceObject.__)('Name updated'), {
onActionPerformed?.(items);
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : (0,external_wp_i18n_namespaceObject.__)('An error occurred while updating the name');
createErrorNotice(errorMessage, {
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("form", {
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.__experimentalVStack, {
children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.TextControl, {
__nextHasNoMarginBottom: true,
__next40pxDefaultSize: true,
label: (0,external_wp_i18n_namespaceObject.__)('Name'),
}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.__experimentalHStack, {
children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
__next40pxDefaultSize: true,
children: (0,external_wp_i18n_namespaceObject.__)('Cancel')
}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
__next40pxDefaultSize: true,
children: (0,external_wp_i18n_namespaceObject.__)('Save')
function useRenamePostAction(resource) {
return useCanUserEligibilityCheckPostType('update', resource, renamePostAction);
const duplicatePostAction = {
label: (0,external_wp_i18n_namespaceObject._x)('Duplicate', 'action label'),
return status !== 'trash';
const [isCreatingPage, setIsCreatingPage] = (0,external_wp_element_namespaceObject.useState)(false);
const [title, setTitle] = (0,external_wp_element_namespaceObject.useState)((0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: Existing item title */
(0,external_wp_i18n_namespaceObject.__)('%s (Copy)'), getItemTitle(item)));
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_coreData_namespaceObject.store);
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store);
async function createPage(event) {
const newItem = await saveEntityRecord('postType', item.type, {
slug: title || (0,external_wp_i18n_namespaceObject.__)('No title'),
comment_status: item.comment_status,
content: typeof item.content === 'string' ? item.content : item.content.raw,
excerpt: item.excerpt.raw,
featured_media: item.featured_media,
menu_order: item.menu_order,
ping_status: item.ping_status,
categories: item.categories,
createSuccessNotice((0,external_wp_i18n_namespaceObject.sprintf)(
// translators: %s: Title of the created template e.g: "Category".
(0,external_wp_i18n_namespaceObject.__)('"%s" successfully created.'), (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(newItem.title?.rendered || title)), {
id: 'duplicate-post-action',
onActionPerformed([newItem]);
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : (0,external_wp_i18n_namespaceObject.__)('An error occurred while duplicating the page.');
createErrorNotice(errorMessage, {
setIsCreatingPage(false);
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("form", {
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.__experimentalVStack, {
children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.TextControl, {
label: (0,external_wp_i18n_namespaceObject.__)('Title'),
placeholder: (0,external_wp_i18n_namespaceObject.__)('No title'),
}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.__experimentalHStack, {
children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
children: (0,external_wp_i18n_namespaceObject.__)('Cancel')
}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
"aria-disabled": isCreatingPage,
children: (0,external_wp_i18n_namespaceObject._x)('Duplicate', 'action label')
const resetTemplateAction = {
label: (0,external_wp_i18n_namespaceObject.__)('Reset'),
return isTemplateRevertable(item);
const [isBusy, setIsBusy] = (0,external_wp_element_namespaceObject.useState)(false);
} = unlock((0,external_wp_data_namespaceObject.useDispatch)(store_store));
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_coreData_namespaceObject.store);
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store);
const onConfirm = async () => {
for (const template of items) {
await revertTemplate(template, {
await saveEditedEntityRecord('postType', template.type, template.id);
createSuccessNotice(items.length > 1 ? (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: The number of items. */
(0,external_wp_i18n_namespaceObject.__)('%s items reset.'), items.length) : (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: The template/part's name. */
(0,external_wp_i18n_namespaceObject.__)('"%s" reset.'), (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(getItemTitle(items[0]))), {
id: 'revert-template-action'
let fallbackErrorMessage;
if (items[0].type === TEMPLATE_POST_TYPE) {
fallbackErrorMessage = items.length === 1 ? (0,external_wp_i18n_namespaceObject.__)('An error occurred while reverting the template.') : (0,external_wp_i18n_namespaceObject.__)('An error occurred while reverting the templates.');
fallbackErrorMessage = items.length === 1 ? (0,external_wp_i18n_namespaceObject.__)('An error occurred while reverting the template part.') : (0,external_wp_i18n_namespaceObject.__)('An error occurred while reverting the template parts.');
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : fallbackErrorMessage;
createErrorNotice(errorMessage, {
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.__experimentalVStack, {
children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.__experimentalText, {
children: (0,external_wp_i18n_namespaceObject.__)('Reset to default and clear all customizations?')
}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.__experimentalHStack, {
children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
__experimentalIsFocusable: true,
children: (0,external_wp_i18n_namespaceObject.__)('Cancel')
}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
onActionPerformed?.(items);
__experimentalIsFocusable: true,
children: (0,external_wp_i18n_namespaceObject.__)('Reset')
const duplicatePatternAction = {
label: (0,external_wp_i18n_namespaceObject._x)('Duplicate', 'action label'),
isEligible: item => item.type !== TEMPLATE_PART_POST_TYPE,
modalHeader: (0,external_wp_i18n_namespaceObject._x)('Duplicate pattern', 'action label'),
const isThemePattern = item.type === actions_PATTERN_TYPES.theme;
const duplicatedProps = useDuplicatePatternProps({
pattern: isThemePattern || !item.patternPost ? item : item.patternPost,
onSuccess: () => closeModal()
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(CreatePatternModalContents, {
confirmLabel: (0,external_wp_i18n_namespaceObject._x)('Duplicate', 'action label'),
const duplicateTemplatePartAction = {
id: 'duplicate-template-part',
label: (0,external_wp_i18n_namespaceObject._x)('Duplicate', 'action label'),
isEligible: item => item.type === TEMPLATE_PART_POST_TYPE,
modalHeader: (0,external_wp_i18n_namespaceObject._x)('Duplicate template part', 'action label'),
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store);
function onTemplatePartSuccess() {
createSuccessNotice((0,external_wp_i18n_namespaceObject.sprintf)(
// translators: %s: The new template part's title e.g. 'Call to action (copy)'.
(0,external_wp_i18n_namespaceObject.__)('"%s" duplicated.'), item.title), {
id: 'edit-site-patterns-success'
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(CreateTemplatePartModalContents, {
defaultArea: item.templatePart?.area || item.area,
defaultTitle: (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: Existing template part title */
(0,external_wp_i18n_namespaceObject.__)('%s (Copy)'), item.title),
onCreate: onTemplatePartSuccess,
confirmLabel: (0,external_wp_i18n_namespaceObject._x)('Duplicate', 'action label')
function usePostActions({