Skip to content

Instantly share code, notes, and snippets.

Last active July 25, 2016 06:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Limit the number of concurrently open tickets in AS
add_filter( 'wpas_before_submit_new_ticket_checks', 'wpas_limit_concurrently_open_tickets' );
* Limit the Number of Concurrent Open Tickets
* @param bool|WP_Error $go Submission status
* @return bool|WP_Error
function wpas_limit_concurrently_open_tickets( $go ) {
var_dump( $go );
$user_id = get_current_user_id();
$open_tickets = wpas_get_user_tickets( $user_id, 'open' );
$limit = 1; // Set the maximum number of open ticket a user can have at any given time
$count = count( $open_tickets );
if ( $count >= $limit ) {
// Make sure $go is not already errored
if ( ! is_wp_error( $go ) ) {
$go = new WP_Error();
// Add a custom error message
$go->add( 'too_many_open_tickets', sprintf( 'You can not have more than %1$d tickets open at the same time (you currently have %2$d open tickets). Please close your tickets before opening a new one.', $limit, $count ) );
return $go;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment