-
Notifications
You must be signed in to change notification settings - Fork 10
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
Integrate with Polylang plugin #13
Open
kusinkay
wants to merge
6
commits into
osano:master
Choose a base branch
from
kusinkay:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+128
−0
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5bbcfca
Integrate with Polylang plugin
c2645a1
Fixed: it should have at least one non-default custom text
c5fc5de
A less agressive warning
e45829a
Select policy page as a policy option
de6e7a8
Sugg. https://github.com/osano/cookieconsent-wpplugin/pull/13#discuss…
7b1a278
Sugg. https://github.com/osano/cookieconsent-wpplugin/pull/13#discuss…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,103 @@ | ||||
<?php | ||||
$icc_i18n_literals = array( | ||||
'message' => array( | ||||
'name' => 'Message', | ||||
'default' => 'This website uses cookies to ensure you get the best experience on our website.' | ||||
), | ||||
'dismiss' => array( | ||||
'name' => 'Dismiss button text', | ||||
'default' => 'Got it!' | ||||
), | ||||
'link' => array( | ||||
'name' => 'Policy link text', | ||||
'default' => 'Learn more' | ||||
), | ||||
'deny' => array( | ||||
'name' => 'Deny button text', | ||||
'default' => 'Refuse cookies' | ||||
), | ||||
); | ||||
|
||||
|
||||
function icc_i18n_init_literals() { | ||||
global $icc_i18n_literals; | ||||
if ( is_admin() ){ | ||||
if ( function_exists('pll_register_string') ) { | ||||
$plugin_name = 'Osano Cookie Consent'; | ||||
|
||||
foreach ( $icc_i18n_literals as $value ){ | ||||
pll_register_string( $value['name'], $value['default'], $plugin_name ); | ||||
} | ||||
} | ||||
} | ||||
|
||||
add_filter('privacy_policy_url', 'icc_translate_privacy_page', 10, 2); | ||||
} | ||||
|
||||
function icc_translate( $config ) { | ||||
global $icc_i18n_literals; | ||||
$result = array(); | ||||
if ( function_exists('pll_register_string')) { | ||||
$a = json_decode($config, true); | ||||
//there is more fields to be preserved than just text | ||||
$save_keys = array('href'); | ||||
$saved_content = array(); | ||||
foreach ( $a as $key => $value ){ | ||||
$result[$key] = $value; | ||||
if ( $key == 'content' ) { | ||||
foreach ( $save_keys as $key2save ) { | ||||
if ($result[$key][$key2save] != null ) { | ||||
$saved_content[$key2save] = $result[$key][$key2save]; | ||||
} | ||||
} | ||||
} | ||||
} | ||||
$result['content'] = array(); | ||||
foreach ( $icc_i18n_literals as $literal => $field ){ | ||||
if ( function_exists('pll__')){ | ||||
$result['content'][$literal] = pll__($field['default']); | ||||
} else if ( $a['content'][$literal] != null ){ | ||||
$result['content'][$literal] = $a['content'][$literal]; | ||||
} | ||||
} | ||||
$result['content'] = array_merge($result['content'], $saved_content); | ||||
return json_encode($result); | ||||
} else { | ||||
return $config; | ||||
} | ||||
|
||||
} | ||||
|
||||
function icc_i18n_warning() { | ||||
if ( function_exists('pll_register_string')) { | ||||
$wmessage = 'You have Polylang plugin installed. You should set up literals in "' . __( 'Languages', 'polylang' ) . ' > ' . __( 'Strings translations', 'polylang' ) . '"'; | ||||
$warning = <<<HTML | ||||
<tr> | ||||
<td colspan="2" style="padding-bottom:0;"> | ||||
<p style="color: red">$wmessage</p> | ||||
</td> | ||||
</tr> | ||||
HTML; | ||||
echo $warning; | ||||
} | ||||
} | ||||
|
||||
/** | ||||
* | ||||
* @param string $url | ||||
* @param int $policy_page_id | ||||
*/ | ||||
function icc_translate_privacy_page( $url, $policy_page_id){ | ||||
//die(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||
if ( function_exists('pll_get_post_translations') && function_exists('pll_current_language') && function_exists('pll_default_language')) { | ||||
$trans = pll_get_post_translations( $policy_page_id ); | ||||
$lang = pll_current_language(); | ||||
if (empty($lang)) { | ||||
$lang = pll_default_language(); | ||||
} | ||||
if ( !empty($trans) && $trans[$lang] != null ){ | ||||
return get_post_permalink($trans[$lang]); | ||||
} | ||||
} | ||||
return $url; | ||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course :$