Skip to content

Commit

Permalink
Add support for WPML post locale (#1166)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Jan 17, 2025
1 parent 47f19ee commit e703e90
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

* Support for WPML post locale

### Removed

* Built-in support for nodeinfo2. Use the [NodeInfo plugin](https://wordpress.org/plugins/nodeinfo/) instead.
Expand Down
40 changes: 40 additions & 0 deletions integration/class-wpml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* WPML integration.
*
* @package Activitypub
*/

namespace Activitypub\Integration;

/**
* Compatibility with the WPML Multilingual CMS plugin.
*
* @see https://wpml.org/
*/
class WPML {
/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
\add_filter( 'activitypub_post_locale', array( self::class, 'get_wpml_post_locale' ), 10, 2 );
}

/**
* Fetch the post locale from the WPML post data.
*
* @param string $lang The language code.
* @param int $post_id The post ID.
*
* @return string The modified language code.
*/
public static function get_wpml_post_locale( $lang, $post_id ) {
$language_details = apply_filters( 'wpml_post_language_details', null, $post_id );

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

return $lang;
}
}
11 changes: 11 additions & 0 deletions integration/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ function ( $transformer, $data, $object_class ) {
3
);
}

/**
* Adds WPML Multilingual CMS (plugin) support.
*
* This class handles the compatibility with the WPML plugin.
*
* @see https://wpml.org/
*/
if ( \defined( 'ICL_SITEPRESS_VERSION' ) ) {
WPML::init();
}
}
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ For reasons of data protection, it is not possible to see the followers of other

= Unreleased =

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

= 4.7.1 =
Expand Down

0 comments on commit e703e90

Please sign in to comment.