Skip to content

Commit

Permalink
Fix: Check Capability to create pages on DataViews add new page button (
Browse files Browse the repository at this point in the history
#62592)

Co-authored-by: jorgefilipecosta <[email protected]>
Co-authored-by: carolinan <[email protected]>
  • Loading branch information
3 people authored and ellatrix committed Jun 25, 2024
1 parent 5460ed3 commit 4a5ed1b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,19 @@ export default function PagePages() {
[ totalItems, totalPages ]
);

const { frontPageId, postsPageId, addNewLabel } = useSelect( ( select ) => {
const { getEntityRecord, getPostType } = select( coreStore );
const siteSettings = getEntityRecord( 'root', 'site' );
return {
frontPageId: siteSettings?.page_on_front,
postsPageId: siteSettings?.page_for_posts,
addNewLabel: getPostType( 'page' )?.labels?.add_new_item,
};
} );
const { frontPageId, postsPageId, addNewLabel, canCreatePage } = useSelect(
( select ) => {
const { getEntityRecord, getPostType, canUser } =
select( coreStore );
const siteSettings = getEntityRecord( 'root', 'site' );
return {
frontPageId: siteSettings?.page_on_front,
postsPageId: siteSettings?.page_for_posts,
addNewLabel: getPostType( 'page' )?.labels?.add_new_item,
canCreatePage: canUser( 'create', 'pages' ),
};
}
);

const fields = useMemo(
() => [
Expand Down Expand Up @@ -499,7 +503,8 @@ export default function PagePages() {
<Page
title={ __( 'Pages' ) }
actions={
addNewLabel && (
addNewLabel &&
canCreatePage && (
<>
<Button
variant="primary"
Expand Down

0 comments on commit 4a5ed1b

Please sign in to comment.