워드프레스 댓글 알람 관련 문의

코스모스팜 회원관리 플러그인 기능에 알림기능이 있습니다.

그런데 이 알림이 KBoard(케이보드)에서만 한정되있고 글(post) 댓글란에는 알림이 안 울리더군요

포스트에도 알림이 울릴 수 있도록 확장 방법은 없습니까?

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

    다른 플러그인 혹은 워드프레스 포스트(post) 쪽에도 알림을 보내시려면

    cosmosfarm_members_send_notification 함수를 사용하시면 가능합니다.

    포스트 댓글에도 알림을 보내시려면

    워드프레스 관리자 -> 외모 -> 테마 편집기 페이지에서 functions.php 파일 하단에

    아래의 코드를 활용해보시겠어요?

    add_action('wp_insert_comment','comment_inserted',99,2);
    function comment_inserted($comment_id, $comment){
    	$post = get_post($comment->comment_post_ID);
    	if(get_current_user_id() != $post->post_author){
    		cosmosfarm_members_send_notification(array(
    			'to_user_id' => $post->post_author,
    			'title'      => '새로운 알림의 제목입니다.',
    			'content'    => '새로운 알림의 내용입니다.',
    			'item_type'  => 'default',
    			'meta_input' => array(
    				'url'           => $post->guid,
    				'url_name'      => '댓글 링크'
    			)
    		));
    	}
    }

     

    아래의 링크들도 참고해보시면 도움이 되실 듯합니다.

    워드프레스 알림 메시지 기능 안내

    https://developer.wordpress.org/reference/functions/wp_insert_post/

    https://developer.wordpress.org/reference/functions/wp_insert_comment/

    고맙습니다.

  • 가능하군요

    커스텀 포스트에도 적용하려면 어떤 것을 수정하면 되는가요?

  • 말씀하신 커스텀 포스트는 어떤 것인지요?

    워드프레스 포스트를 기준으로 설명을 드리자면

    이전 댓글에서 안내해드린 코드에서

    아래의 코드를

    if(get_current_user_id() != $post->post_author){

    아래의 코드처럼 적용하시면

    if(get_current_user_id() != $post->post_author && $post->post_type == 'post'){

     

    post_type이 post(워드프레스 포스트)의 댓글에만 알림을 보냅니다.

    기존의 코드로 적용하신다면 post 타입뿐만 아니라 커스텀 포스트 쪽도 알림을 보냅니다.

    어떤 커스텀 포스트인지 알려주시면 저희도 직접 테스트해보겠습니다.

    고맙습니다.

  • 음.. 테스트 해봤는데 왜 알림이 댓글 작성자한테 가는게 아니고 답글을 단 운영자인 저에게 알림이 갈까요?

  • 안녕하세요.

    이전에 안내해드린 코드는 워드프레스 포스트에 댓글이 달리면

    포스트를 쓴 사람에게 알림을 보내는 코드입니다.

    댓글에 대댓글을 달 때 댓글을 쓴 회원에게 알림을 보내시려면

    아래의 코드를 활용해보시겠어요?

    add_action('wp_insert_comment','comment_inserted', 99, 2);
    function comment_inserted($comment_id, $comment){
    	if($comment->comment_parent){
    		$post = get_post($comment->comment_post_ID);
    		$parent_comment = get_comment($comment->comment_parent);
    		if(get_current_user_id() != $parent_comment->user_id){
    			cosmosfarm_members_send_notification(array(
    				'to_user_id' => $parent_comment->user_id,
    				'title'      => '새로운 알림의 제목입니다.',
    				'content'    => '새로운 알림의 내용입니다.',
    				'item_type'  => 'default',
    				'meta_input' => array(
    					'url'           => $post->guid,
    					'url_name'      => '댓글 링크'
    				)
    			));
    		}
    	}
    }

    고맙습니다.

  • 알림은 잘 작동하는데 댓글 링크가 사라져서 볼 수가 없네요 ㅠ 어떻게하죠?

  • 아래의 코드 위에

    $parent_comment = get_comment($comment->comment_parent);

    아래의 코드도 추가해주시겠어요?

    $post = get_post($comment->comment_post_ID);

    고맙습니다.

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