Skip to content

Instantly share code, notes, and snippets.

@julien731
Last active July 25, 2016 00:32
Show Gist options
  • Save julien731/78443cc09595c5552b0c711d583698ba to your computer and use it in GitHub Desktop.
Save julien731/78443cc09595c5552b0c711d583698ba to your computer and use it in GitHub Desktop.
Add extra verification to AS submission process
<?php
add_filter( 'wpas_before_submit_new_ticket_checks', 'wpas_extra_submission_check' );
/**
* Add extra verifications to the ticket submission process
*
* @param bool|WP_Error $go The submission authorization status
* @return bool|WP_Error
*/
function wpas_extra_submission_check( $go ) {
// Check something
if ( 1 !== 2 ) {
/**
* If the check fails, we create an error to display to the user.
* The $go variable could potentially be errored already (from a custom field for instance), in which case
* we don't want to override the existing errors. For that reason, we only create a WP_Error object if $go
* isn't one already.
*/
// Make sure $go is not already errored
if ( ! is_wp_error( $go ) ) {
$go = new WP_Error();
}
// Add a custom error message
$go->add( 'custom_error_code', 'Explanation of why the submission fails (will be displayed to the user)' );
}
return $go;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment