Make WordPress Core


Ignore:
Timestamp:
09/30/2024 06:47:20 AM (23 months ago)
Author:
cbravobernal
Message:

Block bindings: Add canUpdateBlockBindings editor setting.

Adds a canUpdateBlockBindings editor setting that allows to decide if the user is able to create and modify bindings through the UI. By default, only admin users can do it, but it can be overridden with block_editor_settings_all filter.

Props santosguillamot, gziolo, jorbin, noisysocks, matveb, cbravobernal, youknowriad, mamaduka, timothyblynjacobs, peterwilsoncc, drivingralle.
Fixes #61945.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/capabilities.php

    r58998 r59122  
    802802                        $caps = map_meta_cap( 'edit_user', $user_id, $args[0] );
    803803                        break;
     804                case 'edit_block_binding':
     805                        $block_editor_context = $args[0];
     806                        if ( isset( $block_editor_context->post ) ) {
     807                                $object_id = $block_editor_context->post->ID;
     808                        }
     809                        /*
     810                         * If the post ID is null, check if the context is the site editor.
     811                         * Fall back to the edit_theme_options in that case.
     812                         */
     813                        if ( ! isset( $object_id ) ) {
     814                                if ( ! isset( $block_editor_context->name ) || 'core/edit-site' !== $block_editor_context->name ) {
     815                                        $caps[] = 'do_not_allow';
     816                                        break;
     817                                }
     818                                $caps = map_meta_cap( 'edit_theme_options', $user_id );
     819                                break;
     820                        }
     821
     822                        $object_subtype = get_object_subtype( 'post', (int) $object_id );
     823                        if ( empty( $object_subtype ) ) {
     824                                $caps[] = 'do_not_allow';
     825                                break;
     826                        }
     827
     828                        $caps = map_meta_cap( "edit_{$object_subtype}", $user_id, $object_id );
     829                        break;
    804830                default:
    805831                        // Handle meta capabilities for custom post types.
Note: See TracChangeset for help on using the changeset viewer.