diff --git a/docs/reference-guides/data/data-core-editor.md b/docs/reference-guides/data/data-core-editor.md index ac3413e694877..4bcfffa0dd3e9 100644 --- a/docs/reference-guides/data/data-core-editor.md +++ b/docs/reference-guides/data/data-core-editor.md @@ -555,6 +555,18 @@ _Returns_ - `string|undefined`: The post type label if available, otherwise undefined. +### getPostTypeSupports + +Returns a post type support object on the current post + +_Parameters_ + +- _state_ `Object`: Global application state. + +_Returns_ + +- `Object`: The post type supports object. + ### getPreviousBlockClientId _Related_ diff --git a/lib/init.php b/lib/init.php index 13ca26d4b9e83..8d0c1265256ca 100644 --- a/lib/init.php +++ b/lib/init.php @@ -57,3 +57,27 @@ function gutenberg_menu() { ); } add_action( 'admin_menu', 'gutenberg_menu', 9 ); + + +/** + * This should be implemented in core as a default + * post type feature. + * + */ +if ( ! function_exists( 'add_content_support' ) ) { + /** + * Add the 'content' support to core content post types. + * + * @since 6.8.0 + */ + function add_content_support() { + global $wp_post_types; + + foreach ( array_keys( $wp_post_types ) as $post_type ) { + if ( in_array( $post_type, array( 'post', 'page', 'wp_template' ), true ) ) { + add_post_type_support( $post_type, 'content' ); + } + } + } + add_action( 'init', 'add_content_support' ); +} diff --git a/packages/editor/src/components/header/index.js b/packages/editor/src/components/header/index.js index 1bd1114852fd6..6253e1d4237f5 100644 --- a/packages/editor/src/components/header/index.js +++ b/packages/editor/src/components/header/index.js @@ -54,7 +54,7 @@ function Header( { const isLargeViewport = useViewportMatch( 'medium' ); const isTooNarrowForDocumentBar = useMediaQuery( '(max-width: 403px)' ); const { - postType, + postTypeContentSupport, isTextEditor, isPublishSidebarOpened, showIconLabels, @@ -66,12 +66,13 @@ function Header( { const { getEditorMode, getEditorSettings, - getCurrentPostType, isPublishSidebarOpened: _isPublishSidebarOpened, + getPostTypeSupports, } = select( editorStore ); return { - postType: getCurrentPostType(), + postTypeContentSupport: + getPostTypeSupports().hasOwnProperty( 'content' ), isTextEditor: getEditorMode() === 'text', isPublishSidebarOpened: _isPublishSidebarOpened(), showIconLabels: getPreference( 'core', 'showIconLabels' ), @@ -83,10 +84,6 @@ function Header( { }; }, [] ); - const canBeZoomedOut = [ 'post', 'page', 'wp_template' ].includes( - postType - ); - const [ isBlockToolsCollapsed, setIsBlockToolsCollapsed ] = useState( true ); @@ -149,9 +146,11 @@ function Header( { ) } - { canBeZoomedOut && isEditorIframed && isWideViewport && ( - - ) } + { postTypeContentSupport && + isEditorIframed && + isWideViewport && ( + + ) } ( state ) => { + const currentPostType = getCurrentPostType( state ); + const postType = select( coreStore ).getPostType( currentPostType ); + return postType?.supports ?? {}; + } +); + /** * Returns true if the publish sidebar is opened. *