Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
beneverard committed Jan 8, 2019
2 parents 586c4b6 + 63d2a26 commit 80f6c1b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ The Idea Bureau, WordPresss Foundation

A collection of classes to base WordPress theme functionality on

Version 1.0.0
Version 1.0.1
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "theideabureau/wordpress-foundation",
"version": "1.0.0",
"version": "1.0.1",
"description": "A collection of classes to base WordPress theme functionality on",
"license": "MIT",
"autoload": {
Expand Down
36 changes: 32 additions & 4 deletions src/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,21 @@ function googleTranslate(string $content, string $language_code) {

}

/**
* detect if the post is a duplicate of another
* @param int $post_id the post id to check
* @return boolean
*/
function isDuplicate($post_id = NULL) {

if ( ! $post_id ) {
$post_id = get_the_ID();
}

return metadata_exists('post', $post_id, '_icl_lang_duplicate_of');

}

/**
* fetch either the translation parent id, or itself
* @param int $post_id the post id to check
Expand All @@ -351,13 +366,22 @@ function getTranslationParentId($post_id = NULL) {
$post_id = get_the_ID();
}

$duplicate_of = get_post_meta($post_id, '_icl_lang_duplicate_of', TRUE);
return apply_filters('wpml_object_id', $post_id, get_post_type($post_id), true, 'en');

if ( ! empty($duplicate_of) ) {
return $duplicate_of;
}

/**
* determine if the post should be automatically translated
* @param int $post_id the post id to check
* @return boolean
*/
function isPostTranslatable($post_id = NULL) {

if ( ! $post_id ) {
$post_id = get_the_ID();
}

return $post_id;
return $this->getLanguageCode() !== 'en' && ( $this->isDuplicate() || $post_id === $this->getTranslationParentId() );

}

Expand Down Expand Up @@ -397,6 +421,10 @@ function translateFilter(string $content, int $post_id, string $key) {
return $content;
}

if ( ! $this->isPostTranslatable($post_id) ) {
return $content;
}

if ( $this->ignoreSpecficTranslation($post_id, $key) ) {
return $content;
}
Expand Down

0 comments on commit 80f6c1b

Please sign in to comment.