| 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_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 mixed $post The post object. |
| 28 |
* |
| 29 |
* @return string The modified language code. |
| 30 |
*/ |
| 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 ); |
| 37 |
|
| 38 |
if ( \is_array( $language_details ) && isset( $language_details['language_code'] ) ) { |
| 39 |
$lang = $language_details['language_code']; |
| 40 |
} |
| 41 |
|
| 42 |
return $lang; |
| 43 |
} |
| 44 |
} |
| 45 |
|