@@ -36,21 +36,29 @@ export default function AddNewPattern() {
36
36
const [ showPatternModal , setShowPatternModal ] = useState ( false ) ;
37
37
const [ showTemplatePartModal , setShowTemplatePartModal ] =
38
38
useState ( false ) ;
39
+ // eslint-disable-next-line @wordpress/no-unused-vars-before-return
39
40
const { createPatternFromFile } = unlock ( useDispatch ( patternsStore ) ) ;
40
41
const { createSuccessNotice, createErrorNotice } =
41
42
useDispatch ( noticesStore ) ;
42
43
const patternUploadInputRef = useRef ( ) ;
43
- const { isBlockBasedTheme, addNewPatternLabel, addNewTemplatePartLabel } =
44
- useSelect ( ( select ) => {
45
- const { getCurrentTheme, getPostType } = select ( coreStore ) ;
46
- return {
47
- isBlockBasedTheme : getCurrentTheme ( ) ?. is_block_theme ,
48
- addNewPatternLabel : getPostType ( PATTERN_TYPES . user ) ?. labels
49
- ?. add_new_item ,
50
- addNewTemplatePartLabel : getPostType ( TEMPLATE_PART_POST_TYPE )
51
- ?. labels ?. add_new_item ,
52
- } ;
53
- } , [ ] ) ;
44
+ const {
45
+ isBlockBasedTheme,
46
+ addNewPatternLabel,
47
+ addNewTemplatePartLabel,
48
+ canCreatePattern,
49
+ canCreateTemplatePart,
50
+ } = useSelect ( ( select ) => {
51
+ const { getCurrentTheme, getPostType, canUser } = select ( coreStore ) ;
52
+ return {
53
+ isBlockBasedTheme : getCurrentTheme ( ) ?. is_block_theme ,
54
+ addNewPatternLabel : getPostType ( PATTERN_TYPES . user ) ?. labels
55
+ ?. add_new_item ,
56
+ addNewTemplatePartLabel : getPostType ( TEMPLATE_PART_POST_TYPE )
57
+ ?. labels ?. add_new_item ,
58
+ canCreatePattern : canUser ( 'create' , 'blocks' ) ,
59
+ canCreateTemplatePart : canUser ( 'create' , 'template-parts' ) ,
60
+ } ;
61
+ } , [ ] ) ;
54
62
55
63
function handleCreatePattern ( { pattern } ) {
56
64
setShowPatternModal ( false ) ;
@@ -78,31 +86,37 @@ export default function AddNewPattern() {
78
86
setShowTemplatePartModal ( false ) ;
79
87
}
80
88
81
- const controls = [
82
- {
89
+ const controls = [ ] ;
90
+ if ( canCreatePattern ) {
91
+ controls . push ( {
83
92
icon : symbol ,
84
93
onClick : ( ) => setShowPatternModal ( true ) ,
85
94
title : addNewPatternLabel ,
86
- } ,
87
- ] ;
95
+ } ) ;
96
+ }
88
97
89
- if ( isBlockBasedTheme ) {
98
+ if ( isBlockBasedTheme && canCreateTemplatePart ) {
90
99
controls . push ( {
91
100
icon : symbolFilled ,
92
101
onClick : ( ) => setShowTemplatePartModal ( true ) ,
93
102
title : addNewTemplatePartLabel ,
94
103
} ) ;
95
104
}
96
105
97
- controls . push ( {
98
- icon : upload ,
99
- onClick : ( ) => {
100
- patternUploadInputRef . current . click ( ) ;
101
- } ,
102
- title : __ ( 'Import pattern from JSON' ) ,
103
- } ) ;
106
+ if ( canCreatePattern ) {
107
+ controls . push ( {
108
+ icon : upload ,
109
+ onClick : ( ) => {
110
+ patternUploadInputRef . current . click ( ) ;
111
+ } ,
112
+ title : __ ( 'Import pattern from JSON' ) ,
113
+ } ) ;
114
+ }
104
115
105
116
const { categoryMap, findOrCreateTerm } = useAddPatternCategory ( ) ;
117
+ if ( controls . length === 0 ) {
118
+ return null ;
119
+ }
106
120
return (
107
121
< >
108
122
{ addNewPatternLabel && (
0 commit comments