Skip to content

Commit fb39882

Browse files
jehervepfefferle
andauthored
Post representation: bring back the activitypub_post_locale filter (#1367)
It was removed in #593, but is still neeeded to customize the language of a given post. The filter is used in the WPML integration of this plugin, for example. Co-authored-by: Matthias Pfefferle <[email protected]>
1 parent 15e5910 commit fb39882

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3737
* Send Update-Activity when "Actor-Mode" is changed.
3838
* Added delay to `Announce` Activity from the Blog-Actor, to not have race conditions.
3939
* `Actor` validation in several REST API endpoints.
40+
* Bring back the `activitypub_post_locale` filter to allow overriding the post's locale.
4041

4142
## [5.2.0] - 2025-02-13
4243

includes/transformer/class-post.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,33 @@ public function get_content_visibility() {
7777
return $this->content_visibility;
7878
}
7979

80+
/**
81+
* Get the post's locale.
82+
* By default, the post's locale is the same as the blog's locale,
83+
* and is already set in the parent class's get_locale() method.
84+
* This method allows for overriding the locale for a specific post,
85+
* via a `activitypub_post_locale` filter.
86+
*
87+
* @return string The post's locale.
88+
*/
89+
public function get_locale() {
90+
/**
91+
* Filter the locale of the post.
92+
*
93+
* @param string $lang The locale of the post.
94+
* @param int $post_id The post ID.
95+
* @param WP_Post $post The post object.
96+
*
97+
* @return string The filtered locale of the post.
98+
*/
99+
return apply_filters(
100+
'activitypub_post_locale',
101+
parent::get_locale(),
102+
$this->item->ID,
103+
$this->item
104+
);
105+
}
106+
80107
/**
81108
* Returns the User-Object of the Author of the Post.
82109
*

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ For reasons of data protection, it is not possible to see the followers of other
154154
* Fixed: Send Update-Activity when "Actor-Mode" is changed.
155155
* Fixed: Added delay to `Announce` Activity from the Blog-Actor, to not have race conditions.
156156
* Fixed: `Actor` validation in several REST API endpoints.
157+
* Fixed: Bring back the `activitypub_post_locale` filter to allow overriding the post's locale.
157158

158159
= 5.2.0 =
159160

0 commit comments

Comments
 (0)