댓글의 댓글이 달렸을 때, 먼저 댓글을 쓴 사람한테 이메일 알림 전송 기능

안녕하세요.

현재 KBoard에서 이메일 관련 기능을 만들고 있다고 들었습니다. 이전에 답변하신 도움글을 보면서 '댓글이 달리면 원글 게시자'에게 메일이 가는 건 성공했는데요.

혹시 댓글의 댓글이 달리면 바로 앞 댓글 쓴 사람에게 메일 알림이 가도록 하는 방법이 있는지 궁금합니다.

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
  • 댓글의 답글이 달리면 이메일로 알림이 전송되게 할 수 있습니다.

    아래 코드를 테마의 functions.php 파일에 추가해주세요.

    add_action('kboard_comments_insert', 'my_kboard_comments_insert', 10, 2);
    function my_kboard_comments_insert($comment_uid, $content_uid){
        $comment = new KBComment();
        $comment->initWithUID($comment_uid);
        $document = new KBContent();
        $document->initWithUID($content_uid);
        
        if($comment->parent_uid){
            $parent = new KBComment();
            $parent->initWithUID($comment->parent_uid);
            
            if($parent->user_uid){
                $user = new WP_User($parent->user_uid);
            
                if($user->user_email && $user->id != get_current_user_id()){
                    if(!class_exists('KBMail')){
                        include_once KBOARD_DIR_PATH . '/class/KBMail.class.php';
                    }
                    $url = new KBUrl();
                    $mail = new KBMail();
                    $mail->to = $user->user_email;
                    $mail->title = "답글이 등록 되었습니다.";
                    $mail->content = $comment->content;
                    $mail->url = $url->getDocumentRedirect($document->uid);
                    $mail->send();
                }
            }
            else if($parent->option->email){
                if(!class_exists('KBMail')){
                    include_once KBOARD_DIR_PATH . '/class/KBMail.class.php';
                }
                $url = new KBUrl();
                $mail = new KBMail();
                $mail->to = $parent->option->email;
                $mail->title = "답글이 등록 되었습니다.";
                $mail->content = $comment->content;
                $mail->url = $url->getDocumentRedirect($document->uid);
                $mail->send();
            }
        }
    }

     

    비회원도 이메일 알림을 받을 수 있도록 하시려면 댓글 스킨을 수정해주셔야 합니다.

    /wp-content/plugins/kboard-comments/skin/default/list.php

    위 파일에서 아래 굵게 표시된 코드를 추가해주시면 됩니다.

    <?php if(is_user_logged_in()):?>
    <input type="hidden" name="member_display" value="<?php echo $member_display?>">
    <?php else:?>
    <div class="comments-field">
        <label class="comments-field-label" for="comment_member_display"><?php echo __('Author', 'kboard-comments')?></label>
        <input type="text" id="comment_member_display" name="member_display" value="<?php echo $temporary->member_display?>" placeholder="<?php echo __('Author', 'kboard-comments')?>..." required>
    </div>
    <div class="comments-field">
        <label class="comments-field-label" for="comment_password"><?php echo __('Password', 'kboard-comments')?></label>
        <input type="password" id="comment_password" name="password" value="" placeholder="<?php echo __('Password', 'kboard-comments')?>..." required>
    </div>
    <div class="comments-field">
        <label class="comments-field-label" for="comment_email"><?php echo __('Email', 'kboard-comments')?></label>
        <input type="text" id="comment_email" name="comment_option_email" value="" placeholder="<?php echo __('Email', 'kboard-comments')?>..." required>
    </div>

    <?php endif?>

  • 정말 빠른 답변 감사드립니다. 그런데 첫번째 코드를 적용하니까 사이트가 먹통이 되네요. 혹시 빠진 부분이 있을까요?

  • 사이트가 먹통이 되는건 파일 수정이 잘못된 듯합니다.

    테스트한 코드를 그대로 복사 붙여넣기 한 것이라 버그가 있을 순 있지만 동작은 할겁니다.

    코드상 문제라면 적어도 오류 메시지라도 나와야 하거든요.

    워드프레스 디버그 모드를 활성화해서 오류 메시지가 나오는걸 확인해보시겠어요?

    워드프레스의 wp-config.php 파일에서

    define('WP_DEBUG', false); -> define('WP_DEBUG', true);

    이렇게 수정해주시면 디버그 모드가 활성화 됩니다.

    또는 워드프레스 디버그 모드 대신 아래 플러그인으로 오류 내용을 확인할 수 있습니다.

    https://ko.wordpress.org/plugins/error-log-monitor/

  • 해결했습니다. 너무 감사드립니다!

  • #커뮤니티 자동 추천글

    KBoard 커뮤니티

    더보기

좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기