This topic has 3 replies, 1 voice, and was last updated 8 years by verloren.

  • Author
  • #107230
     verloren
    Participant

    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!

     

    #107273
     verloren
    Participant

    Hi 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 CODE
    
    public 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.

    #107278
     verloren
    Participant

    Instead 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.

    #107279
     verloren
    Participant

    Instead of removing the action, it’s better to add a filter which hooks into “prevent_admin_access”.
    Here an example:

    COPY CODE
    
    add_filter(‘woocommerce_prevent_admin_access’, ‘preventAdminAccess’);
    
    function preventAdminAccess() {
    $prevent = false;
    
    if (userShouldNotSeeDashboard()) {
    $prevent = true;
    }
    
    return $prevent;
    }
    

    Best regards.

Viewing 4 posts - 1 through 4 (of 4 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?