/** * Handles AJAX request for adding a co-author to a post. */ function annowf_add_co_author() { $response = annowf_add_user('co_author'); if ($response['message'] == 'success') { // Used for quick access when filtering posts on a post-author page $post_id = absint($_POST['post_id']); // Send email if (anno_workflow_enabled('notifications')) { $post = get_post($post_id); annowf_send_notification('co_author_added', $post, '', array($response['user']->user_email), $response['user']); } // Add author to JSON for appending to author dropdown $response['author'] = '<option value="' . $response['user']->ID . '">' . $response['user']->user_login . '</option>'; //Add to the audit log $current_user = wp_get_current_user(); annowf_save_audit_item($post_id, $current_user->ID, 6, array($response['user']->ID)); } unset($response['user']); echo json_encode($response); die; }
/** * Processes an AJAX request when submitting a review from the dropdown. */ function anno_internal_comments_review_ajax() { check_ajax_referer('anno_review', '_ajax_nonce-review'); if (isset($_POST['post_id']) && isset($_POST['review'])) { global $current_user; $post_id = absint($_POST['post_id']); $review = $_POST['review']; $post_round = annowf_get_round($post_id); update_user_meta($current_user->ID, '_' . $post_id . '_review_' . $post_round, $review); $reviewed = get_post_meta($post_id, '_round_' . $post_round . '_reviewed', true); if (!is_array($reviewed)) { $reviewed = array(); } // If review is set to none, remove the user from reviewed, otherwise update it with the current user. if ($review != 0) { // Keep track that this user has left a review on the post if (!in_array($current_user->ID, $reviewed)) { $reviewed[] = $current_user->ID; update_post_meta($post_id, '_round_' . $post_round . '_reviewed', array_unique($reviewed)); } // Send notification $post = get_post(intval($post_id)); annowf_send_notification('review_recommendation', $post, null, null, $current_user->ID); annowf_save_audit_item($post_id, $current_user->ID, 4, array($review)); } else { $key = array_search($current_user->ID, $reviewed); if ($key !== false) { unset($reviewed[$key]); update_post_meta($post_id, '_round_' . $post_round . '_reviewed', array_unique($reviewed)); } } echo $review; } die; }