Created
December 3, 2025 11:31
-
-
Save diggeddy/1ac20cf80d0446ff0ac43a57ff0bbdc1 to your computer and use it in GitHub Desktop.
WP allow any user access to the Local Patterns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function author_can_edit_others_patterns( $allcaps, $caps, $args, $user ) { | |
| // Only intercept checks for "edit_others_posts" | |
| if ( ! in_array( 'edit_others_posts', $caps, true ) ) { | |
| return $allcaps; | |
| } | |
| // $args[2] contains the post ID when checking permissions for a post | |
| if ( empty( $args[2] ) ) { | |
| return $allcaps; | |
| } | |
| $post_id = $args[2]; | |
| $post = get_post( $post_id ); | |
| if ( ! $post ) { | |
| return $allcaps; | |
| } | |
| // Only apply override to Local Patterns (wp_block CPT) | |
| if ( $post->post_type === 'wp_block' ) { | |
| // Grant edit_others_posts ONLY for local patterns | |
| $allcaps['edit_others_posts'] = true; | |
| } | |
| return $allcaps; | |
| } | |
| add_filter( 'user_has_cap', 'author_can_edit_others_patterns', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment