fix issue when locale is only two chars (#549)

for example  "de" instead of "de_DE"
This commit is contained in:
Matthias Pfefferle 2023-11-07 08:49:48 +01:00 committed by GitHub
parent 9d5bd8c220
commit a81e20a9ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -82,7 +82,7 @@ class Post {
$object->set_content( $this->get_content() );
$object->set_content_map(
array(
\strstr( \get_locale(), '_', true ) => $this->get_content(),
$this->get_locale() => $this->get_content(),
)
);
$path = sprintf( 'users/%d/followers', intval( $wp_post->post_author ) );
@ -580,4 +580,25 @@ class Post {
protected function get_mentions() {
return apply_filters( 'activitypub_extract_mentions', array(), $this->wp_post->post_content, $this->wp_post );
}
/**
* Returns the locale of the post.
*
* @return string The locale of the post.
*/
public function get_locale() {
$post_id = $this->wp_post->ID;
$lang = \strtolower( \strtok( \get_locale(), '_-' ) );
/**
* Filter the locale of the post.
*
* @param string $lang The locale of the post.
* @param int $post_id The post ID.
* @param WP_Post $post The post object.
*
* @return string The filtered locale of the post.
*/
return apply_filters( 'activitypub_post_locale', $lang, $post_id, $this->wp_post );
}
}