WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.5k stars 4.19k forks source link

Replace `__unstableIsBlockBasedTheme` in block-editor api with core data API #53392

Open t-hamano opened 1 year ago

t-hamano commented 1 year ago

Related to #53137

What problem does this address?

Currently, to determine if a activetheme is a block-based theme, we use the Block Editor API as follows:

import { store as blockEditorStore } from '@wordpress/block-editor';

const isBlockBasedTheme = useSelect( ( select ) => {
    return select( blockEditorStore ).getSettings().__unstableIsBlockBasedTheme;
}, [] );

However, if the current page does not load a block editor, this API returns undefined.

What is your proposed solution?

In order to accurately determine if it is a block-based theme, it would be good to replace it with a core data API, as suggested in this comment.

import { store as coreStore } from '@wordpress/core-data';

const isBlockBasedTheme = useSelect( ( select ) => {
    return select( coreStore ).getCurrentTheme().is_block_theme;
}, [] );
HILAYTRIVEDI commented 1 year ago

I am taking this issue 😄

Mamaduka commented 1 year ago

Thanks, @HILAYTRIVEDI.

The change needs to happen in WP Core and WP_REST_Themes_Controller.

@t-hamano, I think this is probably not a "Good First Issue" task.