Firsh
(Firsh)
3월 23, 2025, 1:15오후
1
WP Discourse 플러그인을 사용하여 정상적으로 자동 게시되는 일반적인 “post” 게시 유형이 있습니다. 또한 Gutenberg 편집기를 지원하는 다른 게시 유형도 있습니다. 그런데 커뮤니티가 기존에 만들거나 새로/수동으로 만든 주제를 이 유형에 연결하려면 다음 위치에 표시해야 합니다:
그러나 이 표시를 하면 Discourse 관련 UI(편집기 오른쪽 위 모서리)가 활성화될 뿐만 아니라:
이 유형에 속하는 게시물에서 수행하는 모든 작업도 자동 게시됩니다. 이 두 가지 기능을 어떻게 분리할 수 있을까요? 저는 개발자이며, 올바른 방향만 알려주신다면 코드를 적용할 수 있습니다. 이 게시 유형의 항목을 포럼의 주제(있는 경우)와 수동으로 연결하는 방식을 선호합니다.
내가 틀릴 수도 있지만, 설정만으로 해결하기는 어려울 것 같습니다.
Exclude Posts By Tag를 사용하는 것은 어떨까요? 플러그인을 사용하여 해당 커스텀 포스트 유형에 특정 태그를 자동으로 적용할 수 있습니다. 이 방법으로 원하는 결과를 얻을 수 있을까요?
또한 wpdc_publish_after_save로 코드를 사용해 필터링할 수도 있습니다.
return null;
}
$post_should_be_auto_published = $this->auto_publish( $post_id );
$post_already_published = $this->dc_get_post_meta( $post_id, 'discourse_post_id', true );
$post_marked_to_be_published = $this->dc_get_post_meta( $post_id, 'publish_to_discourse', true );
$publish_new_post_to_discourse = ( $post_marked_to_be_published || $post_should_be_auto_published ) && ! $post_already_published;
$topic_should_be_updated = $this->dc_get_post_meta( $post_id, 'update_discourse_topic', true );
$force_publish_post = $this->force_publish_post( $post );
$publish_to_discourse = $publish_new_post_to_discourse || $topic_should_be_updated || $force_publish_post;
$publish_to_discourse = apply_filters( 'wpdc_publish_after_save', $publish_to_discourse, $post_id, $post );
if ( $publish_to_discourse ) {
// Clear existing publishing errors.
delete_post_meta( $post_id, 'wpdc_publishing_error' );
$this->sync_to_discourse( $post_id, $post->post_title, $post->post_content );
}
return null;
}
/**
Firsh
(Firsh)
3월 23, 2025, 11:00오후
4
네, 필터가 핵심이었어요! 클래스의 일부로 이렇게 구현했는데 잘 작동합니다:
add_filter('wpdc_publish_after_save', [$this, 'prevent_autopublish_for_konyv'], 10, 3);
public function prevent_autopublish_for_konyv($publish_to_discourse, $post_id, $post)
{
if ('konyv' === get_post_type($post)) {
return false; // 'konyv' 게시물 유형의 자동 게시를 방지합니다.
}
return $publish_to_discourse; // 다른 게시물 유형은 정상 동작을 허용합니다.
}