Skip to content

Commit 064bc58

Browse files
jehervepfefferle
andauthored
Deprecate activitypub_post_locale in favor of activitypub_locale (#1370)
* Deprecate activitypub_post_locale in favor of activitypub_locale Follow-up to #1367 * check for WP_Post --------- Co-authored-by: Matthias Pfefferle <[email protected]>
1 parent b5fb6f6 commit 064bc58

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
* Outbox processing accounts for shared inboxes again.
3030
* Improved check for `?activitypub` query-var.
3131
* Rewrite rules: be more specific in author rewrite rules to avoid conflicts on sites that use the "@author" pattern in their permalinks.
32+
* Deprecate the `activitypub_post_locale` filter in favor of the `activitypub_locale` filter.
3233

3334
### Fixed
3435

includes/transformer/class-base.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,28 @@ public function to_activity( $type ) {
236236
protected function get_locale() {
237237
$lang = \strtolower( \strtok( \get_locale(), '_-' ) );
238238

239+
if ( $this->item instanceof \WP_Post ) {
240+
/**
241+
* Deprecates the `activitypub_post_locale` filter.
242+
*
243+
* @param string $lang The locale of the post.
244+
* @param mixed $item The post object.
245+
*
246+
* @return string The filtered locale of the post.
247+
*/
248+
$lang = apply_filters_deprecated(
249+
'activitypub_post_locale',
250+
array(
251+
$lang,
252+
$this->item->ID,
253+
$this->item,
254+
),
255+
'5.4.0',
256+
'activitypub_locale',
257+
'Use the `activitypub_locale` filter instead.'
258+
);
259+
}
260+
239261
/**
240262
* Filter the locale of the post.
241263
*

includes/transformer/class-post.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,6 @@ 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-
10780
/**
10881
* Returns the User-Object of the Author of the Post.
10982
*

integration/class-wpml.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@ class WPML {
1717
* Initialize the class, registering WordPress hooks.
1818
*/
1919
public static function init() {
20-
\add_filter( 'activitypub_post_locale', array( self::class, 'get_wpml_post_locale' ), 10, 2 );
20+
\add_filter( 'activitypub_locale', array( self::class, 'get_wpml_post_locale' ), 10, 2 );
2121
}
2222

2323
/**
2424
* Fetch the post locale from the WPML post data.
2525
*
26-
* @param string $lang The language code.
27-
* @param int $post_id The post ID.
26+
* @param string $lang The language code.
27+
* @param int $post The post object.
2828
*
2929
* @return string The modified language code.
3030
*/
31-
public static function get_wpml_post_locale( $lang, $post_id ) {
32-
$language_details = apply_filters( 'wpml_post_language_details', null, $post_id );
31+
public static function get_wpml_post_locale( $lang, $post ) {
32+
if ( ! $post instanceof \WP_Post ) {
33+
return $lang;
34+
}
35+
36+
$language_details = apply_filters( 'wpml_post_language_details', null, $post->ID );
3337

3438
if ( is_array( $language_details ) && isset( $language_details['language_code'] ) ) {
3539
$lang = $language_details['language_code'];

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ For reasons of data protection, it is not possible to see the followers of other
148148
* Changed: Outbox processing accounts for shared inboxes again.
149149
* Changed: Improved check for `?activitypub` query-var.
150150
* Changed: Rewrite rules: be more specific in author rewrite rules to avoid conflicts on sites that use the "@author" pattern in their permalinks.
151+
* Changed: Deprecate the `activitypub_post_locale` filter in favor of the `activitypub_locale` filter.
151152
* Fixed: The Outbox purging routine no longer is limited to deleting 5 items at a time.
152153
* Fixed: An issue where the outbox could not send object types other than `Base_Object` (introduced in 5.0.0).
153154
* Fixed: Ellipses now display correctly in notification emails for Likes and Reposts.

0 commit comments

Comments
 (0)