function cp_modify_project_users_handler() { global $wpdb, $cp; // Nonce check check_admin_referer('modify-project-users', 'nonce'); $data = $_REQUEST['data']; extract($data); $wpdb->query($wpdb->prepare("DELETE FROM {$cp->tables->project_users}\n\t\t\tWHERE project_id = %d", $project_id)); foreach ($users as $user_id) { cp_add_user_to_project($project_id, $user_id); } $permalink = cp_get_project_users_permalink($project_id); wp_send_json_success(array('redirect' => $permalink)); }
/** * Update scripts for specific versions * * @since 1.3 */ function cp_update() { global $wpdb; $installed_version = get_option('CP_VERSION'); if ($installed_version != COLLABPRESS_VERSION) { // 1.3 specific upgrades if (version_compare($installed_version, '1.3-dev', '<')) { $tablename = $wpdb->prefix . 'cp_project_users'; // Add project_users table $sql = "CREATE TABLE {$tablename} (\n\t\t\t\tproject_member_id bigint(20) NOT NULL AUTO_INCREMENT,\n\t\t\t\tproject_id bigint(20) NOT NULL,\n\t\t\t\tuser_id bigint(20) NOT NULL,\n\t\t\t\tUNIQUE KEY project_member_id (project_member_id)\n\t\t\t);"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); // Move old user relationships into new user table $projects = get_posts(array('post_type' => 'cp-projects', 'posts_per_page' => -1)); foreach ($projects as $project) { $users = get_post_meta($project->ID, '_cp-project-users', true); foreach ($users as $user_id) { cp_add_user_to_project($project->ID, $user_id); } } } // 1.4 specific upgrades if (version_compare($installed_version, '1.4-dev', '<')) { // Change task due date storage format from m/d/yy to mysql formatted date $tasks = get_posts(array('post_type' => 'cp-tasks', 'posts_per_page' => -1)); foreach ($tasks as $task) { $due_date = cp_get_task_due_date_mysql($task->ID); $unix_timestamp = strtotime($due_date); $formatted_date = gmdate('Y-m-d H:i:s', $unix_timestamp); cp_update_task(array('ID' => $task->ID, 'task_due_date' => $formatted_date)); } // 1.4 introduces the date format option, which we need to add // a default to in the cp_options. $cp_options = cp_get_options(); if (empty($cp_options['date_format'])) { $cp_options['date_format'] = 'F j, Y'; update_option('cp_options', $cp_options); } } update_option('CP_VERSION', COLLABPRESS_VERSION); } }
/** * Create new CollabPress project. * */ function cp_insert_project($args) { $defaults = array('post_title' => 'New Project', 'post_status' => 'publish', 'post_type' => 'cp-projects', 'project_description' => '', 'project_users' => array(1)); $args = wp_parse_args($args, $defaults); extract($args); $project_id = wp_insert_post($args); cp_set_project_description($project_id, $project_description); // Project users update_post_meta($project_id, '_cp-project-users', $project_users); $current_user = wp_get_current_user(); if (!empty($current_user)) { // Add CollabPress Activity entry cp_add_activity(__('added', 'collabpress'), __('project', 'collabpress'), $current_user->ID, $project_id); } $project_users[] = $current_user->ID; $project_users = array_unique($project_users); foreach ($project_users as $user_id) { cp_add_user_to_project($project_id, $user_id); } do_action('cp_project_added', $project_id); return $project_id; }