326 lines
8.6 KiB
PHP
326 lines
8.6 KiB
PHP
<?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' => true,
|
|
)
|
|
);
|
|
|
|
add_role(
|
|
'supplier',
|
|
'Supplier',
|
|
array(
|
|
'read' => true,
|
|
)
|
|
);
|
|
|
|
add_role(
|
|
'user',
|
|
'User',
|
|
array(
|
|
'read' => true
|
|
)
|
|
);
|
|
|
|
// 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',
|
|
)
|
|
);
|
|
|
|
update_option('aam_menu_default', array (
|
|
'menu-edit.php' => '1',
|
|
'edit.php' => '1',
|
|
'post-new.php' => '1',
|
|
'edit-tags.php?taxonomy=category' => '1',
|
|
'edit-tags.php?taxonomy=post_tag' => '1',
|
|
'menu-edit.php?post_type=page' => '1',
|
|
'edit.php?post_type=page' => '1',
|
|
'post-new.php?post_type=page' => '1',
|
|
'menu-woocommerce' => '1',
|
|
'woocommerce' => '1',
|
|
'edit.php?post_type=shop_coupon' => '1',
|
|
'edit-tags.php?taxonomy=shop_order_project' => '1',
|
|
'wc-reports' => '1',
|
|
'wc-settings' => '1',
|
|
'wc-status' => '1',
|
|
'wc-addons' => '1',
|
|
'wcj-tools' => '1',
|
|
'admin.php?page=wc-settings&tab=jetpack' => '1',
|
|
'menu-themes.php' => '1',
|
|
'themes.php' => '1',
|
|
'customize.php' => '1',
|
|
'widgets.php' => '1',
|
|
'nav-menus.php' => '1',
|
|
'custom-header' => '1',
|
|
'menu-tools.php' => '1',
|
|
'tools.php' => '1',
|
|
'import.php' => '1',
|
|
'export.php' => '1',
|
|
'export_personal_data' => '1',
|
|
'remove_personal_data' => '1',
|
|
'menu-options-general.php' => '1',
|
|
'options-general.php' => '1',
|
|
'options-writing.php' => '1',
|
|
'options-reading.php' => '1',
|
|
'options-discussion.php' => '1',
|
|
'options-media.php' => '1',
|
|
'options-permalink.php' => '1',
|
|
'privacy.php' => '1',
|
|
'radio-buttons-for-taxonomies' => '1',
|
|
'sendgrid-settings' => '1',
|
|
'menu-plugins.php' => '1',
|
|
'plugins.php' => '1',
|
|
'plugin-install.php' => '1',
|
|
'menu-groups-admin' => '1',
|
|
'groups-admin' => '1',
|
|
'groups-admin-capabilities' => '1',
|
|
'groups-admin-options' => '1',
|
|
'groups-admin-add-ons' => '1',
|
|
)
|
|
);
|
|
|
|
update_option('aam-utilities', array(
|
|
'core.settings.getStarted' => '0',
|
|
'ui.settings.renderAccessActionLink' => '0',
|
|
'core.settings.secureLogin' => '0',
|
|
'core.settings.xmlrpc' => '0',
|
|
'core.settings.cron' => '0',
|
|
'core.settings.extensionSupport' => '0',
|
|
'ui.settings.renderAccessMetabox' => '0',
|
|
'core.settings.apiAccessControl' => '0',
|
|
'core.settings.frontendAccessControl' => '0',
|
|
|
|
));
|
|
|
|
update_option('aam_menu_role_administrator', array(
|
|
'menu-edit.php' => '1',
|
|
'edit.php' => '1',
|
|
'post-new.php' => '1',
|
|
'edit-tags.php?taxonomy=category' => '1',
|
|
'edit-tags.php?taxonomy=post_tag' => '1',
|
|
'menu-edit.php?post_type=page' => '1',
|
|
'edit.php?post_type=page' => '1',
|
|
'post-new.php?post_type=page' => '1',
|
|
'menu-woocommerce' => '1',
|
|
'woocommerce' => '1',
|
|
'edit.php?post_type=shop_coupon' => '1',
|
|
'wc-reports' => '1',
|
|
'wc-settings' => '1',
|
|
'wc-status' => '1',
|
|
'wc-addons' => '1',
|
|
'wcj-tools' => '1',
|
|
'admin.php?page=wc-settings&tab=jetpack' => '1',
|
|
'menu-themes.php' => '1',
|
|
'themes.php' => '1',
|
|
'customize.php' => '1',
|
|
'widgets.php' => '1',
|
|
'nav-menus.php' => '1',
|
|
'custom-header' => '1',
|
|
'menu-tools.php' => '1',
|
|
'tools.php' => '1',
|
|
'import.php' => '1',
|
|
'export.php' => '1',
|
|
'export_personal_data' => '1',
|
|
'remove_personal_data' => '1',
|
|
'menu-options-general.php' => '1',
|
|
'options-general.php' => '1',
|
|
'options-writing.php' => '1',
|
|
'options-reading.php' => '1',
|
|
'options-discussion.php' => '1',
|
|
'options-media.php' => '1',
|
|
'options-permalink.php' => '1',
|
|
'privacy.php' => '1',
|
|
'radio-buttons-for-taxonomies' => '1',
|
|
'sendgrid-settings' => '1',
|
|
'menu-plugins.php' => '1',
|
|
'plugins.php' => '1',
|
|
'plugin-install.php' => '1',
|
|
'menu-groups-admin' => '1',
|
|
'groups-admin' => '1',
|
|
'groups-admin-capabilities' => '1',
|
|
'groups-admin-options' => '1',
|
|
'groups-admin-add-ons' => '1',
|
|
'menu-edit-comments.php' => '1',
|
|
));
|
|
|
|
update_option('aam_metabox_default', array(
|
|
'dashboard' =>
|
|
array (
|
|
'rg_forms_dashboard' => '1',
|
|
'dashboard_quick_press' => '1',
|
|
'dashboard_primary' => '1',
|
|
'woocommerce_dashboard_status' => '1',
|
|
'dashboard_activity' => '1',
|
|
),
|
|
));
|
|
|
|
update_option('aam_metabox_role_administrator', array(
|
|
'dashboard' =>
|
|
array (
|
|
'rg_forms_dashboard' => '1',
|
|
'dashboard_quick_press' => '1',
|
|
'dashboard_primary' => '1',
|
|
'woocommerce_dashboard_status' => '1',
|
|
'dashboard_activity' => '1',
|
|
'dashboard_right_now' => '1',
|
|
),
|
|
));
|
|
}
|
|
|
|
function wiaas_db_update_update_commercial_lead_capabilities() {
|
|
// add commercial lead specific roles
|
|
|
|
wp_roles()->add_cap( 'commercial_lead', 'view_admin_dashboard' );
|
|
wp_roles()->add_cap( 'commercial_lead', 'read' );
|
|
wp_roles()->add_cap( 'commercial_lead', 'upload_files' );
|
|
|
|
// enable commercial leads to see Products tab
|
|
wp_roles()->add_cap( 'commercial_lead', 'edit_products' );
|
|
wp_roles()->add_cap( 'commercial_lead', 'edit_others_products' );
|
|
// enable commercial leads to set extra prices on products
|
|
wp_roles()->add_cap( 'commercial_lead', 'manage_wiaas_cl_products' );
|
|
|
|
// enable commercial leads to see Orders tab
|
|
wp_roles()->add_cap( 'commercial_lead', 'edit_shop_orders' );
|
|
|
|
// enable commercial leads to se Customers tab
|
|
wp_roles()->add_cap( 'commercial_lead', 'manage_wiaas_cl_customers' );
|
|
}
|
|
|
|
function wiaas_db_update_update_supplier_capabilities() {
|
|
// add supplier specific roles
|
|
wp_roles()->add_cap( 'supplier', 'view_admin_dashboard' );
|
|
wp_roles()->add_cap( 'supplier', 'read' );
|
|
}
|
|
|
|
function wiaas_db_update_update_admin_capabilities() {
|
|
wp_roles()->add_cap( 'administrator', 'create_products' );
|
|
wp_roles()->add_cap( 'administrator', 'manage_wiaas_order_projects' );
|
|
}
|
|
|
|
|
|
function wiaas_admin_create_role_access_groups() {
|
|
Groups_Group::create(array(
|
|
'name' => 'admin',
|
|
));
|
|
}
|
|
|
|
function wiaas_db_update_update_supplier_order_capabilities() {
|
|
// add supplier role to view orders
|
|
wp_roles()->add_cap( 'supplier', 'edit_shop_orders' );
|
|
}
|
|
|
|
function wiaas_db_update_enable_workflow_inbox_for_roles() {
|
|
// add workflow inbox for supplier
|
|
wp_roles()->add_cap( 'supplier', 'gravityflow_inbox' );
|
|
// add workflow inbox for commercial lead
|
|
wp_roles()->add_cap( 'commercial_lead', 'gravityflow_inbox' );
|
|
|
|
} |