/** * 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; }
function cp_edit_project_handler() { // Nonce check check_admin_referer('edit-project', 'nonce'); $data = $_REQUEST['data']; extract($data); wp_update_post($data); cp_set_project_description($ID, $project_description); $permalink = cp_get_project_permalink($ID); wp_send_json_success(array('redirect' => $permalink)); }