Skip to content

Commit

Permalink
Revert "Stabilize the PreSavePost and SavePost filters (WordPress#64198
Browse files Browse the repository at this point in the history
…)"

This reverts commit 4f97ebb.
  • Loading branch information
huubl authored Oct 2, 2024
1 parent 4a95e8c commit 0c00b6a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
23 changes: 15 additions & 8 deletions packages/edit-post/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
privateApis as editorPrivateApis,
} from '@wordpress/editor';
import deprecated from '@wordpress/deprecated';
import { addAction } from '@wordpress/hooks';
import { addFilter } from '@wordpress/hooks';
import { store as coreStore } from '@wordpress/core-data';

/**
Expand Down Expand Up @@ -478,14 +478,21 @@ export const initializeMetaBoxes =
metaBoxesInitialized = true;

// Save metaboxes on save completion, except for autosaves.
addAction(
'editor.savePost',
addFilter(
'editor.__unstableSavePost',
'core/edit-post/save-metaboxes',
async ( options ) => {
if ( ! options.isAutosave && select.hasMetaBoxes() ) {
await dispatch.requestMetaBoxUpdates();
}
}
( previous, options ) =>
previous.then( () => {
if ( options.isAutosave ) {
return;
}

if ( ! select.hasMetaBoxes() ) {
return;
}

return dispatch.requestMetaBoxUpdates();
} )
);

dispatch( {
Expand Down
37 changes: 11 additions & 26 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import {
import { store as noticesStore } from '@wordpress/notices';
import { store as coreStore } from '@wordpress/core-data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import {
applyFilters,
applyFiltersAsync,
doActionAsync,
} from '@wordpress/hooks';
import { applyFilters } from '@wordpress/hooks';
import { store as preferencesStore } from '@wordpress/preferences';
import { __ } from '@wordpress/i18n';

Expand Down Expand Up @@ -188,7 +184,7 @@ export const savePost =
}

const previousRecord = select.getCurrentPost();
let edits = {
const edits = {
id: previousRecord.id,
...registry
.select( coreStore )
Expand All @@ -203,9 +199,9 @@ export const savePost =

let error = false;
try {
edits = await applyFiltersAsync(
'editor.preSavePost',
edits,
error = await applyFilters(
'editor.__unstablePreSavePost',
Promise.resolve( false ),
options
);
} catch ( err ) {
Expand Down Expand Up @@ -240,25 +236,14 @@ export const savePost =
);
}

// Run the hook with legacy unstable name for backward compatibility
if ( ! error ) {
try {
await applyFilters(
'editor.__unstableSavePost',
Promise.resolve(),
options
);
} catch ( err ) {
error = err;
}
}

if ( ! error ) {
try {
await doActionAsync( 'editor.savePost', options );
} catch ( err ) {
await applyFilters(
'editor.__unstableSavePost',
Promise.resolve(),
options
).catch( ( err ) => {
error = err;
}
} );
}
dispatch( { type: 'REQUEST_POST_UPDATE_FINISH', options } );

Expand Down

0 comments on commit 0c00b6a

Please sign in to comment.