-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Block Bindings: Lock binding editing with functions #61734
Block Bindings: Lock binding editing with functions #61734
Conversation
@@ -1796,3 +1796,7 @@ export const getPostTypeLabel = createRegistrySelector( | |||
export function isPublishSidebarOpened( state ) { | |||
return state.publishSidebarActive; | |||
} | |||
|
|||
export const __experimentalIsAdminUser = createRegistrySelector( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should rename this to canDeleteSettings
. I couldn't find any other example in the repo to check if a user is an admin within the selectors.
I think only admins can delete settings, but we have to take into account the difference between an admin and a superadmin in multisites. And make sure it works as expected in both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will explore the possibility of using canUserEditEntityRecord.
@@ -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' ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also take a look at useResourcePermissions
, like the navigation menu does.
export default function useResourcePermissions< IdType = void >( |
Size Change: +511 B (+0.03%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
…k if is admin" This reverts commit 9659455.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me and tests seem to be passing 🙂
* Add lock as a function * Add edit value posibility for post meta, add function to check if is admin * Revert "Add edit value posibility for post meta, add function to check if is admin" This reverts commit 9659455. --------- Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org> Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
What?
When a block attribute is connected to a source using block bindings, we let sources decide when to lock the controls related to that attributes and when not. For example, at this moment, if a paragraph content is connected to a custom field, we lock the editing. Or when an image URL is connected to a custom field, we hide the relevant controls.
At some point, we need to explore how to abstract it so we don't have to modify the block edit functions, but for now it is okay to keep it hardcoded as it is before this pull request.
Why?
Until this pull request, that property was a boolean because it was an all-or-nothing. However, now that we plan to add the possibility of editing the value of the custom fields (or other sources), we need more flexibility. That's why we should probably use a callback.
For example, when a block is connected to a custom field, we want to enable editing only under specific circumstances:
For that reason, using a boolean is not enough. And we should let sources decide when this applies.
Testing Instructions
e2e passing should be enough. If you want to test it manually:
2. Add a paragraph block bound to the custom field using the Code Editor
You can repeat the process for the rest of the block attributes: image, button, and heading.