Created
January 31, 2024 16:04
-
-
Save danielcharrua/92384f8067cd3cca0ea75f18a668524b to your computer and use it in GitHub Desktop.
Create WordPress user with access only to WooCommerce Analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Add new role for Marketing Analytics in WooCommerce | |
* | |
* @author Daniel P. - charrua.es | |
*/ | |
$analytics_role = add_role( | |
'manage_store_analytics', | |
'Analista de la tienda', | |
array( | |
'read' => true, | |
) | |
); | |
if ( null !== $analytics_role ) { | |
$analytics_role->add_cap("view_woocommerce_reports"); | |
} | |
add_filter('woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1); | |
function _wc_disable_admin_bar($prevent_admin_access) { | |
if (!current_user_can('manage_store_analytics')) { | |
return $prevent_admin_access; | |
} | |
return false; | |
} | |
add_filter('woocommerce_prevent_admin_access', '_wc_prevent_admin_access', 10, 1); | |
function _wc_prevent_admin_access($prevent_admin_access) { | |
if (!current_user_can('manage_store_analytics')) { | |
return $prevent_admin_access; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment