From 7cae0350c9661e853e93e01e402f6ad08b30c667 Mon Sep 17 00:00:00 2001 From: muhammadtvk Date: Tue, 21 Feb 2023 12:13:12 +0400 Subject: [PATCH] fixes for issue #1001 fixes for issue #1001 --- .../WordPressExternalConnection.php | 1 + includes/rest-api.php | 4 +++ includes/template-tags.php | 32 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/includes/classes/ExternalConnections/WordPressExternalConnection.php b/includes/classes/ExternalConnections/WordPressExternalConnection.php index 8560f12bc..528d2149a 100644 --- a/includes/classes/ExternalConnections/WordPressExternalConnection.php +++ b/includes/classes/ExternalConnections/WordPressExternalConnection.php @@ -654,6 +654,7 @@ public function push( $post_id, $args = array() ) { 'excerpt' => $post->post_excerpt, 'distributor_original_source_id' => $this->id, 'distributor_original_site_name' => get_bloginfo( 'name' ), + 'distributor_original_site_lang' => get_bloginfo( 'language' ), 'distributor_original_site_url' => home_url(), 'distributor_original_post_url' => get_permalink( $post_id ), 'distributor_remote_post_id' => $post_id, diff --git a/includes/rest-api.php b/includes/rest-api.php index 3d05ee2ea..1022dc593 100644 --- a/includes/rest-api.php +++ b/includes/rest-api.php @@ -86,6 +86,10 @@ function process_distributor_attributes( $post, $request, $update ) { if ( ! empty( $request['distributor_original_site_name'] ) ) { update_post_meta( $post->ID, 'dt_original_site_name', sanitize_text_field( $request['distributor_original_site_name'] ) ); } + + if ( ! empty( $request['distributor_original_site_lang'] ) ) { + update_post_meta( $post->ID, 'dt_original_site_lang', sanitize_text_field( $request['distributor_original_site_lang'] ) ); + } if ( ! empty( $request['distributor_original_site_url'] ) ) { update_post_meta( $post->ID, 'dt_original_site_url', sanitize_text_field( $request['distributor_original_site_url'] ) ); diff --git a/includes/template-tags.php b/includes/template-tags.php index 0c1e2e3ea..5323bccfa 100644 --- a/includes/template-tags.php +++ b/includes/template-tags.php @@ -100,6 +100,38 @@ function distributor_get_original_site_name( $post_id = null ) { } } +/** + * Get original site language + * + * @param int $post_id Leave null to use current post + * @since 1.0 + * @return string|bool + */ +function distributor_get_original_site_lang( $post_id = null ) { + if ( null === $post_id ) { + global $post; + + $post_id = $post->ID; + } + + $original_blog_id = get_post_meta( $post_id, 'dt_original_blog_id', true ); + $original_site_lang = get_post_meta( $post_id, 'dt_original_site_lang', true ); + + if ( ! empty( $original_blog_id ) && is_multisite() ) { + switch_to_blog( $original_blog_id ); + + $lang_code = get_bloginfo( 'language' ); + + restore_current_blog(); + + return $lang_code; + } elseif ( ! empty( $original_site_lang ) ) { + return $original_site_lang; + } else { + return false; + } +} + /** * See docblock for distributor_get_original_site_name *