Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
improve logic for revert button
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed May 9, 2023
1 parent 954335b commit 7730ef0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions assets/js/templates/revert-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { store as blockEditorStore } from '@wordpress/block-editor';

// @ts-expect-error: @wordpress/plugin is typed in the newer versions
// eslint-disable-next-line @woocommerce/dependency-group
import { registerPlugin, unregisterPlugin } from '@wordpress/plugins';
import {
registerPlugin,
unregisterPlugin,
getPlugin,
} from '@wordpress/plugins';

/**
* Internal dependencies
Expand Down Expand Up @@ -150,10 +154,18 @@ subscribe( () => {
PluginTemplateSettingPanel !== undefined;

if ( isWooTemplate && hasSupportForPluginTemplateSettingPanel ) {
registerPlugin( REVERT_BUTTON_PLUGIN_NAME, {
if ( getPlugin( REVERT_BUTTON_PLUGIN_NAME ) ) {
return;
}

return registerPlugin( REVERT_BUTTON_PLUGIN_NAME, {
render: RevertClassicTemplateButton,
} );
} else {
unregisterPlugin( REVERT_BUTTON_PLUGIN_NAME );
}

if ( getPlugin( REVERT_BUTTON_PLUGIN_NAME ) === undefined ) {
return;
}

unregisterPlugin( REVERT_BUTTON_PLUGIN_NAME );
}, 'core/edit-site' );

0 comments on commit 7730ef0

Please sign in to comment.