/**
 * Create a new commment on a task.
 *
 * @uses wp_insert_comment
 */
function cp_insert_comment_on_task($args = array())
{
    global $cp_task, $cp;
    global $current_user;
    get_currentuserinfo();
    $time = current_time('mysql');
    $defaults = array('comment_author' => $current_user->display_name, 'comment_author_email' => $current_user->user_email, 'comment_author_url' => $current_user->user_email, 'comment_type' => 'collabpress', 'comment_parent' => 0, 'user_id' => $current_user->ID, 'comment_author_IP' => preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']), 'comment_agent' => substr($_SERVER['HTTP_USER_AGENT'], 0, 254), 'comment_date' => $time, 'comment_approved' => 1, 'send_email_notification' => true);
    // $cp may not be defined, check here
    if (isset($cp->task->ID)) {
        $defaults['comment_post_ID'] = $cp->task->ID;
    }
    if (isset($_POST['cp-comment-content'])) {
        $defaults['comment_content'] = wp_kses_post($_POST['cp-comment-content']);
    }
    $args = wp_parse_args($args, $defaults);
    wp_insert_comment($args);
    //check if email notification is checked
    if ($args['send_email_notification']) {
        $task_author_id = get_post_meta($args['comment_post_ID'], '_cp-task-assign', true);
        $task_author_data = get_userdata($task_author_id);
        // Add user assigned to the task to the email list.
        $to[] = $task_author_data->user_email;
        // Add all users that have commented on the task to the email list.
        $comments = get_comments(array('post_id' => $args['comment_post_ID'], 'order' => 'ASC'));
        foreach ($comments as $comment) {
            $to[] = $comment->comment_author_email;
        }
        // Remove duplicates from the email list.
        array_unique($to);
        $subject = __('New comment on task ', 'collabpress') . get_the_title($args['comment_post_ID']);
        $subject = apply_filters('cp_new_comment_email_subject', $subject);
        $message = sprintf(__("There is a new comment on the task %s from %s", "collabpress"), get_the_title($args['comment_post_ID']), $current_user->display_name);
        $message .= "\n\n";
        $message .= __("Comment:", "collabpress") . "\n";
        $message .= esc_html($args['comment_content']);
        $message = apply_filters('cp_new_comment_email_body', $message);
        cp_send_email($to, $subject, $message);
    }
    // Add Activity
    cp_add_activity(__('commented', 'collabpress'), __('task', 'collabpress'), $args['user_id'], $args['comment_post_ID']);
}
Beispiel #2
0
    if (isset($_POST['cp-task-priority'])) {
        update_post_meta($task_id, '_cp-task-priority', strip_tags($_POST['cp-task-priority']));
    }
    // Add Activity
    cp_add_activity(__('added', 'collabpress'), __('task', 'collabpress'), $current_user->ID, $task_id);
    do_action('cp_task_added', $task_id);
    //check if email notification is checked
    if (isset($_POST['notify'])) {
        //send email
        $task_author_data = get_userdata(absint($_POST['cp-task-assign']));
        $author_email = $task_author_data->user_email;
        $subject = apply_filters('cp_new_task_email_subject', __('New task assigned to you: ', 'collabpress') . get_the_title($task_id));
        $message = __('There is a new task assigned to you:', 'collabpress') . "\n\n";
        $message .= esc_html($_POST['cp-task']);
        $message = apply_filters('cp_new_task_email_body', $message);
        cp_send_email($author_email, $subject, $message);
    }
}
// Edit Task
if (isset($_POST['cp-edit-task']) && isset($_POST['cp-edit-task-id'])) {
    //check nonce for security
    check_admin_referer('cp-edit-task' . absint($_POST['cp-edit-task-id']));
    //verify user has permission to edit tasks and post ID is a task CPT
    if (cp_check_permissions('settings_user_role') && 'cp-tasks' === get_post_type(absint($_POST['cp-edit-task-id']))) {
        // The ID
        $taskID = absint($_POST['cp-edit-task-id']);
        $task = array();
        $task['ID'] = $taskID;
        $task['post_title'] = sanitize_text_field($_POST['cp-task']);
        wp_update_post($task);
        update_post_meta($taskID, '_cp-task-due', sanitize_text_field($_POST['cp-task-due']));