Hiding controls

The abcon/editor/show_controls hook provides a flexible way for developers to control the visibility of controls for all blocks. This hook allows you to customize the editing interface based on specific conditions, such as user roles or custom logic.

Example 1: Hiding All Controls for All Users #

If you want to hide all block controls for all users, you can use the following code snippet. This code should be added to your theme’s functions.php file or a custom plugin:

function custom_abcon_hide_controls($show_controls) {
    return false; // This will hide all controls
}
add_filter('abcon/editor/show_controls', 'custom_abcon_hide_controls');

By returning false, all block controls will be hidden from all users.

Example 2: Displaying Controls Based on User Role #

You can also conditionally display the controls based on the user’s role. For example, if you want only administrators to see the controls, you can use the following code:

function custom_abcon_show_controls_for_admins($show_controls) {
    if (!current_user_can('administrator')) {
        return false; // Hide controls for non-administrators
    }
    return $show_controls; // Show controls for administrators
}
add_filter('abcon/editor/show_controls', 'custom_abcon_show_controls_for_admins');

This code checks the user’s role and only shows the controls to administrators. Non-administrators will not see the controls.

What are your feelings
Updated on June 17, 2024