게시글 휴지통 삭제 시 액션 훅

1. 정확한 제품 또는 플러그인 이름

케이보드

 

2. 상세 내용

안녕하세요? 케이보드 임시저장 플러그인을 커스터마이징하여 관리자뿐 아니라 모든 회원이 임시저장 기능을 이용할 수 있도록 만들었습니다.

게시글 공개/비공개(임시저장 포함) 설정에 따라 포인트를 제공하고 있는데요.

게시글 삭제(휴지통) 시 포인트를 차감해야 하는데, 바로 삭제 기능을 사용하지 않으면 kboard_document_delete 액션훅이 작동하지 않더라고요.

바로삭제 기능은 사용할 수가 없는 상황이라서, kboard_document_update 액션훅을 제가 만든 함수와 함께 사용하고 있습니다.
이를 위해서 KBContent.class.php에서 휴지통 이동 및 복구 시 실행되는 함수에다가 do_action('kboard_document_update', $this->uid, $this->board_id, $this, $board); 한 줄씩 추가했는데요.
테스트해보니 별 문제 없이 잘 작동합니다.

그런데 혹시나 이 부분을 일부러 안 넣으신 이유가 있을까 염려되어 이렇게 문의드리게 되었습니다.
만약 별 문제가 없는 부분이라면 다음 케이보드 업데이트 시 반영이 가능할까요?

<제가 작성한 함수>

add_action('kboard_document_update', 'my_kboard_document_insert', 10, 4);
function my_kboard_document_insert($content_uid, $board_id, $content, $board)
{
    if (!in_array($board_id, [10, 15])) {
        $user_id = get_current_user_id();
        $insert_point = 1000;
        if (!in_array($content->status, ['hide', 'trash']) && $content->secret != true) {
            $length = mb_strlen($content->content, 'utf-8');
            $limit_point = 3000;
            $total = mycred_get_total_by_time('today', 'now', 'my_kboard_document_insert', $user_id);

            if ( mycred_count_ref_id_instances( 'my_kboard_document_insert', $content_uid, $user_id ) % 2 == 0 ) {
                if ($board_id == '14') {
                    if ($length >= 100 && $total < $limit_point) {
                        mycred_add('my_kboard_document_insert', $user_id, $insert_point, '게시글 작성(혹은 공개로 변경) 포인트', $content_uid);
                    }
                } else {
                    if ($total < $limit_point) {
                        mycred_add('my_kboard_document_insert', $user_id, $insert_point, '게시글 작성(혹은 공개로 변경) 포인트', $content_uid);
                    }
                }
            }
        } else {
            if ( mycred_count_ref_id_instances( 'my_kboard_document_insert', $content_uid, $user_id ) % 2 == 1 ) {
                mycred_subtract('my_kboard_document_insert', $user_id, $insert_point, '게시글 삭제(혹은 임시/비공개로 변경) 포인트 차감', $content_uid);
            }
        }
    }
}

 

<수정한 클래스 함수>

/**
	 * 휴지통으로 이동할 때 실행한다.
	 * @param string $content_uid
	 */
	public function moveReplyToTrash($parent_uid){
		global $wpdb;
		
		$board = $this->getBoard();
		$board->meta->list_total = $board->getListTotal() - 1;
		
		$results = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}kboard_board_content` WHERE `parent_uid`='$parent_uid'");
		$wpdb->flush();
		foreach($results as $row){
			if($row->status != 'trash'){
				$this->moveReplyToTrash($row->uid);
			}
		}
		do_action('kboard_document_update', $this->uid, $this->board_id, $this, $board);
	}
	
	/**
	 * 휴지통에서 복구할 때 실행한다.
	 * @param string $content_uid
	 */
	public function restoreReplyFromTrash($parent_uid){
		global $wpdb;
		
		$board = $this->getBoard();
		$board->meta->list_total = $board->getListTotal() + 1;
		
		$results = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}kboard_board_content` WHERE `parent_uid`='$parent_uid'");
		$wpdb->flush();
		foreach($results as $row){
			if($row->status != 'trash'){
				$this->restoreReplyFromTrash($row->uid);
			}
		}
		do_action('kboard_document_update', $this->uid, $this->board_id, $this, $board);
	}

 

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