Skip to content

Commit

Permalink
Template Part: Add check if create action should be allowed (WordPres…
Browse files Browse the repository at this point in the history
…s#63623)

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
3 people authored Jul 20, 2024
1 parent 8e0a33c commit 3099d18
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions packages/block-library/src/template-part/edit/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { __, sprintf } from '@wordpress/i18n';
import { Placeholder, Button, Spinner } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand All @@ -28,6 +30,21 @@ export default function TemplatePartPlaceholder( {
templatePartId
);
const blockPatterns = useAlternativeBlockPatterns( area, clientId );

const { isBlockBasedTheme, canCreateTemplatePart } = useSelect(
( select ) => {
const { getCurrentTheme, canUser } = select( coreStore );
return {
isBlockBasedTheme: getCurrentTheme()?.is_block_theme,
canCreateTemplatePart: canUser( 'create', {
kind: 'postType',
name: 'wp_template_part',
} ),
};
},
[]
);

const [ showTitleModal, setShowTitleModal ] = useState( false );
const areaObject = useTemplatePartArea( area );
const createFromBlocks = useCreateTemplatePartFromBlocks(
Expand All @@ -39,11 +56,19 @@ export default function TemplatePartPlaceholder( {
<Placeholder
icon={ areaObject.icon }
label={ areaObject.label }
instructions={ sprintf(
// Translators: %s as template part area title ("Header", "Footer", etc.).
__( 'Choose an existing %s or create a new one.' ),
areaObject.label.toLowerCase()
) }
instructions={
isBlockBasedTheme
? sprintf(
// Translators: %s as template part area title ("Header", "Footer", etc.).
__( 'Choose an existing %s or create a new one.' ),
areaObject.label.toLowerCase()
)
: sprintf(
// Translators: %s as template part area title ("Header", "Footer", etc.).
__( 'Choose an existing %s.' ),
areaObject.label.toLowerCase()
)
}
>
{ isResolving && <Spinner /> }

Expand All @@ -54,7 +79,7 @@ export default function TemplatePartPlaceholder( {
</Button>
) }

{ ! isResolving && (
{ ! isResolving && isBlockBasedTheme && canCreateTemplatePart && (
<Button
variant="secondary"
onClick={ () => {
Expand Down

0 comments on commit 3099d18

Please sign in to comment.