Skip to content

Instantly share code, notes, and snippets.

@julien731
Last active July 25, 2016 06:46
Show Gist options
  • Save julien731/6ce73779455bee55e634e10d41aa05cc to your computer and use it in GitHub Desktop.
Save julien731/6ce73779455bee55e634e10d41aa05cc to your computer and use it in GitHub Desktop.
Limit the number of concurrently open tickets in AS
<?php
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