Skip to content

Commit dd53ff0

Browse files
authored
Merge pull request ryanwelcher#108 from ryanwelcher/fix/being-an-editor-breaks-things
Check the user to be sure they can see the site options.
2 parents a533c36 + 527ca6e commit dd53ff0

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/components/post-exclude-controls.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import { ToggleControl } from '@wordpress/components';
55
import { useSelect } from '@wordpress/data';
6-
import { useEntityRecord } from '@wordpress/core-data';
6+
import { useEntityRecord, store as coreDataStore } from '@wordpress/core-data';
77
import { __ } from '@wordpress/i18n';
88

99
/**
@@ -18,26 +18,33 @@ import { __ } from '@wordpress/i18n';
1818
export 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

Comments
 (0)