function annowf_switch_authors($post_id, $post, $post_before) { // Author has changed, add original author as co-author, remove new author from co-authors if ($post->post_author !== $post_before->post_author && in_array($post_before->post_author, anno_get_authors($post->ID))) { anno_add_user_to_post('author', $post_before->post_author, $post->ID); anno_remove_user_from_post('author', $post->post_author, $post->ID); if (anno_workflow_enabled('notifications')) { annowf_send_notification('primary_author', $post, null, array(anno_user_email($post->post_author))); } } }
/** * Article state transistioning. Fires after post has been inserted into the database */ function annowf_transistion_state($post_id, $post, $post_before) { if ($post->post_type == 'article' && $post->post_status != 'auto-draft') { global $anno_post_save; $current_user = wp_get_current_user(); $old_state = get_post_meta($post->ID, '_post_state', true); $new_state = $old_state; if (empty($old_state)) { $old_state = 'draft'; } if (isset($_POST['revert']) && $_POST['revert'] == $anno_post_save['revert']) { $new_state = 'draft'; } else { if (isset($_POST['publish'])) { switch ($_POST['publish']) { // Make sure theres the ability to revert posts if they get a state on accident. case $anno_post_save['revert']: $new_state = 'draft'; break; case $anno_post_save['approve']: // Ensure proper state transitions if (in_array($old_state, array('submitted', 'in_review'))) { $new_state = 'approved'; } break; case $anno_post_save['revisions']: if (in_array($old_state, array('submitted', 'in_review'))) { $new_state = 'draft'; } break; case $anno_post_save['reject']: // Publishing staff can still reject even if editor approves if (in_array($old_state, array('submitted', 'in_review', 'approved'))) { $new_state = 'rejected'; } break; case $anno_post_save['publish']: if ($old_state == 'approved') { $new_state = 'published'; } break; case $anno_post_save['review']: $reviewers = anno_get_reviewers($post->ID); if (is_array($reviewers) && count($reviewers) && in_array($old_state, array('submitted', 'draft'))) { $new_state = 'in_review'; } else { if ($old_state == 'draft') { $new_state = 'submitted'; } } break; default: break; } } } $notification_type = $new_state; if ($old_state == 'draft' && $new_state == 'in_review') { $notification_type = 're_review'; } // Send back for revisions if ($new_state == 'draft' && !empty($old_state) && $old_state != 'draft') { $round = annowf_get_round($post_id); update_post_meta($post_id, '_round', intval($round) + 1); $notification_type = 'revisions'; } if ($new_state != $old_state) { if (empty($new_state)) { $new_state = 'draft'; } update_post_meta($post->ID, '_post_state', $new_state); do_action('anno_state_change', $new_state, $old_state); // Save to audit log annowf_save_audit_item($post->ID, $current_user->ID, 2, array($old_state, $new_state)); // Send notifications, but not for published to draft state if (anno_workflow_enabled('notifications') && !($old_state == 'published' && $new_state == 'draft')) { annowf_send_notification($notification_type, $post); } } // Author has changed, add original author as co-author, remove new author from co-authors if ($post->post_author !== $post_before->post_author) { annowf_add_user_to_post('author', $post_before->post_author, $post->ID); annowf_remove_user_from_post('author', $post->post_author, $post->ID); if (anno_workflow_enabled('notifications')) { annowf_send_notification('primary_author', $post, null, array(anno_user_email($post->post_author))); } } } }