gravityflow_admin_actions_workflow_detail

The gravityflow_admin_actions_workflow_detail filter can be used to add or remove choices from the admin actions drop down on the workflow detail page. If you use it to create a custom admin action, you will need to also hook onto gravityflow_admin_action_feedback filter to process custom choice(s).

Parameters

$admin_actions  boolean

Defaults to true.

$current_step  boolean|Gravity_Flow_Step

The current step.

$steps Gravity_Flow_Step[]

An array of steps for the current form.

$form  Form Object

The current form.

$entry  Entry Object

The current entry.

Examples

Example 1

The following example shows how you can add a new choice to the admin actions drop down.

add_filter( 'gravityflow_admin_actions_workflow_detail', 'filter_admin_actions_workflow_detail', 10, 5 );
function filter_admin_actions_workflow_detail( $admin_actions, $current_step, $steps, $form, $entry ) {
    $admin_actions[] = array( 'label' => 'your new action', 'value' => 'your_new_action' );

    return $admin_actions;
}

Example 2

The following example shows how you can add a new choice to the admin actions drop down limited to display on completed entries.

add_filter( 'gravityflow_admin_actions_workflow_detail', 'filter_admin_actions_workflow_detail', 10, 5 );
function filter_admin_actions_workflow_detail( $admin_actions, $current_step, $steps, $form, $entry ) {
	if( gform_get_meta( $entry['id'], 'workflow_final_status' ) == 'complete') {
		$admin_actions[] = array( 'label' => 'Cancel Completed Workflow', 'value' => 'sh_cancel_completed_workflow' );
	}
	return $admin_actions;
}

Example 3

The following example shows how you can add a new optgroup to the admin actions drop down

add_filter( 'gravityflow_admin_actions_workflow_detail', 'admin_actions_add_optgroup', 10, 5 );
function admin_actions_add_optgroup( $admin_actions, $current_step, $steps, $form, $entry ) {
   $admin_actions[] = array(
      'label'   => esc_html__( 'Your custom optgroup:', 'gravityflow' ),
      'choices' => array(
         array(
            'label' => 'Choice 1',
            'value' => 'custom_optgroup|choice_1'
         ),
         array(
            'label' => 'Choice 2',
            'value' => 'custom_optgroup|choice_2'
         ),
      )
   );

   return $admin_actions;
}

Example 4

By default, the 'Send to Step' options include all active steps in a workflow. The following example shows how you can adjust the 'Send to Step' options to only show a subset based on if they meet their step conditions. Note that step conditions can also be customized through the gravityflow_step_is_condition_met filter.

add_filter( 'gravityflow_admin_actions_workflow_detail', 'jo_gravityflow_admin_actions_workflow_detail', 10, 5 );
function jo_gravityflow_admin_actions_workflow_detail( $admin_actions, $current_step, $steps, $form, $entry ) {

	foreach ( $admin_actions as $action_key => $action ) {
		//May need to adjust if you are using a multi-lingual site
		if ( isset( $action['choices'] ) && $action['label'] == 'Send to step:') {
			if ( count( $steps ) > 1 ) {
				$new_choices = array();					
				foreach ( $steps as $potential_step ) {
					if ( ! $potential_step->is_active() || ! $potential_step->is_condition_met( $form ) ) {
						continue;
					}
					$new_choices[] = array(
						'label' => $potential_step->get_name(),
						'value' => 'send_to_step|' . $potential_step->get_id()
					);
				}
			}
			$admin_actions[ $action_key ]['choices'] = $new_choices;
		}
	}
	return $admin_actions;
}

Example 5

Showing how to customize the drop-down based on the user role who is accessing the page. It either returns no options in the case of a non-administrator, or only a sub-set of options if it is an administrator. This example is more of a reference implementation that is meant to be customized to fit your your use case.

add_filter( 'gravityflow_admin_actions_workflow_detail', 'jo_filter_admin_actions_workflow_detail', 10, 5 );
function filter_admin_actions_workflow_detail( $admin_actions, $current_step, $steps, $form, $entry ) {
	$new_actions = array();

	$current_user = wp_get_current_user();
	if ( ! ( $current_user instanceof WP_User ) ) {
		return $new_actions;
	}

	if ( isset( $current_user->roles ) && in_array( 'administrator', $current_user->roles ) ) {
		$new_actions = array();

		//To specify a new custom action
		$new_actions[] = array( 'label' => 'Cancel Completed Workflow', 'value' => 'sh_custom_action_function' );

		//Or you could loop through existing $admin_actions to determine which ones you want to map to the new array
		foreach ( $admin_actions as $potential_action ) {
			//optgroups like Send to Step do not have value at top level, you may want to also check/adjust $potential_action['choices']
			if ( isset( $potential_action['value'] ) && in_array( $potential_action['value'], array( 'restart_step', 'restart_workflow' ) ) ) {
				$new_actions[] = $potential_action;
			}
		}
	}
	return $new_actions;
}