Claim allows users to own a particular task.
Typically, assignment and publish tasks are assigned to a single individual, while review process can be assigned to multiple users.
In the case, when an assignment or a publish task gets assigned to multiple individuals, “Claim” comes into play.
Why Claim?
Typically writer tasks and publisher tasks are “one person” tasks. No two users are going to publish the same article. In such cases, it’s always better to have clear understanding of who owns the task.
Even though a task can be assigned to multiple users, one has to claim the task to own it. Oasis Workflow will only show the “Claim” option if it finds a conflict in task assignment.
Once a task is claimed, the task is deleted from the inbox of other users. The person who claimed the task can then go about doing his/her work and eventually sign off from the task.
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
Use the following hook implementation to update post author after claim.
Usage:
add_action( "owf_claim_action", "update_post_author", 10, 2 );
Parameters:
$action_histories : array of action histories for the claim action.
$new_history_id : new history id created after the claim action.
Example:
add_action( "owf_claim_action", "update_post_author", 10, 2 );
function update_post_author( $action_histories, $new_history_id ) {
global $wpdb;
$ow_history_service = new OW_History_Service();
$claimed_post_history = $ow_history_service->get_action_history_by_id( $new_history_id );
// Get post id and assigned task user.
$post_id = $claimed_post_history->post_id;
$post_claimed_user = $claimed_post_history->assign_actor_id;
// update the post author here
}
Source Code
The filter is located in class-ow-process-flow.php.