Pre-Claim Filter

Description

The action filter is executed when the user is trying to claim a task.

Use this filter to add any pre validation before a user can claim a task. For example, if you want to limit the number of tasks a user can actively work on, you can restrict the user from claiming additional tasks.

Usage

add_filter( 'owf_claim_process_pre', array( 'pre_validate_claim', 10, 4 );

Parameters

  • $validation_result – Array of Validation Messages. Add your validation message to this array.
  • $action_history_id – Action History ID, will be used to retrieve any information related to the current task.
  • $post_id – ID of the post.
  • $user_id – ID of the user claiming the task.

Example


add_filter( 'owf_claim_process_pre', 'pre_validate_claim', 10, 4 );

// a user cannot have more than 5 assignments in his/her inbox.
function pre_validate_claim( $validation_result, $action_history_id, $post_id, $user_id ) {
   // sanitize data
   $action_history_id = intval( $action_history_id );
   $post_id = intval( $post_id );
   $user_id = intval( $user_id );
   $assigned_task_count = 0;

   $ow_process_flow = new OW_Process_Flow();

   $assigned_tasks = $ow_process_flow->get_assigned_post( null, $user_id );

   foreach( $assigned_tasks as $assigned_task ) {
      if( ! $ow_process_flow->check_for_claim( $assigned_task->ID) ) { // if this task is already claimed
         $assigned_task_count++;
      }
   }

   if ( $assigned_task_count >= 2 ) {
      $error_messages[] = __( "You cannot claim additional tasks, since you already have more than 5 assignments.", 'oasisworkflow' );
      $validation_result = array_merge( $validation_result, $error_messages );
   }

   return $validation_result;
}

Source Code

The filter is located in class-ow-process-flow.php