Commit 803b0a57 authored by Kevin Cristiano's avatar Kevin Cristiano 🌎

initial commit of plugin to reset caps for users and add Anonymou User and...

initial commit of plugin to reset caps for users and add Anonymou User and CiviCRM Admin user if they do not exist
parents
<?php
/*
Plugin Name: Resync Default CiviCRM permissions
Plugin URI: https://tadpole.cc
Description: Resync Default CiviCRM permissions
Author: Tadpole Collective
Author URI: https://tadpole.cc
Version: 1.0
License: GPLv2
Based upon code in https://github.com/civicrm/civicrm-wordpress/blob/master/includes/civicrm.users.php
*/
function tc_reset_wp_user_capabilities() {
global $wp_roles;
if ( ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}
// Minimum capabilities (Civicrm permissions) arrays
$default_min_capabilities = array(
'access_civimail_subscribe_unsubscribe_pages' => 1,
'access_all_custom_data' => 1,
'access_uploaded_files' => 1,
'make_online_contributions' => 1,
'profile_create' => 1,
'profile_edit' => 1,
'profile_view' => 1,
'register_for_events' => 1,
'view_event_info' => 1,
'sign_civicrm_petition' => 1,
'view_public_civimail_content' => 1,
'access_ajax_api' => 1,
);
// allow other plugins to filter
$min_capabilities = apply_filters( 'civicrm_min_capabilities', $default_min_capabilities );
// Assign the Minimum capabilities (CiviCRM permissions) to all WP roles
foreach ( $wp_roles->role_names as $role => $name ) {
$roleObj = $wp_roles->get_role( $role );
foreach ( $min_capabilities as $capability_name => $capability_value ) {
$roleObj->add_cap( $capability_name );
}
}
// Minimum capabilities (Civicrm permissions) arrays
$default_admin_capabilities = array(
'read' => 1,
'access_ajax_api' => 1,
'access_all_cases_and_activities' => 1,
'access_all_custom_data' => 1,
'access_civicontribute' => 1,
'access_civicrm' => 1,
'access_civievent' => 1,
'access_civigrant' => 1,
'access_civimail' => 1,
'access_civimail_subscribe_unsubscribe_pages' => 1,
'access_civimember' => 1,
'access_civipledge' => 1,
'access_civireport' => 1,
'access_contact_dashboard' => 1,
'access_contact_reference_fields' => 1,
'access_deleted_contacts' => 1,
'access_my_cases_and_activities' => 1,
'access_report_criteria' => 1,
'access_uploaded_files' => 1,
'add_cases' => 1,
'add_contacts' => 1,
'administer_civicampaign' => 1,
'administer_civicase' => 1,
'administer_civicrm' => 1,
'administer_dedupe_rules' => 1,
'administer_reports' => 1,
'administer_reserved_groups' => 1,
'administer_reserved_reports' => 1,
'administer_reserved_tags' => 1,
'administer_tagsets' => 1,
'create_manual_batch' => 1,
'delete_activities' => 1,
'delete_all_manual_batches' => 1,
'delete_contacts' => 1,
'delete_in_civicase' => 1,
'delete_in_civicontribute' => 1,
'delete_in_civievent' => 1,
'delete_in_civigrant' => 1,
'delete_in_civimail' => 1,
'delete_in_civimember' => 1,
'delete_in_civipledge' => 1,
'delete_own_manual_batches' => 1,
'edit_all_contacts' => 1,
'edit_all_events' => 1,
'edit_all_manual_batches' => 1,
'edit_contributions' => 1,
'edit_event_participants' => 1,
'edit_grants' => 1,
'edit_groups' => 1,
'edit_memberships' => 1,
'edit_own_manual_batches' => 1,
'edit_pledges' => 1,
'export_all_manual_batches' => 1,
'export_own_manual_batches' => 1,
'gotv_campaign_contacts' => 1,
'import_contacts' => 1,
'interview_campaign_contacts' => 1,
'make_online_contributions' => 1,
'manage_campaign' => 1,
'merge_duplicate_contacts' => 1,
'profile_create' => 1,
'profile_edit' => 1,
'profile_listings' => 1,
'profile_listings_and_forms' => 1,
'profile_view' => 1,
'register_for_events' => 1,
'release_campaign_contacts' => 1,
'reserve_campaign_contacts' => 1,
'sign_civicrm_petition' => 1,
'translate_civicrm' => 1,
'view_all_activities' => 1,
'view_all_contacts' => 1,
'view_all_manual_batches' => 1,
'view_all_notes' => 1,
'view_debug_output' => 1,
'view_event_info' => 1,
'view_event_participants' => 1,
'view_own_manual_batches' => 1,
'view_public_civimail_content' => 1,
);
$admin_capabilities = apply_filters( 'civicrm_admin_capabilities', $default_admin_capabilities );
// Add the 'anonymous_user' role with minimum capabilities.
if ( ! in_array( 'anonymous_user', $wp_roles->roles ) ) {
add_role(
'anonymous_user',
__( 'Anonymous User', 'civicrm' ),
$min_capabilities
);
}
// Add the 'civicrm_admin' role with all capabilities.
if ( ! in_array( 'civicrm_admin', $wp_roles->roles ) ) {
add_role(
'civicrm_admin',
__( 'CiviCRM Administrator', 'civicrm' ),
$admin_capabilities
);
}
}
register_activation_hook( __FILE__, 'tc_reset_wp_user_capabilities' );
\ No newline at end of file
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