Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Editing "Page" is broken for low capability users. #68110

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions packages/core-data/src/private-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { createSelector, createRegistrySelector } from '@wordpress/data';
/**
* Internal dependencies
*/
import { getDefaultTemplateId, getEntityRecord, type State } from './selectors';
import {
canUser,
getDefaultTemplateId,
getEntityRecord,
type State,
} from './selectors';
import { STORE_NAME } from './name';
import { unlock } from './lock-unlock';

Expand Down Expand Up @@ -134,6 +139,13 @@ interface SiteData {
export const getHomePage = createRegistrySelector( ( select ) =>
createSelector(
() => {
const canReadSiteData = select( STORE_NAME ).canUser( 'read', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do something similar for getPostsPageId and getTemplateId

kind: 'root',
name: 'site',
} );
if ( ! canReadSiteData ) {
return null;
}
const siteData = select( STORE_NAME ).getEntityRecord(
'root',
'site'
Expand All @@ -156,7 +168,10 @@ export const getHomePage = createRegistrySelector( ( select ) =>
return { postType: 'wp_template', postId: frontPageTemplateId };
},
( state ) => [
getEntityRecord( state, 'root', 'site' ),
canUser( state, 'read', {
kind: 'root',
name: 'site',
} ) && getEntityRecord( state, 'root', 'site' ),
getDefaultTemplateId( state, {
slug: 'front-page',
} ),
Expand Down
8 changes: 6 additions & 2 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
BlockEditorProviderComponent = ExperimentalBlockEditorProvider,
__unstableTemplate: template,
} ) => {
const hasTemplate = !! template;
const {
editorSettings,
selection,
Expand Down Expand Up @@ -195,15 +196,17 @@ export const ExperimentalEditorProvider = withRegistryProvider(
isReady: __unstableIsEditorReady(),
mode: getRenderingMode(),
defaultMode:
postTypeObject?.default_rendering_mode ?? 'post-only',
hasTemplate && postTypeObject?.default_rendering_mode
? postTypeObject?.default_rendering_mode
: 'post-only',
selection: getEditorSelection(),
postTypeEntities:
post.type === 'wp_template'
? getEntitiesConfig( 'postType' )
: null,
};
},
[ post.type ]
[ post.type, hasTemplate ]
);

const shouldRenderTemplate = !! template && mode !== 'post-only';
Expand Down Expand Up @@ -308,6 +311,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
recovery,
setupEditor,
updatePostLock,
hasTemplate,
] );

// Synchronizes the active post with the state
Expand Down
Loading