The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Restrict Available Gutenberg Blocks Based on User Role

Shared by Alkesh Miyani · October 31, 2026 · @allowed_block_types_all

15 views
Back to Snippets

Not every WordPress user needs access to every Gutenberg block.

For example, administrators may need access to all available blocks, while authors and contributors should only have access to a selected set of blocks.

This snippet restricts the Gutenberg block inserter based on the current user’s WordPress role. It allows administrators to configure which blocks are available to Editors, Authors, Contributors, and other custom roles.

How to use

  1. Add the code to your child theme’s functions.php file or a PHP snippets plugin.
  2. Open the $role_blocks configuration array.
  3. Add or remove block names according to your editorial requirements.
  4. Log in using different WordPress user accounts.
  5. Open the Gutenberg editor and check the available blocks in the inserter.

Example configuration

WordPress role Block access
Administrator All blocks
Editor All blocks
Author Selected content blocks
Contributor Basic writing blocks
Subscriber No blocks configured

Adding custom user roles

You can add custom roles to the $role_blocks array.

For example:

'custom_editor' => array(
    'core/paragraph',
    'core/heading',
    'core/image',
),

Replace custom_editor with the actual role slug registered on your website.

Important notes

/**
 * Restrict available Gutenberg blocks based on user roles.
 */
add_filter(
	'allowed_block_types_all',
	'alkesh_restrict_gutenberg_blocks_by_role',
	20,
	2
);

function alkesh_restrict_gutenberg_blocks_by_role(
	$allowed_block_types,
	$editor_context
) {
	// Allow administrators to use all available blocks.
	if ( current_user_can( 'manage_options' ) ) {
		return $allowed_block_types;
	}

	$user = wp_get_current_user();

	if ( empty( $user->roles ) ) {
		return $allowed_block_types;
	}

	/*
	 * Configure allowed blocks for each user role.
	 * Use null to allow all blocks for a particular role.
	 */
	$role_blocks = array(
		'editor' => null,

		'author' => array(
			'core/paragraph',
			'core/heading',
			'core/image',
			'core/list',
			'core/list-item',
			'core/quote',
			'core/separator',
			'core/spacer',
		),

		'contributor' => array(
			'core/paragraph',
			'core/heading',
			'core/list',
			'core/list-item',
			'core/quote',
		),

		'subscriber' => array(),
	);

	$allowed_for_user = array();

	foreach ( $user->roles as $role ) {
		if ( ! array_key_exists( $role, $role_blocks ) ) {
			continue;
		}

		// A role with null configuration has unrestricted block access.
		if ( null === $role_blocks[ $role ] ) {
			return $allowed_block_types;
		}

		$allowed_for_user = array_merge(
			$allowed_for_user,
			$role_blocks[ $role ]
		);
	}

	// Remove duplicate block names.
	$allowed_for_user = array_unique( $allowed_for_user );

	// Respect restrictions applied by other filters.
	if ( false === $allowed_block_types ) {
		return false;
	}

	if ( is_array( $allowed_block_types ) ) {
		$allowed_for_user = array_intersect(
			$allowed_for_user,
			$allowed_block_types
		);
	}

	return array_values( $allowed_for_user );
}

Tested on

WordPress 7.1.4 Gutenberg

Reported by the author on October 31, 2026. WPFolks has not verified this.

Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

1 comment

  1. Amit Dholiya
    Amit Dholiya @amitdholiya

    Useful snippet for keeping the editor clean on multi-author sites. Restricting the Gutenberg block inserter by user role means contributors and authors only see the blocks they need, which helps protect layouts and keeps content consistent. The $role_blocks array makes it easy to adjust per role, including custom roles.

    Report

Proudly supported by