33 */
44import { ToggleControl } from '@wordpress/components' ;
55import { useSelect } from '@wordpress/data' ;
6- import { useEntityRecord } from '@wordpress/core-data' ;
6+ import { useEntityRecord , store as coreDataStore } from '@wordpress/core-data' ;
77import { __ } from '@wordpress/i18n' ;
88
99/**
@@ -18,26 +18,33 @@ import { __ } from '@wordpress/i18n';
1818export const PostExcludeControls = ( { attributes, setAttributes } ) => {
1919 const { query : { exclude_current : excludeCurrent } = { } } = attributes ;
2020 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+ } ;
2329 } , [ ] ) ;
2430
2531 if ( ! currentPost ) {
2632 return < div > { __ ( 'Loading…' , 'advanced-query-loop' ) } </ div > ;
2733 }
2834
2935 const isDisabled = ( ) => {
36+ // If the user is not an admin, they cannot edit template anyway
37+ if ( ! isAdmin ) {
38+ return false ;
39+ }
3040 const templatesToExclude = [ 'archive' , 'search' ] ;
31-
3241 const {
3342 show_on_front : showOnFront , // What is the front page set to show? Options: 'posts' or 'page'
3443 } = siteOptions ;
35-
3644 const disabledTemplates = [
3745 ...templatesToExclude ,
3846 ...( showOnFront === 'posts' ? [ 'home' , 'front-page' ] : [ ] ) ,
3947 ] ;
40-
4148 return (
4249 currentPost . type === 'wp_template' &&
4350 disabledTemplates . includes ( currentPost . slug )
@@ -71,7 +78,6 @@ export const PostExcludeControls = ( { attributes, setAttributes } ) => {
7178 'advanced-query-loop'
7279 )
7380 }
74- __nextHasNoMarginBottom
7581 />
7682 </ >
7783 ) ;
0 commit comments