WordPress: How Remove Subcriber’s Permission to View WP Profile

Sometimes your theme requires that the Subscribers group shouldn’t be allowed to view their profile page or modify their account information.

In order to achieve this, you must remove the user level’s capability to view their account page.

Add the following script to your functions.php to remove the permission

{code type=”}
add_action( ‘admin_init’, ‘theme_admin_init’ );
function theme_admin_init(){
global $wp_roles;
$wp_roles->remove_cap( ‘subscriber’, ‘read’ );
}
{/code}

On the other hand, if you need to add the permission back, just use the code below.

{code type=”}
add_action( ‘admin_init’, ‘theme_admin_init’ );
function theme_admin_init(){
$role = get_role( ‘subscriber’ );
$role->add_cap( ‘read’ );
}
{/code}

WordPress Readings and Resources

Recommended Posts