| @@ -1,62 +1,62 @@ | ||
| 1 | -<?php | |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - exit; // Exit if accessed directly | |
| 4 | -} | |
| 5 | -global $wpdb, $wppmfunction, $current_user; | |
| 6 | -if ( check_ajax_referer( 'wppm_create_project', '_ajax_nonce', false ) != 1 ) { | |
| 7 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 8 | -} | |
| 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') { | |
| 11 | - // project name | |
| 12 | - $name = isset($_POST['name']) ? sanitize_text_field(wp_unslash($_POST['name'])) : ''; | |
| 13 | - if($name) $args['name'] = $name; | |
| 14 | - | |
| 15 | - // Description | |
| 16 | - $project_description = ''; | |
| 17 | - | |
| 18 | - if ( !empty( $_POST['wppm_proj_description'] ) ) { | |
| 19 | - $project_description = wp_kses_post( | |
| 20 | - wp_unslash( $_POST['wppm_proj_description'] ) | |
| 21 | - ); | |
| 22 | - } | |
| 23 | - if($project_description) $args['wppm_proj_description'] = $project_description; | |
| 24 | - | |
| 25 | - //Project start date | |
| 26 | - $text = isset($_POST['wppm_start_date']) ? sanitize_text_field(wp_unslash($_POST['wppm_start_date'])) : ''; | |
| 27 | - if($text) $args['wppm_start_date'] = wp_date("Y-m-d H:i:s" ,strtotime($text)); | |
| 28 | - | |
| 29 | - //Project end date | |
| 30 | - $text2 = isset($_POST['wppm_end_date']) ? sanitize_text_field(wp_unslash($_POST['wppm_end_date'])) : ''; | |
| 31 | - if($text2) $args['wppm_end_date'] = wp_date("Y-m-d H:i:s" ,strtotime($text2)); | |
| 32 | - | |
| 33 | - // Category | |
| 34 | - $project_category = isset($_POST['wppm_create_project_category']) ? intval(sanitize_text_field(wp_unslash($_POST['wppm_create_project_category']))) : ''; | |
| 35 | - if($project_category) $args['wppm_create_project_category'] = $project_category; | |
| 36 | - | |
| 37 | - //Assign user | |
| 38 | - $users = array(); | |
| 39 | - if ( isset( $_POST['user_names'] ) && is_array( $_POST['user_names'] ) ) { | |
| 40 | - $users = array_map( | |
| 41 | - 'absint', | |
| 42 | - wp_unslash( $_POST['user_names'] ) | |
| 43 | - ); | |
| 44 | - $users = array_unique( $users ); | |
| 45 | - } | |
| 46 | - if($users) $args['user_names'] = $wppmfunction->sanitize_array($users); | |
| 47 | - | |
| 48 | - //public project | |
| 49 | - $public_proj = isset($_POST['wppm_public_project']) ? 1 : 0; | |
| 50 | - | |
| 51 | - $args = apply_filters( 'wppm_before_create_project_args', $args); | |
| 52 | - | |
| 53 | - $project_id = WPPM_Functions::create_project($args); | |
| 54 | - if ( empty( $project_id ) ) { | |
| 55 | - wp_send_json_error( 'Permission denied', 403 ); | |
| 56 | - } | |
| 57 | - $auth_code = $wppmfunction->getRandomString(10); | |
| 58 | - $wppmfunction->add_project_meta($project_id,'public_project',$public_proj); | |
| 59 | - $wppmfunction->add_project_meta($project_id,'project_auth_code',$auth_code); | |
| 60 | -} | |
| 61 | - | |
| 62 | -do_action('wppm_after_project_created',$project_id); | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; // Exit if accessed directly | |
| 4 | +} | |
| 5 | +global $wpdb, $wppmfunction, $current_user; | |
| 6 | +if ( check_ajax_referer( 'wppm_create_project', '_ajax_nonce', false ) != 1 ) { | |
| 7 | + wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 8 | +} | |
| 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') { | |
| 11 | + // project name | |
| 12 | + $name = isset($_POST['name']) ? sanitize_text_field(wp_unslash($_POST['name'])) : ''; | |
| 13 | + if($name) $args['name'] = $name; | |
| 14 | + | |
| 15 | + // Description | |
| 16 | + $project_description = ''; | |
| 17 | + | |
| 18 | + if ( !empty( $_POST['wppm_proj_description'] ) ) { | |
| 19 | + $project_description = wp_kses_post( | |
| 20 | + wp_unslash( $_POST['wppm_proj_description'] ) | |
| 21 | + ); | |
| 22 | + } | |
| 23 | + if($project_description) $args['wppm_proj_description'] = $project_description; | |
| 24 | + | |
| 25 | + //Project start date | |
| 26 | + $text = isset($_POST['wppm_start_date']) ? sanitize_text_field(wp_unslash($_POST['wppm_start_date'])) : ''; | |
| 27 | + if($text) $args['wppm_start_date'] = wp_date("Y-m-d H:i:s" ,strtotime($text)); | |
| 28 | + | |
| 29 | + //Project end date | |
| 30 | + $text2 = isset($_POST['wppm_end_date']) ? sanitize_text_field(wp_unslash($_POST['wppm_end_date'])) : ''; | |
| 31 | + if($text2) $args['wppm_end_date'] = wp_date("Y-m-d H:i:s" ,strtotime($text2)); | |
| 32 | + | |
| 33 | + // Category | |
| 34 | + $project_category = isset($_POST['wppm_create_project_category']) ? intval(sanitize_text_field(wp_unslash($_POST['wppm_create_project_category']))) : ''; | |
| 35 | + if($project_category) $args['wppm_create_project_category'] = $project_category; | |
| 36 | + | |
| 37 | + //Assign user | |
| 38 | + $users = array(); | |
| 39 | + if ( isset( $_POST['user_names'] ) && is_array( $_POST['user_names'] ) ) { | |
| 40 | + $users = array_map( | |
| 41 | + 'absint', | |
| 42 | + wp_unslash( $_POST['user_names'] ) | |
| 43 | + ); | |
| 44 | + $users = array_unique( $users ); | |
| 45 | + } | |
| 46 | + if($users) $args['user_names'] = $wppmfunction->sanitize_array($users); | |
| 47 | + | |
| 48 | + //public project | |
| 49 | + $public_proj = isset($_POST['wppm_public_project']) ? 1 : 0; | |
| 50 | + | |
| 51 | + $args = apply_filters( 'wppm_before_create_project_args', $args); | |
| 52 | + | |
| 53 | + $project_id = WPPM_Functions::create_project($args); | |
| 54 | + if ( empty( $project_id ) ) { | |
| 55 | + wp_send_json_error( 'Permission denied', 403 ); | |
| 56 | + } | |
| 57 | + $auth_code = $wppmfunction->getRandomString(10); | |
| 58 | + $wppmfunction->add_project_meta($project_id,'public_project',$public_proj); | |
| 59 | + $wppmfunction->add_project_meta($project_id,'project_auth_code',$auth_code); | |
| 60 | +} | |
| 61 | + | |
| 62 | +do_action('wppm_after_project_created',$project_id); | |