| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
global $wpdb,$wppmfunction,$current_user; |
| 6 |
$project_id = intval(sanitize_text_field($project_id)); |
| 7 |
$project_data = $wppmfunction->get_project($project_id); |
| 8 |
$users = explode(',',$project_data['users']); |
| 9 |
$users = array_unique($users); |
| 10 |
if(!empty($users)){ |
| 11 |
foreach($users as $user){ |
| 12 |
if(!empty($user)){ |
| 13 |
$user_role = sanitize_text_field(wp_unslash($_POST['wppm_select_user_role_'.$user])); |
| 14 |
$project_user = $wpdb->get_row( |
| 15 |
$wpdb->prepare( |
| 16 |
"SELECT * FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", |
| 17 |
absint($project_id), |
| 18 |
absint($user) |
| 19 |
) |
| 20 |
); |
| 21 |
if(!empty($project_user)){ |
| 22 |
$project_user_id = absint($project_user->id); |
| 23 |
$values=array( |
| 24 |
'role_id'=> absint($user_role), |
| 25 |
'assigned_by'=>absint($current_user->ID) |
| 26 |
); |
| 27 |
$wpdb->update($wpdb->prefix.'wppm_project_users', $values, array('id'=>$project_user_id)); |
| 28 |
}else{ |
| 29 |
$wpdb->insert( |
| 30 |
$wpdb->prefix . 'wppm_project_users', |
| 31 |
array( |
| 32 |
'proj_id' => absint($project_id), |
| 33 |
'user_id' => absint($user), |
| 34 |
'role_id' => absint($user_role), |
| 35 |
'assigned_by' =>absint($current_user->ID) |
| 36 |
) ); |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
} |