Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for WPML post locale #1166

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading