ALBA BOARD

Hello {user_name},

You have a new task waiting on your board. Here are the main details:

{card_title}

{card_content}
View Card

Notification automatically generated by Alba Board

HTML; $defaults['new_comment'] = <<

ALBA BOARD

Hello {user_name},

Someone left a new comment on the task {card_title}:

"{comment_text}"
Reply to Comment

Notification automatically generated by Alba Board

HTML; // Get the custom HTML template from settings, or use fallback $html_template = !empty($options['template_' . $template_type]) ? $options['template_' . $template_type] : $defaults[$template_type]; // Replace the placeholders with actual data $search = ['{user_name}', '{card_title}', '{card_content}', '{card_link}', '{comment_text}']; $replace = [ esc_html($user_name), esc_html($card_title), wp_kses_post($card_content), esc_url($card_link), esc_html($comment_text) // Only used if it's a comment notification ]; $final_html_message = str_replace($search, $replace, $html_template); // Filter to allow other add-ons to intercept before sending $process_native_mail = apply_filters('alba_board_pre_send_notification', true, $to_email, $subject, $final_html_message); if ($process_native_mail) { $headers = ['Content-Type: text/html; charset=UTF-8']; wp_mail($to_email, $subject, $final_html_message, $headers); } } /** * 2. TRIGGER 1: New Card Created/Assigned */ function alba_board_notify_on_new_card( $post_id, $post, $update ) { if ( get_post_type( $post_id ) !== 'alba_card' || $update ) return; $options = get_option( 'alba_board_notifications' ); if ( empty( $options['notify_on_card'] ) ) return; // Find who to notify (Assignee first, then Author) $assignee_id = get_post_meta( $post_id, '_alba_assignee', true ); $user_to_notify = $assignee_id ? get_userdata( $assignee_id ) : get_userdata( $post->post_author ); if ( ! $user_to_notify || empty( $user_to_notify->user_email ) || ! is_email( $user_to_notify->user_email ) ) return; // Build the subject $subject = sprintf( __( 'New task assigned: %s', 'alba-board' ), $post->post_title ); $subject = apply_filters( 'alba_board_notification_subject_new_card', $subject, $post_id, $post ); // Call the engine alba_board_send_notification( $user_to_notify->user_email, $subject, $user_to_notify->display_name, $post->post_title, $post->post_content, get_permalink($post_id), 'new_card' ); } add_action( 'wp_insert_post', 'alba_board_notify_on_new_card', 10, 3 ); /** * 3. TRIGGER 2: New Comment Added to a Card */ function alba_board_notify_on_new_comment( $comment_id, $comment_approved, $commentdata ) { // Only proceed if it's an approved comment if ( $comment_approved !== 1 ) return; $post_id = $commentdata['comment_post_ID']; // Ensure the comment belongs to an alba_card if ( get_post_type( $post_id ) !== 'alba_card' ) return; $options = get_option( 'alba_board_notifications' ); if ( empty( $options['notify_on_comment'] ) ) return; $post = get_post( $post_id ); // Find who to notify: In a Kanban, if I comment, the assignee should know. // If the assignee is the one commenting, maybe the card author should know. $assignee_id = get_post_meta( $post_id, '_alba_assignee', true ); $comment_author_id = $commentdata['user_id']; // Logic: Default to notify assignee. If assignee is the commenter, notify post author. $notify_user_id = ($assignee_id && $assignee_id != $comment_author_id) ? $assignee_id : $post->post_author; // Prevent sending email to the person who just wrote the comment if ($notify_user_id == $comment_author_id) return; $user_to_notify = get_userdata( $notify_user_id ); if ( ! $user_to_notify || empty( $user_to_notify->user_email ) || ! is_email( $user_to_notify->user_email ) ) return; // Build the subject $subject = sprintf( __( 'New comment on task: %s', 'alba-board' ), $post->post_title ); $subject = apply_filters( 'alba_board_notification_subject_new_comment', $subject, $post_id, $comment_id ); // Call the engine alba_board_send_notification( $user_to_notify->user_email, $subject, $user_to_notify->display_name, $post->post_title, $post->post_content, get_permalink($post_id) . '#comment-' . $comment_id, // Link directly to comment anchor 'new_comment', $commentdata['comment_content'] // Pass the comment text to the engine ); } add_action( 'comment_post', 'alba_board_notify_on_new_comment', 10, 3 );