Description
The gravityflow_feedback_approval filter allows you to change the text of the feedback message on the approval step.
Parameters
Parameter | Type | Details |
---|---|---|
$feedback | String | The feedback to send to the browser. |
$entry | Entry | The current entry array. |
$assignee | Assignee | The assignee object. |
$new_status | String | The new status |
$form | Form | The current form array. |
$step | Step | The current step |
Examples
Display a custom message for a specific step ID.
add_filter( 'gravityflow_feedback_approval', 'sh_gravityflow_feedback_approval', 10, 6 );
function sh_gravityflow_feedback_approval( $feedback, $entry, $assignee, $new_status, $form, $step ) {
if ( $step->get_id() == '12' ) {$feedback = 'Thank you very much!';}
return $feedback;
}
NOTE: This filter will only run when the approval buttons are clicked on the workflow detail page. If you want to modify the feedback for the one-click approval links, you need to use the gravityflow_feedback_approval_token filter which takes the same arguments.
Customize the user field for subsequent step assignment
When the approval step has been approved, this filter updates a user field in the form (who will get next step assigned) and adds a unique note to the timeline. Ordinarily this type of logic would fit better in gravityflow_step_complete but the need to evaluate approval status combined with assignee modification and additional note led to it occurring earlier in the processing cycle.
add_filter( 'gravityflow_feedback_approval', 'jo_define_approver_to_field', 10, 6 );
function jo_define_approver_to_field( $feedback, $entry, $assignee, $new_status, $form, $step ) {
//Modify this to match the step ID of your approval step that needs customization.
$step_id_approval = 570;
//Modify this to match the field ID of the user field that you add to your form. It will be what your post-approval step gets assigned to.
$field_id_user = 4;
if ( $step->get_id() !== $step_id_approval ) {
return $feedback;
}
if ( $new_status == 'approved' ) {
$user = get_user_by( 'ID', $assignee->get_id() );
if ( $user ) {
GFAPI::update_entry_field( $entry['id'], $field_id_user, $user->ID );
$note = sprintf( esc_html__( 'Updating Post-Approval Step Assignee to: %s (%s)' ), $user->display_name, $user->ID );
$step->add_note( $note, true );
}
}
return $feedback;
}
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?