kboard_comments_insert 액션 사용으로 댓글 이메일 알림

안녕하세요?

케이보드를 잘 사용하고 있습니다.

사용자가 단 댓글에 관리자가 답변을 주면 답변 내용이 사용자에게 이메일 알림 전송되도록 하려고 하는데요.

이 경우 본래 답변을 단 사용자의 이메일을 어떻게 가져올 수 있나요?

감사합니다.

좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
  • 댓글을 단 사용자가 회원인지요?

    회원이라면 조금 더 간단할 듯합니다.

    아래 코드를 테마의 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($insert_id);
    	
    	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()){
    				
    				$title = '등록하신 댓글에 답변이 등록 되었습니다.';
    				$content = '등록하신 댓글에 대해 답변이 등록 되었습니다.';
    				wp_mail($user->user_email, $title, $content);
    			}
    		}
    	}
    }

     

    회원이 아니라면 댓글을 남길 때 이메일을 입력받아야겠죠.

    아래 코드를 테마의 functions.php 파일에 추가하시면 아마 댓글 입력창에 이메일 입력 필드가 출력될 겁니다.

    add_action('kboard_comments_field', 'my_kboard_comments_field', 5, 4);
    function my_kboard_comments_field($field_html, $board, $content_uid, $comment_builder){
    	if(!is_user_logged_in()){
    		$current_user = wp_get_current_user();
    		if(!$current_user->user_email){
    			?>
    			<div class="comments-field">
    				<label class="comments-field-label" for="comment_option_email">이메일</label>
    				<input type="email" id="comment_option_email" name="comment_option_email" value="" placeholder="이메일..." required>
    			</div>
    			<?php
    		}
    	}
    }

     

    그리고 아래 코드를 테마의 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);
    	
    	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()){
    				$title = '등록하신 댓글에 답변이 등록 되었습니다.';
    				$content = '등록하신 댓글에 대해 답변이 등록 되었습니다.';
    				wp_mail($user->user_email, $title, $content);
    			}
    		}
    		else if($parent->option->email){
    			$title = '등록하신 댓글에 답변이 등록 되었습니다.';
    			$content = '등록하신 댓글에 대해 답변이 등록 되었습니다.';
    			wp_mail($parent->option->email, $title, $content);
    		}
    	}
    }

     

    댓글 스킨에서도 새로운 입력 필드를 쉽게 추가하실 수 있습니다.

    <input type="email" name="comment_option_email">

    이렇게 필드를 추가한 다음,

    <?php echo $comment->option->email?>

    이런 형식의 코드로 입력된 값을 출력하실 수 있습니다.

     

    댓글이 아닌 게시글 작성자에게 이메일 알림에 대해서 참고 하시라고 링크 남겨드립니다.

    http://www.cosmosfarm.com/threads/document/12558

    http://www.cosmosfarm.com/threads/document/11766

  • 감사합니다.

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요