3
3
*/
4
4
import { ToggleControl } from '@wordpress/components' ;
5
5
import { useSelect } from '@wordpress/data' ;
6
- import { useEntityRecord } from '@wordpress/core-data' ;
6
+ import { useEntityRecord , store as coreDataStore } from '@wordpress/core-data' ;
7
7
import { __ } from '@wordpress/i18n' ;
8
8
9
9
/**
@@ -18,26 +18,33 @@ import { __ } from '@wordpress/i18n';
18
18
export const PostExcludeControls = ( { attributes, setAttributes } ) => {
19
19
const { query : { exclude_current : excludeCurrent } = { } } = attributes ;
20
20
const { record : siteOptions } = useEntityRecord ( 'root' , 'site' ) ;
21
- const currentPost = useSelect ( ( select ) => {
22
- return select ( 'core/editor' ) . getCurrentPost ( ) ;
21
+ const { currentPost, isAdmin } = useSelect ( ( select ) => {
22
+ return {
23
+ currentPost : select ( 'core/editor' ) . getCurrentPost ( ) ,
24
+ isAdmin : select ( coreDataStore ) . canUser ( 'update' , {
25
+ kind : 'root' ,
26
+ name : 'site' ,
27
+ } ) ,
28
+ } ;
23
29
} , [ ] ) ;
24
30
25
31
if ( ! currentPost ) {
26
32
return < div > { __ ( 'Loading…' , 'advanced-query-loop' ) } </ div > ;
27
33
}
28
34
29
35
const isDisabled = ( ) => {
36
+ // If the user is not an admin, they cannot edit template anyway
37
+ if ( ! isAdmin ) {
38
+ return false ;
39
+ }
30
40
const templatesToExclude = [ 'archive' , 'search' ] ;
31
-
32
41
const {
33
42
show_on_front : showOnFront , // What is the front page set to show? Options: 'posts' or 'page'
34
43
} = siteOptions ;
35
-
36
44
const disabledTemplates = [
37
45
...templatesToExclude ,
38
46
...( showOnFront === 'posts' ? [ 'home' , 'front-page' ] : [ ] ) ,
39
47
] ;
40
-
41
48
return (
42
49
currentPost . type === 'wp_template' &&
43
50
disabledTemplates . includes ( currentPost . slug )
@@ -71,7 +78,6 @@ export const PostExcludeControls = ( { attributes, setAttributes } ) => {
71
78
'advanced-query-loop'
72
79
)
73
80
}
74
- __nextHasNoMarginBottom
75
81
/>
76
82
</ >
77
83
) ;
0 commit comments