| @@ -6,33 +6,47 @@ | ||
| 6 | 6 | if ( check_ajax_referer( 'wppm_create_project', '_ajax_nonce', false ) != 1 ) { |
| 7 | 7 | wp_send_json_error( 'Unauthorised request!', 401 ); |
| 8 | 8 | } |
| 9 | 9 | $wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); |
| 10 | -if (($current_user->has_cap('manage_options')) || $wppm_current_user_capability == 'wppm_manager'|| $wppm_current_user_capability == 'wppm_admin') { | |
| 10 | +$wppm_can_create_project = ($current_user->has_cap('manage_options')) || $wppm_current_user_capability == 'wppm_manager'|| $wppm_current_user_capability == 'wppm_admin'; | |
| 11 | +$wppm_can_create_project = apply_filters( 'wppm_can_create_project', $wppm_can_create_project, $current_user->ID ); | |
| 12 | +if ($wppm_can_create_project) { | |
| 11 | 13 | // project name |
| 12 | - $name = isset($_POST['name']) ? sanitize_text_field($_POST['name']) : ''; | |
| 14 | + $name = isset($_POST['name']) ? sanitize_text_field(wp_unslash($_POST['name'])) : ''; | |
| 13 | 15 | if($name) $args['name'] = $name; |
| 14 | 16 | |
| 15 | 17 | // Description |
| 16 | - $allowedtags = array( 'br' => array(), 'abbr' => array('title' => array(),), 'p' => array(), 'strong' => array(), 'a' => array('href' => array(), 'title' => array(),'target'=> array(), 'rel'=>array()),'em' =>array(),'span' =>array(), 'blockquote'=>array('cite' => array(),),'div' => array('class' => array(),'title' => array(),'style' => array(),),'ul'=>array(),'li'=>array(),'ol'=>array(),'img' => array( 'alt'=> array(),'class' => array(),'height' => array(),'src'=> array(),'width'=> array(),)); | |
| 17 | - $project_description = isset($_POST['wppm_proj_description']) ? wp_kses(htmlspecialchars_decode($_POST['wppm_proj_description'], ENT_QUOTES),$allowedtags) : ''; | |
| 18 | + $project_description = ''; | |
| 19 | + | |
| 20 | + if ( !empty( $_POST['wppm_proj_description'] ) ) { | |
| 21 | + $project_description = wp_kses_post( | |
| 22 | + wp_unslash( $_POST['wppm_proj_description'] ) | |
| 23 | + ); | |
| 24 | + } | |
| 18 | 25 | if($project_description) $args['wppm_proj_description'] = $project_description; |
| 19 | 26 | |
| 20 | 27 | //Project start date |
| 21 | - $text = isset($_POST['wppm_start_date']) ? sanitize_text_field($_POST['wppm_start_date']) : ''; | |
| 22 | - if($text) $args['wppm_start_date'] = date("Y-m-d H:i:s" ,strtotime($text)); | |
| 28 | + $text = isset($_POST['wppm_start_date']) ? sanitize_text_field(wp_unslash($_POST['wppm_start_date'])) : ''; | |
| 29 | + if($text) $args['wppm_start_date'] = wp_date("Y-m-d H:i:s" ,strtotime($text)); | |
| 23 | 30 | |
| 24 | 31 | //Project end date |
| 25 | - $text2 = isset($_POST['wppm_end_date']) ? sanitize_text_field($_POST['wppm_end_date']) : ''; | |
| 26 | - if($text2) $args['wppm_end_date'] = date("Y-m-d H:i:s" ,strtotime($text2)); | |
| 32 | + $text2 = isset($_POST['wppm_end_date']) ? sanitize_text_field(wp_unslash($_POST['wppm_end_date'])) : ''; | |
| 33 | + if($text2) $args['wppm_end_date'] = wp_date("Y-m-d H:i:s" ,strtotime($text2)); | |
| 27 | 34 | |
| 28 | 35 | // Category |
| 29 | - $project_category = isset($_POST['wppm_create_project_category']) ? intval(sanitize_text_field($_POST['wppm_create_project_category'])) : ''; | |
| 36 | + $project_category = isset($_POST['wppm_create_project_category']) ? intval(sanitize_text_field(wp_unslash($_POST['wppm_create_project_category']))) : ''; | |
| 30 | 37 | if($project_category) $args['wppm_create_project_category'] = $project_category; |
| 31 | 38 | |
| 32 | 39 | //Assign user |
| 33 | - $arrVal = isset($_POST['user_names']) ? array_unique($_POST['user_names']) : array(); | |
| 34 | - if($arrVal) $args['user_names'] = $wppmfunction->sanitize_array($arrVal); | |
| 40 | + $users = array(); | |
| 41 | + if ( isset( $_POST['user_names'] ) && is_array( $_POST['user_names'] ) ) { | |
| 42 | + $users = array_map( | |
| 43 | + 'absint', | |
| 44 | + wp_unslash( $_POST['user_names'] ) | |
| 45 | + ); | |
| 46 | + $users = array_unique( $users ); | |
| 47 | + } | |
| 48 | + if($users) $args['user_names'] = $wppmfunction->sanitize_array($users); | |
| 35 | 49 | |
| 36 | 50 | //public project |
| 37 | 51 | $public_proj = isset($_POST['wppm_public_project']) ? 1 : 0; |
| 38 | 52 | |
| @@ -38,10 +52,15 @@ | ||
| 38 | 52 | |
| 39 | 53 | $args = apply_filters( 'wppm_before_create_project_args', $args); |
| 40 | 54 | |
| 41 | 55 | $project_id = WPPM_Functions::create_project($args); |
| 56 | + if ( empty( $project_id ) ) { | |
| 57 | + wp_send_json_error( 'Permission denied', 403 ); | |
| 58 | + } | |
| 42 | 59 | $auth_code = $wppmfunction->getRandomString(10); |
| 43 | 60 | $wppmfunction->add_project_meta($project_id,'public_project',$public_proj); |
| 44 | 61 | $wppmfunction->add_project_meta($project_id,'project_auth_code',$auth_code); |
| 62 | +} else { | |
| 63 | + wp_send_json_error( 'Permission denied', 403 ); | |
| 45 | 64 | } |
| 46 | 65 | |
| 47 | -do_action('wppm_after_project_created',$project_id); | |
| 66 | +do_action('wppm_after_project_created',$project_id); | |