File "wpml_translate.php"
Full Path: /home/ubunrgit/public_html/wp-content/plugins/unicoach-core/includes/elementor/includes/wpml_translate.php
File size: 4.22 KB
MIME-type: text/x-php
Charset: utf-8
<?php
namespace WglAddons\Includes;
defined('ABSPATH') || exit;
if (!class_exists('Wgl_WPML_Settings')) {
/**
* WGL Elementor module settings for WPML compatibility
*
*
* @package unicoach-core\includes\elementor
* @author WebGeniusLab <[email protected]>
* @since 1.0.8
*/
class Wgl_WPML_Settings
{
private static $instance;
public static function wpml_type_field($type) {
switch ($type) {
case 'text':
$editor_type = 'LINE';
break;
case 'textarea':
$editor_type = 'AREA';
break;
case 'wysiwyg':
$editor_type = 'VISUAL';
break;
case 'url':
$editor_type = 'LINK';
break;
default:
$editor_type = 'LINE';
}
return $editor_type;
}
public static function get_translate($self, $widgets ) {
if (!$self) {
// Bailout.
return;
}
$wpml_settings = [];
$controls_data = [];
foreach ( $self->get_controls() as $name => $control ) {
if( is_array($control) && 'advanced' !== $control['tab'] && (!isset($control['of_type'])) ){
if (
'repeater' === $control['type']
|| 'text' === $control['type']
|| 'textarea' === $control['type']
|| 'wysiwyg' === $control['type']
) {
if('repeater' === $control['type']){
$wpml_settings['name'] = $control['name'];
foreach( $control['fields'] as $key => $value ){
if (
'text' === $value['type']
|| 'textarea' === $value['type']
|| 'wysiwyg' === $value['type']
) {
$wpml_settings['fields'][] = [
'name' => $value['name'],
'label' => $value['label'] ?? esc_html__('WGL Module', 'unicoach-core'),
'type' => self::wpml_type_field($value['type'])
];
}
}
}else{
$editor_type = self::wpml_type_field($control['type']);
$controls_data[] = [
'field' => $control['name'],
'type' => $control['label'] ?? esc_html__('WGL Module', 'unicoach-core'),
'editor_type' => $editor_type
];
}
}
}
}
if(!empty($controls_data) || !empty($wpml_settings)){
$widgets[ $self->get_name() ] = [
'conditions' => [ 'widgetType' => $self->get_name() ],
'fields' => $controls_data,
];
if(!empty($wpml_settings)){
$widgets[$self->get_name() ]['integration-class'] = new \WglAddons\Includes\Wgl_Elementor_Translate($wpml_settings);
}
}
return $widgets;
}
public static function get_instance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
}
}
if (!class_exists('Wgl_Elementor_Translate')) {
class Wgl_Elementor_Translate extends \WPML_Elementor_Module_With_Items {
private $wgl_name;
private $wgl_fields;
public function __construct($params){
$this->wgl_name = !empty($params) && isset($params['name']) ? $params['name'] : '';
$this->wgl_fields['fields'] = !empty($params) && isset($params['fields']) ? $params['fields'] : [];
}
/**
* @return string
*/
public function get_items_field() {
return $this->wgl_name;
}
/**
* @return array
*/
public function get_fields() {
$name = [];
if(!empty($this->wgl_fields['fields'])){
foreach( $this->wgl_fields['fields'] as $key => $value ){
$name[] = $value['name'];
}
}
return $name;
}
/**
* @param string $field
*
* @return string
*/
protected function get_title( $field ) {
if(!empty($this->wgl_fields['fields'])){
foreach( $this->wgl_fields['fields'] as $key => $value ){
if($field === $value['name']){
return $value['label'];
}
}
}
return '';
}
/**
* @param string $field
*
* @return string
*/
protected function get_editor_type( $field ) {
if(!empty($this->wgl_fields['fields'])){
foreach( $this->wgl_fields['fields'] as $key => $value ){
if($field === $value['name']){
return $value['type'];
}
}
}
return '';
}
}
}