我确实说过它未经测试,对吧?
我现在无法提供太多调试帮助,但这是一个更新版本,应该可以修复该问题,并移除第二个操作中的冗余检查:
add_action( 'create_category', 'discourse_create_category', 10, 1 );
function discourse_create_category( $term_id ) {
$category = get_term_by( 'id', $term_id, 'category' );
$name = $category->name;
$path = '/categories.json';
// Use the WPDiscourse plugin to generate a new category
$utils = new \WPDiscourse\Utilities\PublicPluginUtilities();
$utils->discourse_request(
$path,
[
'method' => 'POST',
'name' => $name,
]
);
}
add_action( 'set_object_terms', 'discourse_set_object_terms', 10, 1 );
function discourse_set_object_terms( $object_id ) {
if ( ! metadata_exists( 'post', $object_id, 'publish_to_discourse' ) ) {
// Enable publishing in Discourse, during initial save only.
update_post_meta( $object_id, 'publish_to_discourse', true );
$discourse_publish_option = get_option( 'discourse_publish' );
// set the Discourse category based on WP category
if ( is_array( $discourse_publish_option ) ) {
$categories_list = wp_get_post_categories( $object_id );
update_post_meta( $object_id, 'publish_post_category', $categories_list[0]->name );
}
}
}
7.4 距离 EOL(生命周期结束)只有大约三个月了,所以你应该开始计划升级你的托管环境,如果你还没有的话 ![]()