From 9659455eed4343c455760b2f9076fe3a5bdbf2d7 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Thu, 16 May 2024 18:36:38 +0200 Subject: [PATCH] Add edit value posibility for post meta, add function to check if is admin --- packages/editor/src/bindings/post-meta.js | 16 ++++++++++++++++ packages/editor/src/store/selectors.js | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/packages/editor/src/bindings/post-meta.js b/packages/editor/src/bindings/post-meta.js index f5b3b526dbfd4..81145d8be0aaf 100644 --- a/packages/editor/src/bindings/post-meta.js +++ b/packages/editor/src/bindings/post-meta.js @@ -8,6 +8,7 @@ import { _x } from '@wordpress/i18n'; * Internal dependencies */ import { store as editorStore } from '../store'; +import { __experimentalIsAdminUser } from '../store/selectors'; export default { name: 'core/post-meta', @@ -25,4 +26,19 @@ export default { .getEditedEntityRecord( 'postType', postType, context.postId ) .meta?.[ args.key ]; }, + setValue( { registry, context, args, value } ) { + const postType = context.postType + ? context.postType + : registry.select( editorStore ).getCurrentPostType(); + registry + .dispatch( coreDataStore ) + .editEntityRecord( 'postType', postType, context.postId, { + meta: { + [ args.key ]: value, + }, + } ); + }, + lockAttributesEditing() { + return ! __experimentalIsAdminUser(); + }, }; diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index e1a6be18e4601..66c68861b1db3 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1796,3 +1796,7 @@ export const getPostTypeLabel = createRegistrySelector( export function isPublishSidebarOpened( state ) { return state.publishSidebarActive; } + +export const __experimentalIsAdminUser = createRegistrySelector( + ( select ) => () => select( coreStore ).canUser( 'delete', 'settings' ) +);