Exemplo n.º 1
0
/**
 * Create new CollabPress task.
 *
 */
function cp_insert_task($args = array())
{
    $defaults = array('post_title' => 'New Task', 'post_status' => 'publish', 'post_type' => 'cp-tasks', 'project_id' => NULL, 'task_due_date' => NULL, 'task_assigned_to' => NULL, 'task_priority' => 'None', 'task_list' => 0, 'send_email_notification' => true);
    $args = wp_parse_args($args, $defaults);
    extract($args);
    $task_id = wp_insert_post($args);
    // Where we get the project_id from depends on whether this is a BP installation
    if (!$project_id) {
        if (is_object($cp_bp_integration) && method_exists($cp_bp_integration, 'get_current_item_project')) {
            $project_id = $cp_bp_integration->get_current_item_project();
        }
    }
    if ($project_id) {
        update_post_meta($task_id, '_cp-project-id', $project_id);
    }
    //add task status
    update_post_meta($task_id, '_cp-task-status', 'open');
    if ($task_due_date) {
        // Validate Date
        if (cp_validate_date($task_due_date)) {
            $taskDate = esc_html($task_due_date);
        }
        update_post_meta($task_id, '_cp-task-due', $taskDate);
    }
    // update task list
    update_post_meta($task_id, '_cp-task-list-id', $task_list);
    //save the user assignment
    if ($task_assigned_to) {
        update_post_meta($task_id, '_cp-task-assign', $task_assigned_to);
    }
    //save the task priority
    if ($task_priority) {
        update_post_meta($task_id, '_cp-task-priority', $task_priority);
    }
    // Add CollabPress Activity entry
    $current_user = wp_get_current_user();
    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, and a user is assigned to a project
    if ($send_email_notification && $task_assigned_to) {
        // send email
        $task_author_data = get_userdata($task_assigned_to);
        $author_email = $task_author_data->user_email;
        $subject = sprintf(__('You have been assigned the task %s.', 'collabpress'), esc_attr(get_the_title($task_id)));
        $message = sprintf(__('You have been assigned the task %s.', 'collabpress'), esc_attr(get_the_title($task_id)));
        cp_send_email($author_email, $subject, $message);
    }
}
Exemplo n.º 2
0
 // Where we get the task list from depends on whether this is a BP installation
 if (isset($_GET['task-list'])) {
     $task_list_id = $cp_task_list->id;
 } else {
     if (is_object($cp_bp_integration) && method_exists($cp_bp_integration, 'get_current_item_task_list')) {
         $task_list_id = $cp_bp_integration->get_current_item_task_list();
     } else {
         $task_list_id = NULL;
     }
 }
 if ($task_list_id) {
     update_post_meta($task_id, '_cp-task-list-id', $task_list_id);
 }
 if (isset($_POST['cp-task-due'])) {
     // Validate Date
     if (cp_validate_date($_POST['cp-task-due'])) {
         $taskDate = esc_html($_POST['cp-task-due']);
     } else {
         $taskDate = date('n/j/Y');
     }
     update_post_meta($task_id, '_cp-task-due', $taskDate);
 }
 //save the user assignment
 if (isset($_POST['cp-task-assign'])) {
     update_post_meta($task_id, '_cp-task-assign', absint($_POST['cp-task-assign']));
 }
 //save the task priority
 if (isset($_POST['cp-task-priority'])) {
     update_post_meta($task_id, '_cp-task-priority', strip_tags($_POST['cp-task-priority']));
 }
 // Add Activity