| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
global $current_user,$wpdb,$wppmfunction; |
| 6 |
if ( check_ajax_referer( 'wppm_change_project_visibility', '_ajax_nonce', false ) != 1 ) { |
| 7 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 8 |
} |
| 9 |
$project_id = isset($_POST['project_id']) ? absint(sanitize_text_field(wp_unslash($_POST['project_id']))) : '' ; |
| 10 |
$project = $wppmfunction->get_project($project_id); |
| 11 |
$wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); |
| 12 |
if (!(($current_user->ID && $current_user->has_cap('manage_options')) || ($current_user->ID && $current_user->has_cap('wppm_admin')) || ($project['created_by']==$current_user->ID && $wppm_current_user_capability == 'wppm_manager'))) {exit;} |
| 13 |
$wppm_project_visibility = isset($_POST['project_visibility']) ? sanitize_text_field(wp_unslash($_POST['project_visibility'])):"0"; |
| 14 |
$wppm_project_visibility = absint($wppm_project_visibility ); |
| 15 |
$id = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}wppm_project_meta WHERE project_id = %d AND meta_key ='public_project'", $project_id)); |
| 16 |
$id = absint($id); |
| 17 |
if(empty($id )){ |
| 18 |
$wppmfunction->add_project_meta($project_id,'public_project',$wppm_project_visibility); |
| 19 |
}elseif(!empty($id)){ |
| 20 |
$values = array( |
| 21 |
'meta_value'=>$wppm_project_visibility |
| 22 |
); |
| 23 |
$wpdb->update($wpdb->prefix.'wppm_project_meta', $values,array('id'=>intval($id))); |
| 24 |
} |