Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function* editPost( edits, options ) {
const { id, type } = yield select( STORE_KEY, 'getCurrentPost' );
yield dispatch(
'core',
'editEntityRecord',
'postType',
type,
id,
edits,
options
);
}
const getBlockEditorAction = ( name ) => function* ( ...args ) {
deprecated( '`wp.data.dispatch( \'core/editor\' ).' + name + '`', {
alternative: '`wp.data.dispatch( \'core/block-editor\' ).' + name + '`',
} );
yield dispatch( 'core/block-editor', name, ...args );
};
export function* saveWidgetAreas() {
const widgetAreas = yield select(
'core/edit-widgets',
'getWidgetAreas',
);
for ( const { id } of widgetAreas ) {
const blocks = yield select(
'core/edit-widgets',
'getBlocksFromWidgetArea',
id
);
yield dispatch(
'core',
'saveWidgetArea',
{
id,
content: serialize( blocks ),
}
);
}
yield dispatch(
'core/notices',
'createSuccessNotice',
__( 'Block areas saved succesfully.' ),
{
id: WIDGET_AREAS_SAVE_NOTICE_ID,
type: 'snackbar',
function* invalidateModifiedCollection( timestamp ) {
const lastModified = yield select( STORE_KEY, 'getCollectionLastModified' );
if ( ! lastModified ) {
yield dispatch( STORE_KEY, 'receiveLastModified', timestamp );
} else if ( timestamp > lastModified ) {
yield dispatch( STORE_KEY, 'invalidateResolutionForStore' );
yield dispatch( STORE_KEY, 'receiveLastModified', timestamp );
}
}
export function* resetAutosave( newAutosave ) {
deprecated( 'resetAutosave action (`core/editor` store)', {
alternative: 'receiveAutosaves action (`core` store)',
plugin: 'Gutenberg',
} );
const postId = yield select( STORE_KEY, 'getCurrentPostId' );
yield dispatch( 'core', 'receiveAutosaves', postId, newAutosave );
return { type: '__INERT__' };
}
'removeNotice',
TRASH_POST_NOTICE_ID
);
try {
const post = yield select(
STORE_KEY,
'getCurrentPost'
);
yield apiFetch(
{
path: `/wp/v2/${ postType.rest_base }/${ post.id }`,
method: 'DELETE',
}
);
yield dispatch(
STORE_KEY,
'savePost'
);
} catch ( error ) {
yield dispatch(
'core/notices',
'createErrorNotice',
...getNotificationArgumentsForTrashFail( { error } ),
);
}
}
}
yield __experimentalRequestPostUpdateStart( options );
const previousRecord = yield select( STORE_KEY, 'getCurrentPost' );
edits = {
id: previousRecord.id,
...( yield select(
'core',
'getEntityRecordNonTransientEdits',
'postType',
previousRecord.type,
previousRecord.id
) ),
...edits,
};
yield dispatch(
'core',
'saveEntityRecord',
'postType',
previousRecord.type,
edits,
options
);
yield __experimentalRequestPostUpdateFinish( options );
const error = yield select(
'core',
'getLastEntitySaveError',
'postType',
previousRecord.type,
previousRecord.id
);
export function* trashPost() {
const postTypeSlug = yield select(
STORE_KEY,
'getCurrentPostType'
);
const postType = yield select(
'core',
'getPostType',
postTypeSlug
);
yield dispatch(
'core/notices',
'removeNotice',
TRASH_POST_NOTICE_ID
);
try {
const post = yield select(
STORE_KEY,
'getCurrentPost'
);
yield apiFetch(
{
path: `/wp/v2/${ postType.rest_base }/${ post.id }`,
method: 'DELETE',
}
);
export function* redo() {
yield dispatch( 'core', 'redo' );
}