Skip to content

Commit e703e90

Browse files
thomas-pikemattwiebepfefferle
authored
Add support for WPML post locale (#1166)
* Add support for WPML post locale * Address review check failures * added missing changelog --------- Co-authored-by: Matt Wiebe <[email protected]> Co-authored-by: Matthias Pfefferle <[email protected]>
1 parent 47f19ee commit e703e90

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
* Support for WPML post locale
13+
1014
### Removed
1115

1216
* Built-in support for nodeinfo2. Use the [NodeInfo plugin](https://wordpress.org/plugins/nodeinfo/) instead.

integration/class-wpml.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* WPML integration.
4+
*
5+
* @package Activitypub
6+
*/
7+
8+
namespace Activitypub\Integration;
9+
10+
/**
11+
* Compatibility with the WPML Multilingual CMS plugin.
12+
*
13+
* @see https://wpml.org/
14+
*/
15+
class WPML {
16+
/**
17+
* Initialize the class, registering WordPress hooks.
18+
*/
19+
public static function init() {
20+
\add_filter( 'activitypub_post_locale', array( self::class, 'get_wpml_post_locale' ), 10, 2 );
21+
}
22+
23+
/**
24+
* Fetch the post locale from the WPML post data.
25+
*
26+
* @param string $lang The language code.
27+
* @param int $post_id The post ID.
28+
*
29+
* @return string The modified language code.
30+
*/
31+
public static function get_wpml_post_locale( $lang, $post_id ) {
32+
$language_details = apply_filters( 'wpml_post_language_details', null, $post_id );
33+
34+
if ( is_array( $language_details ) && isset( $language_details['language_code'] ) ) {
35+
$lang = $language_details['language_code'];
36+
}
37+
38+
return $lang;
39+
}
40+
}

integration/load.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ function ( $transformer, $data, $object_class ) {
100100
3
101101
);
102102
}
103+
104+
/**
105+
* Adds WPML Multilingual CMS (plugin) support.
106+
*
107+
* This class handles the compatibility with the WPML plugin.
108+
*
109+
* @see https://wpml.org/
110+
*/
111+
if ( \defined( 'ICL_SITEPRESS_VERSION' ) ) {
112+
WPML::init();
113+
}
103114
}
104115
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );
105116

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ For reasons of data protection, it is not possible to see the followers of other
134134

135135
= Unreleased =
136136

137+
* Added: Support for WPML post locale
137138
* Removed: Built-in support for nodeinfo2. Use the [NodeInfo plugin](https://wordpress.org/plugins/nodeinfo/) instead.
138139

139140
= 4.7.1 =

0 commit comments

Comments
 (0)