Example #1
0
/**
 * 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']);
}
Example #2
0
    $taskID = isset($_GET['cp-complete-task-id']) ? absint($_GET['cp-complete-task-id']) : null;
    //get current task status
    $task_status = get_post_meta($taskID, '_cp-task-status', true);
    if ($taskID && $task_status != 'complete') {
        //set the task to complete
        update_post_meta($taskID, '_cp-task-status', 'complete');
        // Add Activity
        cp_add_activity(__('completed', 'collabpress'), __('task', 'collabpress'), $current_user->ID, $taskID);
        do_action('cp_task_completed', $taskID);
    } elseif ($taskID) {
        //open the task
        update_post_meta($taskID, '_cp-task-status', 'open');
        // Add Activity
        cp_add_activity(__('opened', 'collabpress'), __('task', 'collabpress'), $current_user->ID, $taskID);
        do_action('cp_task_reopened', $taskID);
    }
}
// Delete Task
if (isset($_GET['cp-delete-task-id'])) {
    //check nonce for security
    check_admin_referer('cp-action-delete_task' . absint($_GET['cp-delete-task-id']));
    //verify user has permission to delete tasks and post ID is a task CPT
    if (cp_check_permissions('settings_user_role') && 'cp-tasks' === get_post_type(absint($_GET['cp-delete-task-id']))) {
        $cp_task_id = absint($_GET['cp-delete-task-id']);
        //delete the task
        wp_trash_post($cp_task_id, true);
        //add activity log
        cp_add_activity(__('deleted', 'collabpress'), __('task', 'collabpress'), $current_user->ID, $cp_task_id);
        do_action('cp_task_deleted', $cp_task_id);
    }
}
Example #3
0
        //send email
        //get user assigned to the task
        $task_author_id = get_post_meta($cp->task->ID, '_cp-task-assign', true);
        $task_author_data = get_userdata($task_author_id);
        $author_email = $task_author_data->user_email;
        $subject = __('New comment on task ', 'collabpress') . get_the_title($cp->task->ID);
        $message = __("There is a new comment on your task from ", "collabpress") . $current_user->display_name . ": " . get_the_title($cp->task->ID) . "\n\n";
        $subject = __('New comment on task ', 'collabpress') . get_the_title($cp_task->id);
        $subject = apply_filters('cp_new_comment_email_subject', $subject);
        $message = __("There is a new comment on your task from ", "collabpress") . $current_user->display_name . ": " . get_the_title($cp_task->id) . "\n\n";
        $message .= __("Comment:", "collabpress") . "\n";
        $message .= esc_html($_POST['cp-comment-content']);
        $message = apply_filters('cp_new_comment_email_body', $message);
        cp_send_email($author_email, $subject, $message);
    }
    // Add Activity
    cp_add_activity(__('added', 'collabpress'), __('comment', 'collabpress'), $current_user->ID, $cp->task->ID);
}
// Delete Project
if (isset($_GET['cp-delete-comment-id'])) {
    global $current_user, $cp;
    get_currentuserinfo();
    check_admin_referer('cp-action-delete_comment');
    //verify user has permission to delete comments
    if (cp_check_permissions('settings_user_role')) {
        $cp_comment_id = absint($_GET['cp-delete-comment-id']);
        wp_delete_comment($cp_comment_id);
        //add activity log
        cp_add_activity(__('deleted', 'collabpress'), __('comment', 'collabpress'), $current_user->ID, $cp->task->id);
    }
}
}
// Edit Task List
if (isset($_POST['cp-edit-task-list']) && $_POST['cp-edit-task-list-id']) {
    //check nonce for security
    check_admin_referer('cp-edit-task-list' . absint($_POST['cp-edit-task-list-id']));
    //verify user has permission to edit task lists and post ID is a task list CPT
    if (cp_check_permissions('settings_user_role') && 'cp-task-lists' === get_post_type(absint($_POST['cp-edit-task-list-id']))) {
        // The ID
        $tasklistID = absint($_POST['cp-edit-task-list-id']);
        $tasklist = array();
        $tasklist['ID'] = $tasklistID;
        $tasklist['post_title'] = sanitize_text_field($_POST['cp-task-list']);
        wp_update_post($tasklist);
        update_post_meta($tasklistID, '_cp-task-list-description', esc_html($_POST['cp-task-list-description']));
        // Add Activity
        cp_add_activity(__('updated', 'collabpress'), __('task list', 'collabpress'), $current_user->ID, $tasklistID);
        do_action('cp_task_list_edited', $tasklistID);
    }
}
// Delete Task List
if (isset($_GET['cp-delete-task-list-id'])) {
    //check nonce for security
    check_admin_referer('cp-action-delete_task_list' . absint($_GET['cp-delete-task-list-id']));
    //verify user has permission to delete task lists and post ID is a task list CPT
    if (cp_check_permissions('settings_user_role') && 'cp-task-lists' === get_post_type(absint($_GET['cp-delete-task-list-id']))) {
        $cp_task_list_id = absint($_GET['cp-delete-task-list-id']);
        //delete the task list
        wp_delete_post($cp_task_list_id, true);
        //delete all tasks in the task list
        $tasks_args = array('post_type' => 'cp-tasks', 'meta_key' => '_cp-task-list-id', 'meta_value' => $cp_task_list_id, 'showposts' => '-1');
        $tasks_query = new WP_Query($tasks_args);
Example #5
0
    if (cp_check_permissions('settings_user_role') && 'cp-projects' === get_post_type(absint($_GET['cp-delete-project-id']))) {
        $cp_project_id = absint($_GET['cp-delete-project-id']);
        //delete the project
        wp_delete_post($cp_project_id, true);
        //delete all task lists assigned to this project
        $tasks_args = array('post_type' => 'cp-task-lists', 'meta_key' => '_cp-project-id', 'meta_value' => $cp_project_id, 'showposts' => '-1');
        $tasks_query = new WP_Query($tasks_args);
        // WP_Query();
        if ($tasks_query->have_posts()) {
            while ($tasks_query->have_posts()) {
                $tasks_query->the_post();
                //delete the task
                wp_delete_post(get_the_ID(), true);
            }
        }
        //delete all tasks assigned to this project
        $tasks_args = array('post_type' => 'cp-tasks', 'meta_key' => '_cp-project-id', 'meta_value' => $cp_project_id, 'showposts' => '-1');
        $tasks_query = new WP_Query($tasks_args);
        // WP_Query();
        if ($tasks_query->have_posts()) {
            while ($tasks_query->have_posts()) {
                $tasks_query->the_post();
                //delete the task
                wp_delete_post(get_the_ID(), true);
            }
        }
        //add activity log
        cp_add_activity(__('deleted', 'collabpress'), __('project', 'collabpress'), $current_user->ID, $cp_project_id);
        do_action('cp_project_deleted', $cp_project_id);
    }
}