Skip to content

Commit

Permalink
fixes for issue 10up#1001
Browse files Browse the repository at this point in the history
fixes for issue 10up#1001
  • Loading branch information
muhammadtvk committed Feb 21, 2023
1 parent 13fb240 commit 7cae035
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) );
Expand Down
32 changes: 32 additions & 0 deletions includes/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 7cae035

Please sign in to comment.