from projectmanager.php, the actions which call the register user function (the first is the app's original one, the second is the one added by me which works 100% of the time but requires the user to update their profile):
/**
* add new dataset
*
* @param int $project_id
* @param string $name
* @param array $cat_ids
* @param array $dataset_meta
* @param false|int $user_id
* @return string
*/
function addDataset( $project_id, $name, $cat_ids, $dataset_meta = false, $user_id = false )
{
global $wpdb, $current_user, $projectmanager;
if ( $user_id && $this->datasetExists($project_id, $user_id) ) {
$this->setMessage( __( 'You cannot add two datasets with same User ID.', 'projectmanager' ), true );
return false;
}
$projectmanager->initialize($project_id);
$this->project_id = $project_id;
$project = $this->project = $projectmanager->getProject($project_id);
if ( !$user_id ) $user_id = $current_user->ID;
// Negative check on capability: user can't edit datasets
if ( !current_user_can('edit_datasets') && !current_user_can('projectmanager_user') && !current_user_can('import_datasets') ) {
$this->setMessage( __("You don't have permission to perform this task", 'projectmanager'), true );
return;
}
// user has only cap 'projectmanager_user' but not 'edit_other_datasets' and 'edit_datasets'
if ( current_user_can('projectmanager_user') && !current_user_can('edit_other_datasets') && !current_user_can('edit_datasets') && !current_user_can('import_datasets') ) {
// and dataset with this user ID already exists
if ( $this->datasetExists($project_id, $user_id) ) {
$this->setMessage( __("You don't have permission to perform this task", 'projectmanager'), true );
return;
}
}
$wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->projectmanager_dataset} (name, cat_ids, project_id, user_id) VALUES ('%s', '%s', '%d', '%d')", $name, maybe_serialize($cat_ids), $project_id, $user_id ) );
$dataset_id = $wpdb->insert_id;
if ( $dataset_meta ) {
foreach ( $dataset_meta AS $meta_id => $meta_value ) {
$formfield = parent::getFormFields($meta_id);
// Manage file upload
if ( 'file' == $formfield->type || 'image' == $formfield->type || 'video' == $formfield->type ) {
$file = array('name' => $_FILES['form_field']['name'][$meta_id], 'tmp_name' => $_FILES['form_field']['tmp_name'][$meta_id], 'size' => $_FILES['form_field']['size'][$meta_id], 'type' => $_FILES['form_field']['type'][$meta_id]);
if ( !empty($file['name']) )
$this->uploadFile($file);
$meta_value = basename($file['name']);
// Create Thumbails for Image
if ( 'image' == $formfield->type && !empty($meta_value) ) {
$new_file = parent::getFilePath().'/'.$meta_value;
$image = new ProjectManagerImage($new_file);
// Resize original file and create thumbnails
$dims = array( 'width' => $project->medium_size['width'], 'height' => $project->medium_size['height'] );
$image->createThumbnail( $dims, $new_file, $project->chmod );
$dims = array( 'width' => $project->thumb_size['width'], 'height' => $project->thumb_size['height'] );
$image->createThumbnail( $dims, parent::getFilePath().'/thumb.'.$meta_value, $project->chmod );
$dims = array( 'width' => 80, 'height' => 50 );
$image->createThumbnail( $dims, parent::getFilePath().'/tiny.'.$meta_value, $project->chmod );
}
} elseif ( 'numeric' == $formfield->type || 'currency' == $formfiel->type ) {
$meta_value += 0; // convert value to numeric type
}
if ( is_array($meta_value) ) {
// form field value is a date
if ( array_key_exists('day', $meta_value) && array_key_exists('month', $meta_value) && array_key_exists('year', $meta_value) ) {
$meta_value = sprintf("%s-%s-%s", $meta_value['year'], $meta_value['month'], $meta_value['day']);
} elseif ( array_key_exists('hour', $meta_value) && array_key_exists('minute', $meta_value) ) {
$meta_value = sprintf("%s:%s", $meta_value['hour'], $meta_value['minute']);
}
}
$wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->projectmanager_datasetmeta} (form_id, dataset_id, value) VALUES ('%d', '%d', '%s')", $meta_id, $dataset_id, maybe_serialize($meta_value) ) );
}
// Check for unsubmitted form data, e.g. checkbox list
if ($form_fields = parent::getFormFields()) {
foreach ( $form_fields AS $form_field ) {
if ( !array_key_exists($form_field->id, $dataset_meta) ) {
$wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->projectmanager_datasetmeta} (form_id, dataset_id, value) VALUES ('%d', '%d', '')", $dataset_id, $form_field->id ) );
}
}
}
} else {
// Populate empty meta value for new registered user
foreach ( $projectmanager->getFormFields() AS $formfield ) {
$wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->projectmanager_datasetmeta} (form_id, dataset_id, value) VALUES ('%d', '%d', '')", $formfield->id, $dataset_id ) );
}
}
if ( isset($_FILES['projectmanager_image']) && $_FILES['projectmanager_image']['name'] != '' )
$this->uploadImage($dataset_id, $_FILES['projectmanager_image']);
$this->setMessage( __( 'New dataset added to the database.', 'projectmanager' ) );
do_action('projectmanager_add_dataset', $dataset_id);
}