Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • in reply to: Grant access to dashboard for specific roles/users #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.

    in reply to: Grant access to dashboard for specific roles/users #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.

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

Log in with your credentials

Forgot your details?