From 0fae69b147130e3deff18dbe6cdcb664268d9cc5 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Mon, 13 May 2024 19:34:29 +0100 Subject: [PATCH] take into account post type support on labels --- .../src/components/post-discussion/panel.js | 22 ++++++++++++++++--- .../editor/src/components/sidebar/index.js | 1 - 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/components/post-discussion/panel.js b/packages/editor/src/components/post-discussion/panel.js index c1e184a826e63b..681bd6cb8a17c6 100644 --- a/packages/editor/src/components/post-discussion/panel.js +++ b/packages/editor/src/components/post-discussion/panel.js @@ -12,6 +12,7 @@ import { import { useSelect } from '@wordpress/data'; import { useState, useMemo } from '@wordpress/element'; import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor'; +import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies @@ -51,18 +52,33 @@ function ModalContents( { onClose } ) { } function PostDiscussionToggle( { isOpen, onClick } ) { - const { commentStatus, pingStatus } = useSelect( ( select ) => { + const { + commentStatus, + pingStatus, + commentsSupported, + trackbacksSupported, + } = useSelect( ( select ) => { const { getEditedPostAttribute } = select( editorStore ); + const { getPostType } = select( coreStore ); + const postType = getPostType( getEditedPostAttribute( 'type' ) ); return { commentStatus: getEditedPostAttribute( 'comment_status' ) ?? 'open', pingStatus: getEditedPostAttribute( 'ping_status' ) ?? 'open', + commentsSupported: !! postType.supports.comments, + trackbacksSupported: !! postType.supports.trackbacks, }; }, [] ); let label; if ( commentStatus === 'open' ) { - label = pingStatus === 'open' ? __( 'Open' ) : __( 'Comments only' ); + if ( pingStatus === 'open' ) { + label = __( 'Open' ); + } else { + label = trackbacksSupported ? __( 'Comments only' ) : __( 'Open' ); + } + } else if ( pingStatus === 'open' ) { + label = commentsSupported ? __( 'Pings only' ) : __( 'Pings enabled' ); } else { - label = pingStatus === 'open' ? __( 'Pings only' ) : __( 'Closed' ); + label = __( 'Closed' ); } return (