Commit 2fff189a authored by Christian Wach's avatar Christian Wach

Apply min caps to all roles

parent a8a4636e
......@@ -121,8 +121,8 @@ class CiviCRM_Permissions_Sync {
* role-related changes are made, so use that.
*/
// Add to minimum CiviCRM capabilities.
add_action( 'init', [ $this, 'capabilities_anon' ], 100 );
// Add minimum CiviCRM capabilities to all roles.
add_action( 'init', [ $this, 'capabilities_all_roles' ], 100 );
// Sync late on init.
add_action( 'init', [ $this, 'capabilities_sync' ], 100 );
......@@ -185,30 +185,25 @@ class CiviCRM_Permissions_Sync {
/**
* Filter minimum CiviCRM capabilities for the anonymous user.
* Add minimum CiviCRM capabilities to all roles.
*
* This method adds a few capabilities which many CiviCRM installs need to
* function as expected.
*
* @since 1.0
*/
public function capabilities_anon() {
public function capabilities_all_roles() {
// Fetch roles object.
$wp_roles = wp_roles();
// Bail if the anonymous_user role does not exist.
if ( ! $wp_roles->is_role( 'anonymous_user' ) ) {
return;
}
// Get anonymous_user role.
$anon = $wp_roles->get_role( 'anonymous_user' );
// Add the capabilities if not already added.
foreach( $this->min_capabilities AS $capability => $value ) {
if ( ! $anon->has_cap( $capability ) ) {
$anon->add_cap( $capability );
// Add capabilities to all roles if not already added.
foreach( $wp_roles->role_names AS $role_name => $title ) {
$role = $wp_roles->get_role( $role_name );
foreach( $this->min_capabilities AS $capability => $value ) {
if ( ! $role->has_cap( $capability ) ) {
$role->add_cap( $capability );
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment