Example #1
0
/**
 * Handles AJAX request for remove a co-author to a post.
 */
function annowf_remove_co_author()
{
    $response = annowf_remove_user('co_author');
    if ($response['message'] == 'success') {
        if (isset($_POST['user_id'])) {
            //Add to the audit log
            $current_user = wp_get_current_user();
            annowf_save_audit_item(absint($_POST['post_id']), $current_user->ID, 7, array(absint($_POST['user_id'])));
        }
    }
    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;
}