handle user roles by organization
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,90 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bbe558ba265c",
|
||||
"title": "Organization Info",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bbe5c0d1f1a7",
|
||||
"label": "Phone",
|
||||
"name": "_wiaas_organization_phone",
|
||||
"type": "text",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": "",
|
||||
"placeholder": "",
|
||||
"prepend": "",
|
||||
"append": "",
|
||||
"maxlength": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bbe5c291f1a8",
|
||||
"label": "VAT Code",
|
||||
"name": "_wiaas_organization_vat",
|
||||
"type": "text",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": "",
|
||||
"placeholder": "",
|
||||
"prepend": "",
|
||||
"append": "",
|
||||
"maxlength": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bbe559d66d17",
|
||||
"label": "Roles",
|
||||
"name": "_wiaas_organization_roles",
|
||||
"type": "select",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"choices": {
|
||||
"administrator": "Administrator",
|
||||
"supplier": "Supplier",
|
||||
"commercial_lead": "Commercial Lead",
|
||||
"customer": "Customer"
|
||||
},
|
||||
"default_value": [],
|
||||
"allow_null": 0,
|
||||
"multiple": 1,
|
||||
"ui": 1,
|
||||
"ajax": 1,
|
||||
"return_format": "label",
|
||||
"placeholder": ""
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "taxonomy",
|
||||
"operator": "==",
|
||||
"value": "wiaas-user-organization"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "normal",
|
||||
"style": "seamless",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "field",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,52 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bbce9f38f149",
|
||||
"title": "User Organization",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bbe54366aac1",
|
||||
"label": "Organization",
|
||||
"name": "_wiaas_organization_id",
|
||||
"type": "taxonomy",
|
||||
"instructions": "Select Organization for user",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "wiaas-user-organization",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 0,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "user_form",
|
||||
"operator": "==",
|
||||
"value": "edit"
|
||||
},
|
||||
{
|
||||
"param": "current_user_role",
|
||||
"operator": "==",
|
||||
"value": "administrator"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "normal",
|
||||
"style": "seamless",
|
||||
"label_placement": "left",
|
||||
"instruction_placement": "field",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Wiaas DB updates
|
||||
* General Wiaas DB updates
|
||||
*
|
||||
* Functions for updating database to latest version
|
||||
* General functions for updating wiaas database to latest version
|
||||
*/
|
||||
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Roles Wiaas DB updates
|
||||
*
|
||||
* Functions for updating wiaas roles in database
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
function wiaas_db_update_create_default_roles() {
|
||||
$roles = array(
|
||||
'customer', // this role will be created by woocommerce so we do not have to create it here
|
||||
'supplier',
|
||||
'commercial_lead'
|
||||
);
|
||||
|
||||
// remove wordpress default roles
|
||||
remove_role('author');
|
||||
remove_role('contributor');
|
||||
remove_role('editor');
|
||||
remove_role('subscriber');
|
||||
|
||||
// remove woocoommerce shop manager role
|
||||
remove_role('shop_manager');
|
||||
|
||||
// Dummy gettext calls to get strings in the catalog.
|
||||
/* translators: user role */
|
||||
_x( 'Supplier', 'User role', 'wiaas' );
|
||||
/* translators: user role */
|
||||
_x( 'Commercial Lead', 'User role', 'wiaas' );
|
||||
|
||||
// Add wiaas roles
|
||||
add_role(
|
||||
'commercial_lead',
|
||||
'Commercial Lead',
|
||||
array(
|
||||
'read',
|
||||
'view_admin_dashboard'
|
||||
)
|
||||
);
|
||||
|
||||
add_role(
|
||||
'supplier',
|
||||
'Supplier',
|
||||
array(
|
||||
'read',
|
||||
'view_admin_dashboard'
|
||||
)
|
||||
);
|
||||
|
||||
add_role(
|
||||
'user',
|
||||
'User',
|
||||
array(
|
||||
'read'
|
||||
)
|
||||
);
|
||||
|
||||
// set default wiaas role
|
||||
update_option('default_role', 'user');
|
||||
|
||||
// capabilities
|
||||
|
||||
$capabilities = array();
|
||||
|
||||
$capability_types = array( 'wiaas_doc' );
|
||||
|
||||
foreach ( $capability_types as $capability_type ) {
|
||||
|
||||
$capabilities[ $capability_type ] = array(
|
||||
// Post type.
|
||||
"edit_{$capability_type}",
|
||||
"read_{$capability_type}",
|
||||
"delete_{$capability_type}",
|
||||
"edit_{$capability_type}s",
|
||||
"edit_others_{$capability_type}s",
|
||||
"publish_{$capability_type}s",
|
||||
"read_private_{$capability_type}s",
|
||||
"delete_{$capability_type}s",
|
||||
"delete_private_{$capability_type}s",
|
||||
"delete_published_{$capability_type}s",
|
||||
"delete_others_{$capability_type}s",
|
||||
"edit_private_{$capability_type}s",
|
||||
"edit_published_{$capability_type}s",
|
||||
|
||||
// Terms.
|
||||
"manage_{$capability_type}_terms",
|
||||
"edit_{$capability_type}_terms",
|
||||
"delete_{$capability_type}_terms",
|
||||
"assign_{$capability_type}_terms",
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $capabilities as $cap_group ) {
|
||||
foreach ( $cap_group as $cap ) {
|
||||
wp_roles()->add_cap( 'administrator', $cap );
|
||||
wp_roles()->add_cap( 'commercial_lead', $cap );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function wiaas_db_import_aam_role_settings() {
|
||||
// update role settings that are imported
|
||||
$content = file_get_contents( dirname( __FILE__ ) . '/data/aam-settings.json' );
|
||||
|
||||
$importer = new AAM_Core_Importer($content);
|
||||
|
||||
$importer->run();
|
||||
|
||||
// update toolbar settins manually since it does not get imported
|
||||
update_option('aam_toolbar_default', array (
|
||||
'about' => '1',
|
||||
'toolbar-wp-logo' => '1',
|
||||
'wporg' => '1',
|
||||
'documentation' => '1',
|
||||
'support-forums' => '1',
|
||||
'feedback' => '1',
|
||||
'toolbar-site-name' => '0',
|
||||
'view-site' => '1',
|
||||
'view-store' => '1',
|
||||
'toolbar-updates' => '1',
|
||||
'toolbar-comments' => '1',
|
||||
'toolbar-new-content' => '1',
|
||||
'new-post' => '1',
|
||||
'new-media' => '1',
|
||||
'new-page' => '1',
|
||||
'new-product' => '1',
|
||||
'new-shop_order' => '1',
|
||||
'new-shop_coupon' => '1',
|
||||
'new-wiaas_doc' => '1',
|
||||
'new-user' => '1',
|
||||
'gravityforms-new-form' => '1',
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
function wiaas_db_update_add_organization_info_ui_fields() {
|
||||
|
||||
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-organization-info.json' );
|
||||
|
||||
$ui_json = json_decode( $ui_json, true );
|
||||
|
||||
acf_import_field_group($ui_json[0]);
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_user_organization_ui_fields() {
|
||||
|
||||
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-user-organization.json' );
|
||||
|
||||
$ui_json = json_decode( $ui_json, true );
|
||||
|
||||
acf_import_field_group($ui_json[0]);
|
||||
}
|
||||
Reference in New Issue
Block a user