Firsh
(Firsh)
2025 年3 月 23 日 13:15
1
我有一个普通的“post”文章类型,它使用 WP Discourse 插件按预期自动发布。我还有另一种文章类型,启用了 Gutenberg 编辑器,但唯一可以将现有或新创建/手动创建的主题(由社区创建)分配给它的方法是,如果我在这里标记它:
但是,标记它不仅会在此处(编辑器右上角)启用与 Discourse 相关的 UI:
而且还会自动发布我对此文章类型的所有操作。我该如何区分这些问题? 我是一名开发人员,如果能得到正确的指导,我可以应用一些代码。如果可能,我更倾向于手动将此文章类型的条目与其论坛中的主题链接起来。
1 个赞
我可能是错的;我不认为你仅凭设置就能做到这一点。
使用“按标签排除帖子”怎么样?你可以(通过插件)自动为这些自定义帖子类型应用一个特定的标签。这对你来说可行吗?
你也可以用代码进行过滤,使用 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;
}
/**
4 个赞
Firsh
(Firsh)
2025 年3 月 23 日 23: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; // Prevent auto-publishing for 'konyv' post type
}
return $publish_to_discourse; // Allow normal behavior for other post types
}
3 个赞
system
(system)
关闭
2025 年4 月 22 日 23:00
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.