$allcaps The user's capabilities. * @return array */ public static function grant( $allcaps ) { if ( ! empty( $allcaps[ self::SETTINGS ] ) ) { $allcaps[ self::MANAGE ] = true; } if ( ! empty( $allcaps[ self::MANAGE ] ) ) { $allcaps[ self::VIEW ] = true; } return $allcaps; } /** * Activation: add both capabilities to the Administrator role (capability registration, §9.7). * * @return void */ public static function add_to_roles() { $role = get_role( 'administrator' ); if ( $role ) { $role->add_cap( self::MANAGE ); $role->add_cap( self::VIEW ); } } /** * Uninstall: remove them from every role they were granted to. * * @return void */ public static function remove_from_roles() { foreach ( wp_roles()->role_objects as $role ) { $role->remove_cap( self::MANAGE ); $role->remove_cap( self::VIEW ); } } /** @return bool */ public static function can_view() { return current_user_can( self::VIEW ); } /** @return bool */ public static function can_manage() { return current_user_can( self::MANAGE ); } /** @return bool */ public static function can_configure() { return current_user_can( self::SETTINGS ); } }