[Support System] Tiered Support?

I have a scenario where there are three tiers of user roles, essentially: User, Manager, and Admin. User inquiries should go to Managers, and Manager inquiries should go to the Admin.

The Support plugin has a user-selectable dropdown for Category. Since each ticket category is assigned to a specific user, one way to do this would be to use code to use code to auto-categorize ticket submissions from specific user roles. But this is not ideal.

Another way to do this would be to only display specific categories in the dropdown to specific user roles. Then Users could not enter a ticket on a topic reserved for a Manager.

Anything I can think of for this relies on custom code. This dove-tails with my ongoing theme about making WPMU plugins more extensible so that we can hook solutions like this.

Can anyone suggest a built-in solution, existing hook, or other way to do this elegantly?

Thanks.

  • Tony G

    Hmm, looking at incsub-support\inc\helpers\capabilities.php....

    It looks like after the default $user_can is established that the support_system_user_can filter can be used to override the decision. See code provided by Adam Czajczyk here. It seems we should be able to get the ticket with incsub_support_get_ticket(), get the category from there, and then make a decision based on the current user role about what they can do with that ticket.

    Further, I see there's a filter support_system_get_ticket_categories that can be used to limit the category selection which is displayed in the dropdown.

    As with everything else, there are a number of hooks in the Support plugin code ... just no documentation for the hooks.

    As to sending tickets up from Managers to the Admin, I'm thinking a Manager can enter a ticket, then go back to update it and assign the Admin manually.

    It seems I have a way to solve this challenge but it will take a while to implement. Other ideas (or confirmations) would still be appreciated.

    Thanks!

  • viobru

    Hi, Tony!

    Hope you’re doing great and thanks for contacting us :slight_smile:

    I see that the code you’ve mentioned from Adam’s post is used to allow an additional role, different than admins, to be able to see all tickets.

    The option that you suggest is really interesting too. Since I’m not a PHP expert I’ll ping my teammates from SLS to check if they can provide a quick option to achieve this (if this requires too much customization, which would go beyond the scope of our support service, they will inform you in this ticket).

    You’ll be notified by email as soon as they post on this ticket but please note that SLS response can take more time than usual staff response, so we appreciate your patience with this :slight_smile:

    Kind regards,

    Violeta

  • Ivan

    Hi Tony G !

    You could try adding the following snippet in a MU plugin ( more info about MU plugins is here )

    <?php
    function wpmu_incsub_support_tiered_support( $cats, $args ) {
    	$assing_roles = array(
    		'User' => 'Manager',
    		'Manager' => 'administrator',
    	);
    	$user = wp_get_current_user();
        $roles = ( array ) $user->roles;
    	if ( empty( $roles ) ) {
    		return $cats;
    	}
    	foreach ( $assing_roles as $key => $val ) {
    		if ( in_array( $key, $roles ) ) {
    			$assigned_role = $val;
    			break;
    		}
    	}
    	if ( empty( $assigned_role ) ) {
    		return $cats;
    	}
    	$args = array(
    		'role' => $assigned_role,
    		'fields' => 'ID',
    	);
    	$users = get_users( $args );
    	if ( $users ) {
    		foreach ( $cats as $key => $cat ) {
    			if ( !empty( $cat->user_id ) && !in_array( $cat->user_id, $users ) ) {
    				unset( $cats[ $key ] );
    			}
    		}
    		return $cats;
    	} else {
    		return array();
    	}
    }
    add_filter( 'support_system_get_ticket_categories', 'wpmu_incsub_support_tiered_support', 10, 2 );

    Note: you should change the $assing_roles array to accurate names of your roles.

    Best,
    Ivan.