| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPML Compatibility for Header Footer Elementor. |
| 4 |
* |
| 5 |
* @package EASYEL |
| 6 |
* @author EASYEL |
| 7 |
* @copyright Copyright (c) 2018, EASYEL |
| 8 |
* @since EASYEL 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Set up WPML Compatibiblity Class. |
| 15 |
*/ |
| 16 |
class EASYEL_WPML_Compatibility { |
| 17 |
|
| 18 |
/** |
| 19 |
* Instance of EASYEL_WPML_Compatibility. |
| 20 |
* |
| 21 |
* @since 1.0.9 |
| 22 |
* @var null |
| 23 |
*/ |
| 24 |
private static $_instance = null; |
| 25 |
|
| 26 |
/** |
| 27 |
* Get instance of EASYEL_WPML_Compatibility |
| 28 |
* |
| 29 |
* @since 1.0.9 |
| 30 |
* @return EASYEL_WPML_Compatibility |
| 31 |
*/ |
| 32 |
public static function instance() { |
| 33 |
if ( ! isset( self::$_instance ) ) { |
| 34 |
self::$_instance = new self(); |
| 35 |
} |
| 36 |
|
| 37 |
return self::$_instance; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Setup actions and filters. |
| 42 |
* |
| 43 |
* @since 1.0.9 |
| 44 |
*/ |
| 45 |
private function __construct() { |
| 46 |
add_filter( 'easyel_get_settings_type_header', [ $this, 'easyel_wpml_object' ] ); |
| 47 |
add_filter( 'easyel_get_settings_type_easy_after__header', [ $this, 'easyel_wpml_object' ] ); |
| 48 |
add_filter( 'easyel_get_settings_type_footer', [ $this, 'easyel_wpml_object' ] ); |
| 49 |
add_filter( 'easyel_get_settings_type_before_footer', [ $this, 'easyel_wpml_object' ] ); |
| 50 |
add_filter( 'easyel_get_settings_type_easy_topbar', [ $this, 'easyel_wpml_object' ] ); |
| 51 |
add_filter( 'hfe_render_template_id', [ $this, 'easyel_wpml_object' ] ); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Pass the final header and footer ID from the WPML's object filter to allow strings to be translated. |
| 56 |
* |
| 57 |
* @since 1.0.0 |
| 58 |
* @param Int $id Post ID of the template being rendered. |
| 59 |
* @return Int $id Post ID of the template being rendered, Passed through the `wpml_object_id` id. |
| 60 |
*/ |
| 61 |
public function easyel_wpml_object( $id ) { |
| 62 |
$translated_id = apply_filters( 'wpml_object_id', $id ); |
| 63 |
|
| 64 |
if ( defined( 'POLYLANG_BASENAME' ) ) { |
| 65 |
|
| 66 |
if ( null === $translated_id ) { |
| 67 |
|
| 68 |
// The current language is not defined yet or translation is not available. |
| 69 |
return $id; |
| 70 |
} else { |
| 71 |
|
| 72 |
// Return translated post ID. |
| 73 |
return $translated_id; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
if ( null === $translated_id ) { |
| 78 |
$translated_id = ''; |
| 79 |
} |
| 80 |
|
| 81 |
return $translated_id; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Initiate the class. |
| 87 |
*/ |
| 88 |
EASYEL_WPML_Compatibility::instance(); |
| 89 |
|