Exemple #1
0
/**
 * 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);
    }
}
								</p>
							</fieldset></td>
						</tr>
						<tr valign="top">
							<th scope="row"><label for="cp-task-due"><?php 
_e('Due: ', 'collabpress');
?>
</label></th>
							<td>
								<p>
									<input name="cp-task-due" class="cp-task-due-date" id="cp-task-due-date" class="regular-text" type="text" value=<?php 
echo cp_get_the_task_due_date();
?>
 />
									<input id="cp-task-due-date-formatted" type="hidden" value="<?php 
echo str_replace(' 00:00:00', '', cp_get_task_due_date_mysql(cp_get_task_id()));
?>
" />
								</p>
							</td>
						</tr>
						<tr valign="top">
							<th scope="row"><label for="cp-task-assign"><?php 
_e('Assigned to: ', 'collabpress');
?>
</label></th>
							<td>
								<p>
			                        <?php 
$user_list = '<select name="cp-task-assign" id="cp-task-assign">';
foreach (cp_get_project_users() as $wp_user) {
function cp_get_task_due_date($task_id)
{
    $due_date_mysql = cp_get_task_due_date_mysql($task_id);
    $unix_timestamp = strtotime($due_date_mysql);
    $cp_options = cp_get_options();
    return date(cp_get_date_format(), $unix_timestamp);
}