# WP Discourse：为 discourse\_publish\_format\_html 提供高级自定义过滤器

**URL:** https://meta.discourse.org/t/wp-discourse-advanced-custom-filter-for-discourse-publish-format-html/106059
**Category:** WordPress
**Created:** [2019 年1 月 9 日 14:35 UTC](https://meta.discourse.org/t/wp-discourse-advanced-custom-filter-for-discourse-publish-format-html/106059 "2019-01-09T14:35:02Z")
**Posts on this page:** 1
**Showing post:** 10

<div class="post-metadata">

### 作者： ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### 发布日期： [2019 年1 月 11 日 00:31 UTC](https://meta.discourse.org/t/wp-discourse-advanced-custom-filter-for-discourse-publish-format-html/106059/10 "2019-01-11T00:31:07Z")

</div>

If you update to [WP Discourse Version 1.8.2](https://wordpress.org/plugins/wp-discourse/), you can now pass a `$post_id` parameter to the `publish_format_html` template. Doing this will make it possible to access the current post when the post is published with the Block Editor, or through the REST API.

Here’s a quick example of how to use it. I’ll add more detailed examples and update [Customize the structure of WP Discourse templates](https://meta.discourse.org/t/wp-discourse-template-customization/50754) very soon.

```plaintext
function wpdc_custom_publish_format_html( $output, $post_id ) {
	ob_start();
    the_permalink( $post_id );
	$output = ob_get_clean();
	return $output;
}
add_filter( 'discourse_publish_format_html', 'wpdc_custom_publish_format_html', 10, 2 );

```

To have access to the `$post_id` parameter, you need to be sure to call `add_filter` with the priority and accepted\_args parameters from the example.

For cases where you are trying to access properties of the current post, instead of using `global $post` use

```plaintext
$post = get_post( $post_id );

```

---

_[View the full topic](https://meta.discourse.org/t/wp-discourse-advanced-custom-filter-for-discourse-publish-format-html/106059)._
