• Resolved lukag

    (@lukag)


    I created a custom capability and it added it correctly, but i would like to delete the capability but there is no option to do so… so how do I delete a custom capability from my list of permissions?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Caseproof LLC

    (@caseproof)

    Hi @lukag

    Unfortunately, there’s currently no way to remove capabilities that are created. The only way to actually “remove” them would be to modify the database option that stores the roles and capabilities. Otherwise, simply denying a role that capability will have the same effect.

    Cheers

    @lukag – you can use the following php snippet. In this example I am removing unwanted capabilities after removing MailPoet plugin. Fill the array as required and run the snippet once. You would need to disable or comment out this snippet straight after you run it. Hope this helps.

    // Function to delete capabilities
    // Based on http://chrisburbridge.com/delete-unwanted-wordpress-custom-capabilities/
    add_action( 'admin_init', 'clean_unwanted_caps' );
    function clean_unwanted_caps() {
    	global $wp_roles;
    	$delete_caps = array(
    		'mailpoet_access_plugin_admin',
    		'mailpoet_manage_emails',
    		'mailpoet_manage_features',
    		'mailpoet_manage_forms',
    		'mailpoet_manage_segments',
    		'mailpoet_manage_settings',
    		'mailpoet_manage_subscribers',
    	 );
    	foreach ($delete_caps as $cap) {
    		foreach (array_keys($wp_roles->roles) as $role) {
    			$wp_roles->remove_cap($role, $cap);
    		}
    	}
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How to delete custom capability’ is closed to new replies.