Skip to content

Commit

Permalink
Fix: Editing "Page" is broken for low capability users. (WordPress#68110
Browse files Browse the repository at this point in the history
)

Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: vipul0425 <vipulgupta003@git.wordpress.org>
Co-authored-by: Marc-pi <mdxfr@git.wordpress.org>
  • Loading branch information
6 people authored Dec 27, 2024
1 parent 9ae31d3 commit b1f23ea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
26 changes: 24 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', {
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 All @@ -165,6 +180,13 @@ export const getHomePage = createRegistrySelector( ( select ) =>
);

export const getPostsPageId = createRegistrySelector( ( select ) => () => {
const canReadSiteData = select( STORE_NAME ).canUser( 'read', {
kind: 'root',
name: 'site',
} );
if ( ! canReadSiteData ) {
return null;
}
const siteData = select( STORE_NAME ).getEntityRecord( 'root', 'site' ) as
| SiteData
| undefined;
Expand Down
7 changes: 5 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

0 comments on commit b1f23ea

Please sign in to comment.