Skip to content

Commit

Permalink
Add edit value posibility for post meta, add function to check if is …
Browse files Browse the repository at this point in the history
…admin
  • Loading branch information
cbravobernal committed May 16, 2024
1 parent 051c6a4 commit 9659455
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/editor/src/bindings/post-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();
},
};
4 changes: 4 additions & 0 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
);

0 comments on commit 9659455

Please sign in to comment.