Description
Allow the validation result to be overridden using the gravityflow_validation_approval filter.
Parameters
Parameter | Type | Details |
---|---|---|
$validation_result | Array | The validation result and form currently being processed |
$step | Step | The current user input step |
$new_status | String | The new status for the current step |
Examples
Prevent a specific approval step of form from being rejected without customizing the workflow note.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | add_filter( 'gravityflow_validation_approval' , 'validate_agreement_default_note' , 10, 2 ); function validate_agreement_default_note( $validation_result , $step ) { if ( $validation_result [ 'form' ][ 'id' ] == '1' && $step ->_step_type == 'approval' ) : $current_step_ID = rgpost( 'step_id' ); if ( $current_step_ID == 14 ): $note = rgpost( 'gravityflow_note' ); $new_status = rgpost( 'gravityflow_approval_new_status_step_' . $current_step_ID ); if ( $new_status == 'rejected' && $note == "I acknowledge and accept the terms and conditions listed above" ): $validation_result [ 'is_valid' ] = false; $validation_result [ 'form' ][ 'failed_validation' ] = true; $validation_result [ 'form' ][ 'workflow_note' ] = array ( 'failed_validation' => true, 'validation_message' => esc_html__( 'Please change the confirmation above to rationale for rejection' ) ); endif ; endif ; endif ; return $validation_result ; } |
Prevent the entry creator from completing an approval step
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | add_filter( 'gravityflow_validation_approval' , 'validate_entry_creator_conflict' , 10, 2 ); function validate_entry_creator_conflict( $validation_result , $step ) { // Only check for a specific step ID if ( $step ->get_id() != 443 ) { return $validation_result ; } //Only apply for logged in user $current_user = wp_get_current_user(); if ( 0 == $current_user ->ID ) { return $validation_result ; } $entry = $step ->get_entry(); $created_by_user_id = $entry [ 'created_by' ]; $error = new WP_Error( 'validation_result' , esc_html__( 'You cannot action a step for an entry that you submit.' , 'gravityflow' ), $validation_result ); // if current user is the entry creator if ( $created_by_user_id == $current_user ->ID ) { $assignees = $step ->get_assignees(); $matched = false; // loop through all assignees foreach ( $assignees as $assignee ) { switch ( $assignee ->get_type() ) { case 'user_id' : // remove when user id match return $error ; break ; case 'role' : // remove when user role match $assignee_role = $assignee ->get_id(); if ( in_array( $assignee_role , $current_user ->roles ) ) { return $error ; } break ; case 'email' : // remove when user email match $assignee_email = $assignee ->get_id(); if ( $assignee_email == $current_user ->user_email ) { return $error ; } break ; } } } return $validation_result ; } |
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?