| 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_submit_proj_comment', '_ajax_nonce', false ) != 1 ) { |
| 7 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 8 |
} |
| 9 |
$proj_id = isset($_POST['proj_id']) ? sanitize_text_field($_POST['proj_id']) : '' ; |
| 10 |
$comment = isset($_POST['comment_body']) ? ($_POST['comment_body']) : '' ; |
| 11 |
$allowed_tags = array( 'br' => array(), 'abbr' => array('title' => array(),), 'p' => array(), 'strong' => array(), 'a' => array('href' => array(), 'title' => array(), 'rel'=> array(), 'target'=> 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(),)); |
| 12 |
$comment_body = wp_kses(htmlspecialchars_decode($comment, ENT_QUOTES),$allowed_tags); |
| 13 |
if($comment_body=="") exit; |
| 14 |
$attachments = !empty($_POST['wppm_proj_comment_attachment']) ? $wppmfunction->sanitize_array($_POST['wppm_proj_comment_attachment']) : []; |
| 15 |
$attachment_ids = implode(",",$attachments); |
| 16 |
if(!empty($attachments)){ |
| 17 |
$project_auth_code = $wppmfunction->get_project_meta($proj_id,'project_auth_code',true); |
| 18 |
if(empty($project_auth_code)){ |
| 19 |
$auth_code = $wppmfunction->getRandomString(10); |
| 20 |
$wppmfunction->add_project_meta($proj_id,'project_auth_code',$auth_code); |
| 21 |
} |
| 22 |
} |
| 23 |
$vals = array('is_active' => 1); |
| 24 |
foreach($attachments as $attach){ |
| 25 |
$wpdb->update($wpdb->prefix.'wppm_attachments', $vals, array('id'=>$attach)); |
| 26 |
} |
| 27 |
$args=array( |
| 28 |
'proj_id'=> $proj_id, |
| 29 |
'body'=>$comment_body, |
| 30 |
'attachment_ids'=>$attachment_ids, |
| 31 |
'create_time'=>current_time('mysql', 1), |
| 32 |
'created_by'=>$current_user->ID |
| 33 |
); |
| 34 |
$args = apply_filters( 'wppm_submit_proj_comment_args', $args ); |
| 35 |
$comment_id = $wppmfunction->wppm_submit_proj_comment($args); |
| 36 |
|
| 37 |
do_action('wppm_after_submit_proj_comment', $proj_id,$comment_id); |
| 38 |
|
| 39 |
|