Skip to content

Instantly share code, notes, and snippets.

@KittenCodes
Last active October 4, 2023 00:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save KittenCodes/e7a7207dc56155473cd2f572e27e09ad to your computer and use it in GitHub Desktop.
Save KittenCodes/e7a7207dc56155473cd2f572e27e09ad to your computer and use it in GitHub Desktop.
Language Conditions for Oxygen
<?php
if( function_exists('oxygen_vsb_register_condition') && function_exists('pll_languages_list') ) {
$lang_list = pll_languages_list();
oxygen_vsb_register_condition(
//Condition Name
'Locale',
//Values
array(
'options' => $lang_list,
'custom' => false
),
//Operators
array('==', '!='),
//Callback Function
'polylang_callback',
//Condition Category
'Polylang'
);
function polylang_callback($value, $operator) {
$my_lang = pll_current_language();
global $OxygenConditions;
return $OxygenConditions->eval_string($my_lang, $value, $operator);
}
}
<?php
if( function_exists('oxygen_vsb_register_condition') && function_exists('weglot_get_languages_available') ) {
$lang_list_full = weglot_get_languages_available();
$lang_list = array();
foreach ($lang_list_full as $code => $value) {
$lang_list[] = $code;
}
oxygen_vsb_register_condition(
//Condition Name
'Locale',
//Values
array(
'options' => $lang_list,
'custom' => false
),
//Operators
array('==', '!='),
//Callback Function
'weglot_callback',
//Condition Category
'Weglot'
);
function weglot_callback($value, $operator) {
$my_lang = weglot_get_current_language();
global $OxygenConditions;
return $OxygenConditions->eval_string($my_lang, $value, $operator);
}
}
<?php
// WPML condition
if (function_exists('oxygen_vsb_register_condition')) {
$lang_list_full = icl_get_languages();
$lang_list = array();
foreach($lang_list_full as $code) {
$lang_list[] = $code['code'];
}
oxygen_vsb_register_condition(
//Condition Name
'Language',
//Values
array(
'options' => $lang_list,
'custom' => false
),
//Operators
array('==', '!='),
//Callback Function
'wpml_callback',
//Condition Category
'WPML'
);
function wpml_callback($value, $operator) {
$my_lang = ICL_LANGUAGE_CODE;
global $OxygenConditions;
return $OxygenConditions -> eval_string($my_lang, $value, $operator);
}
}
@trkoehler
Copy link

Hi there,

How can I use the WPML condition. It doesn't show in the oxygen builder?

@poonasor
Copy link

poonasor commented Oct 4, 2023

Hi there,

How can I use the WPML condition. It doesn't show in the oxygen builder?

you need to wrap it around an init action

add_action('init', function() {
// WPML condition
if (function_exists('oxygen_vsb_register_condition') && function_exists('icl_get_languages') ) {
...
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment