Redesign settings with configurable workflows and detected languages
This commit is contained in:
1 parent
1bbd3e0141
commit
3b558409f3
12 files changed
+335
-187
No files matched your search
+27
-6
@@ -1,9 +1,30 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH'))exit;
|
||||
function hgcf_language($content='') {
|
||||
if($content!=='' && preg_match('/'.get_shortcode_regex(['hg_contactform','mlh_contact']).'/s',$content,$match)) {
|
||||
$attrs=shortcode_parse_atts($match[3]);if(is_array($attrs)&&in_array($attrs['lang']??'',['nl','en'],true))return $attrs['lang'];
|
||||
if (!defined('ABSPATH')) exit;
|
||||
function hgcf_languages() {
|
||||
$languages=[];
|
||||
if(function_exists('pll_languages_list')) {
|
||||
foreach(pll_languages_list(['hide_empty'=>false,'fields'=>'slug']) as $slug) {
|
||||
if(is_string($slug)&&preg_match('/^[a-z][a-z0-9_-]{1,19}$/i',$slug)) {
|
||||
$name=$slug;
|
||||
if(function_exists('PLL')) { $item=PLL()->model->get_language($slug); if($item)$name=$item->name; }
|
||||
$languages[$slug]=$name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(function_exists('pll_current_language')){ $language=pll_current_language('slug');if(in_array($language,['nl','en'],true))return $language; }
|
||||
return str_starts_with(get_locale(),'en')?'en':'nl';
|
||||
if(!$languages){$locale=get_option('WPLANG')?:'en_US';$slug=strtolower(explode('_',$locale)[0]);$languages[$slug]=['nl'=>'Nederlands','en'=>'English'][$slug]??$locale;}
|
||||
$languages=apply_filters('hgcf_languages',$languages);
|
||||
return is_array($languages)&&$languages?$languages:['en'=>'English'];
|
||||
}
|
||||
function hgcf_default_language() {
|
||||
$languages=hgcf_languages();
|
||||
if(function_exists('pll_default_language')){$lang=pll_default_language('slug');if(isset($languages[$lang]))return $lang;}
|
||||
return array_key_first($languages);
|
||||
}
|
||||
function hgcf_language($content='') {
|
||||
$languages=hgcf_languages();
|
||||
if($content!==''&&preg_match('/'.get_shortcode_regex(['hg_contactform','mlh_contact']).'/s',$content,$match)) {
|
||||
$attrs=shortcode_parse_atts($match[3]);if(is_array($attrs)&&isset($languages[$attrs['lang']??'']))return $attrs['lang'];
|
||||
}
|
||||
if(function_exists('pll_current_language')){$lang=pll_current_language('slug');if(isset($languages[$lang]))return $lang;}
|
||||
return hgcf_default_language();
|
||||
}
|
||||
Reference in new issue
Block a user