Home / Admin / Prevent WPCode Access by User Id
Duplicate Snippet

Embed Snippet on Your Site

Prevent WPCode Access by User Id

Using this snippet you can prevent access to WPCode for users by id. Administrator users will still be able access WPCode using the WPCode Safe Mode as that bypasses all the snippets so if you don't want that you can add the code outside WPCode.

<10
Code Preview
php
<?php
add_filter( 'map_meta_cap', function ( $caps, $cap, $user_id, $args ) {
	$blocked_users       = array( 999 ); // Replace 999 with the id of the user you want to block or add more ids.
	$custom_capabilities = array(
		'wpcode_edit_php_snippets',
		'wpcode_edit_html_snippets',
		'wpcode_manage_conversion_pixels',
		'wpcode_file_editor',
		'wpcode_manage_settings',
		'wpcode_edit_snippets'
	);
	if ( in_array( $cap, $custom_capabilities, true ) && in_array( $user_id, $blocked_users, true ) ) {
		return array( 'do_not_allow' );
	}
	return $caps;
}, 500, 4 );

Comments

Add a Comment