Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*
*/
// This file must not accessed directly.
if (!defined('ABSPATH')) {
exit;
}
/**
* WPML plugin compatatibility class.
*
* @since 5.66
*/
class CiviCRM_For_WordPress_Compat_WPML {
/**
* @var object
* Plugin object reference.
* @since 5.66
* @access public
*/
public $civi;
/**
* Instance constructor.
*
* @since 5.66
*/
public function __construct() {
// Store reference to CiviCRM plugin object.
$this->civi = civi_wp();
// Register plugin compatibility hooks.
$this->register_hooks();
}
/**
* Register hooks.
*
* This is called via the constructor during the "plugins_loaded" action which
* is much earlier that CiviCRM's own internal hooks. The reason for this is
* that compability may need callbacks for events that fire well before "init"
* which is when CiviCRM begins to load.
*
* @since 5.66
*/
public function register_hooks() {
// Bail if CiviCRM not installed yet.
if (!CIVICRM_INSTALLED) {
return;
}
// Bail if WPML is not present.
if (!defined('ICL_SITEPRESS_VERSION')) {
return;
}
// Register WPML compatibility callbacks.
add_filter('civicrm/core/locale', [$this, 'locale_filter'], 10, 2);
}
/**
* Filters the CiviCRM locale for the current language as set by WPML.
*
* @since 5.66
*
* @param str $locale The locale as reported by WordPress.
* @return str $locale The locale as modified by Polylang.
*/
public function locale_filter($locale) {
$languages = apply_filters('wpml_active_languages', NULL);
foreach ($languages as $language) {
if ($language['active']) {
$locale = $language['default_locale'];
break;
}
}
return $locale;
}
}