Design System is here - Read the release post

Learn GeneratePress

Developers

Editor Access (Pro)

Editor Access decides which controls each user sees in the block editor and which blocks they can edit, using access profiles and control sets. These hooks change who can manage it, how profiles are matched to users, and which controls it allows. The JavaScript hooks let your own blocks and controls respect the same rules.

Jump to

Permissions and profiles

generateblocks_editor_access_capability

GB Pro

The generateblocks_editor_access_capability filter sets the capability needed to use or manage Editor Access. A value that isn’t a non-empty string is ignored.

Parameters: $capability (string), $context (string: use to apply existing access profiles, or manage to create, edit and delete them). Default: edit_posts for use, manage_options for manage.

add_filter( 'generateblocks_editor_access_capability', function( $capability, $context ) {
    if ( 'manage' === $context ) {
        return 'edit_theme_options';
    }

    return $capability;
}, 10, 2 );

Related: generateblocks_conditions_capability Guide: Editor Access

generateblocks_editor_access_role_order

GB Pro

The generateblocks_editor_access_role_order filter sets the order GenerateBlocks uses to pick one access profile for a user who has more than one role. The first role in the order that has a profile wins.

Parameters: $roles (array of role slugs). Default: every role registered on the site, in the order WordPress lists them. Slugs are run through sanitize_key().

add_filter( 'generateblocks_editor_access_role_order', function( $roles ) {
    // Check the editor role before any other role.
    return array_values( array_unique( array_merge( [ 'editor' ], $roles ) ) );
} );

Related: generateblocks_editor_access_capability Guide: Editor Access

Back to top

Blocks and controls

generateblocks_editor_access_companion_block_types

GB Pro

The generateblocks_editor_access_companion_block_types filter lists the child blocks a block needs to keep working when Editor Access limits which blocks can be inserted. A block that is allowed also allows its companions, so that the block’s own add item buttons still work. Use it for a block of your own that depends on a child block that can also be used on its own.

Parameters: $companions (array of block name => array of child block names). Default: generateblocks/query with generateblocks/looper, generateblocks-pro/carousel with generateblocks-pro/carousel-control, and generateblocks-pro/navigation with generateblocks-pro/menu-container. Entries that aren’t a name with an array of names are removed.

add_filter( 'generateblocks_editor_access_companion_block_types', function( $companions ) {
    $companions['my-plugin/slider'] = [ 'my-plugin/slider-controls' ];

    return $companions;
} );

Related: generateblocks.editor.areInspectorControlsDisabled Guide: Editor Access

generateblocks_editor_access_control_components

GB Pro

The generateblocks_editor_access_control_components filter changes the control components that can be used in Editor Access control sets. It is a PHP allow-list of component names.

Parameters: $components (array of component names). Default: ColorPicker, ColorPalette, UnitControl, DimensionsControl, BackgroundControl, BoxShadowControl, FilterControl, TransformControl, TransitionControl, TextControl, SelectControl, ButtonGroup, ToggleControl and MediaUpload.

add_filter( 'generateblocks_editor_access_control_components', function( $components ) {
    return array_values( array_diff( $components, [ 'MediaUpload' ] ) );
} );

Related: generateblocks_editor_access_companion_block_types Guide: Editor Access

Back to top

Editor (JavaScript)

These are wp.hooks filters and actions. Editor Access adds its own callbacks to the filters. If you add a block with its own inspector or toolbar controls, apply the same filters so your controls follow the user’s access rules.

generateblocks.editor.areInspectorControlsDisabled

GB Free — GenerateBlocks Pro also uses it.

The generateblocks.editor.areInspectorControlsDisabled filter chooses whether a block’s inspector controls are hidden. GenerateBlocks applies it to the main controls and to the advanced controls of every block.

Parameters: isDisabled (bool), context (object with the block’s props, including area (default or advanced), defaultControls, selectedBlock and, for the main controls, replaceable). Default: true when the block’s editing mode is contentOnly or disabled, otherwise false.

wp.hooks.addFilter(
    'generateblocks.editor.areInspectorControlsDisabled',
    'my-plugin/disable-advanced-controls',
    ( isDisabled, context ) => ( 'advanced' === context.area ? true : isDisabled )
);

Related: generateblocks.editor.inspectorControls Guide: Editor Access

generateblocks.editor.areStyleControlsDisabled

GB Pro

The generateblocks.editor.areStyleControlsDisabled filter chooses whether a block’s style controls are disabled, which also decides whether the CSS editor can open for it.

Parameters: isDisabled (bool), context (object with name, attributes, clientId and selectedBlock). Default: true when the block’s editing mode is contentOnly or disabled, otherwise false.

wp.hooks.addFilter(
    'generateblocks.editor.areStyleControlsDisabled',
    'my-plugin/disable-text-styles',
    ( isDisabled, { name } ) => ( 'generateblocks/text' === name ? true : isDisabled )
);

Related: generateblocks.editor.areToolbarControlsDisabled Guide: Editor Access

generateblocks.editor.areToolbarControlsDisabled

GB Pro

The generateblocks.editor.areToolbarControlsDisabled filter chooses whether a block’s toolbar controls are hidden. GenerateBlocks Pro’s Accordion, Carousel, Form and Tabs blocks apply it to their toolbar buttons.

Parameters: isDisabled (bool), context (object with name, attributes and clientId). Default: true when the block’s editing mode is contentOnly or disabled, otherwise false.

wp.hooks.addFilter(
    'generateblocks.editor.areToolbarControlsDisabled',
    'my-plugin/disable-toolbar',
    ( isDisabled, { name } ) => ( 'generateblocks-pro/tabs' === name ? true : isDisabled )
);

Related: generateblocks.editor.areStyleControlsDisabled Guide: Editor Access

generateblocks.editor.editorAccessStateChanged

GB Pro

The generateblocks.editor.editorAccessStateChanged action fires when Editor Access is switched off or on for the current editing session, or when a person previews another access profile. Use it to refresh anything of yours that depends on what the user may edit.

Parameters: none. Default: none. It is an action.

wp.hooks.addAction(
    'generateblocks.editor.editorAccessStateChanged',
    'my-plugin/access-changed',
    () => {
        // Refresh your own controls here.
    }
);

Related: generateblocks_editor_access_capability Guide: Editor Access

Back to top