Skip to content

Commit

Permalink
Test extensible SaveButton
Browse files Browse the repository at this point in the history
  • Loading branch information
okmttdhr committed Dec 8, 2023
1 parent d709e5c commit f01589b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/edit-site/src/components/save-hub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
import { check } from '@wordpress/icons';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { store as noticesStore } from '@wordpress/notices';
import { addFilter, removeFilter } from '@wordpress/hooks';
import { useEffect } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -115,6 +117,32 @@ export default function SaveHub() {
};
}, [] );

// This is only for testing purposes.
useEffect( () => {
addFilter(
'edit-site.SaveButton.onClick',
'my-plugin',
( originalFunction ) => {
return () => {
// eslint-disable-next-line no-alert
window.alert( 'Custom action' );
originalFunction();
};
}
);
addFilter(
'edit-site.SaveButton.label',
'my-plugin',
( originalLabel ) => {
return `Custom ${ originalLabel }`;
}
);
return () => {
removeFilter( 'edit-site.SaveButton.onClick', 'my-plugin' );
removeFilter( 'edit-site.SaveButton.label', 'my-plugin' );
};
}, [] );

const saveCurrentEntity = async () => {
if ( ! dirtyCurrentEntity ) return;

Expand Down

0 comments on commit f01589b

Please sign in to comment.