-
Author
-
February 28, 2016 at 17:29 #107230verlorenParticipant
Hi all,
is it possible to grant access to dashboard for specific roles and or specific users? I have several “country manager” which all need access to dashboard. More detailed, they need access to wpml string translation for translating the website into several languages.
At the moment only admins can login to dashboard/backend. I couldn’t find any settings or rules for this behavior.
Hope you can help me.
Best regards!
February 28, 2016 at 21:41 #107273verlorenParticipantHi all,
found it.
In /wp-content/plugins/woocommerce/includes/admin/class-wc-admin.php is function “prevent_admin_access”. Here the docblock:
COPY CODE/** * Prevent any user who cannot 'edit_posts' (subscribers, customers etc) from accessing admin. */
Within class-wc-admin.php constructor, the action is added:
COPY CODEpublic function __construct() { ... add_action( 'admin_init', array( $this, 'prevent_admin_access' ) ); }
So from here it’s easy to remove the action and add an own action.
Best regards.
February 28, 2016 at 22:45 #107278verlorenParticipantInstead of removing the action, it’s better to add a filter which hooks into “prevent_admin_access”.
Here an example:`
add_filter(‘woocommerce_prevent_admin_access’, ‘preventAdminAccess’);function preventAdminAccess() {
$prevent = false;if (userShouldNotSeeDashboard()) {
$prevent = true;
}return $prevent;
}Best regards.
February 28, 2016 at 22:46 #107279verlorenParticipantInstead of removing the action, it’s better to add a filter which hooks into “prevent_admin_access”.
Here an example:COPY CODEadd_filter(‘woocommerce_prevent_admin_access’, ‘preventAdminAccess’); function preventAdminAccess() { $prevent = false; if (userShouldNotSeeDashboard()) { $prevent = true; } return $prevent; }
Best regards.
-
AuthorPosts
The forum ‘General questions’ is closed to new topics and replies.