PluginProbe
ActivityPub / trunk
ActivityPub vtrunk
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / integration / class-wpml.php

class-wpml.php in ActivityPub trunk, at integration/class-wpml.php

45 lines 973 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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