has_permission('add_task_comment',$task_id)){ exit; }
$task_url = '' . $wppmfunction->get_task_url($task_id,$view) . '';
$comment = isset( $_POST['comment_body'] ) ? ( wp_unslash( $_POST['comment_body'] ) ) : '';
$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('class' => array(),'data-user-id' => array(),'data-username' => array(),'contenteditable' => 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(),));
$comment_body = !empty($comment) ? wp_kses_post($comment) : '';
$attachments = !empty($_POST['wppm_comment_attachment']) ? $wppmfunction->sanitize_array($_POST['wppm_comment_attachment']) : [];
$attachment_ids = implode(",",$attachments);
if($comment_body=="" && $attachment_ids=="") exit;
$mentions = $wppmfunction->wppm_extract_mentions($comment_body);
// Remove mention list div completely
$comment_body = preg_replace('/
/is', '', $comment_body);
// Allow only safe HTML
$comment_body = wp_kses_post($comment_body);
$user_ids = $mentions; // Since we are now extracting user IDs directly, we can use them as is
$user_ids = array_unique($user_ids);
foreach ($user_ids as $uid => $user) {
$uid = is_object($user) ? $user->ID : (int) $user;
// Skip self notification
if ($uid == $current_user->ID) {
continue;
}
$task_url = esc_url($wppmfunction->get_task_url($task_id, $view));
$message = sprintf(
'%s
%s',
esc_html__("You were mentioned in a comment.", "taskbuilder"),
$task_url,
esc_html__("View Task", "taskbuilder")
);
$wppmfunction->wppm_insert_notification(
$uid,
$message,
$task_url,
'0',
'mention_task_comment'
);
$userdata = get_userdata($uid);
if ($userdata) {
$email_addresses[] = $userdata->user_email;
}
}
$vals = array('is_active' => 1);
foreach($attachments as $attach){
$wpdb->update($wpdb->prefix.'wppm_attachments', $vals, array('id'=>$attach));
}
$args=array(
'task_id'=> $task_id,
'body'=>$comment_body,
'attachment_ids'=>$attachment_ids,
'create_time'=>wp_date("Y-m-d h:i:sa"),
'created_by'=>$current_user->ID
);
$args = apply_filters( 'wppm_submit_comment_args', $args );
$comment_id = $wppmfunction->wppm_submit_task_comment($args);
$wppmfunction->wppm_send_mention_email($email_addresses, $comment_body, $task_id);
$task_log_values = array('task_id'=>esc_sql($task_id),'comment_id'=>esc_sql($comment_id),'comment_type'=>'comment');
$wpdb->insert($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values);
do_action('wppm_after_submit_task_comment', $task_id,$comment_id);