1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Modules\Multilingual; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\MultilingualContract as Contract; |
6
|
|
|
use GeminiLabs\SiteReviews\Database\OptionManager; |
7
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
8
|
|
|
|
9
|
|
|
class Wpml implements Contract |
10
|
|
|
{ |
11
|
|
|
public $pluginName = 'WPML'; |
12
|
|
|
public $supportedVersion = '3.3.5'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
|
|
public function getPost($postId) |
18
|
|
|
{ |
19
|
|
|
$postId = trim($postId); |
20
|
|
|
if (!is_numeric($postId)) { |
21
|
|
|
return; |
22
|
|
|
} |
23
|
|
|
if ($this->isEnabled()) { |
24
|
|
|
$postId = apply_filters('wpml_object_id', $postId, 'any', true); |
25
|
|
|
} |
26
|
|
|
return get_post(intval($postId)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function getPostIds(array $postIds) |
33
|
|
|
{ |
34
|
|
|
if (!$this->isEnabled()) { |
35
|
|
|
return $postIds; |
36
|
|
|
} |
37
|
|
|
$newPostIds = []; |
38
|
|
|
foreach (Arr::unique($postIds) as $postId) { |
39
|
|
|
$postType = get_post_type($postId); |
40
|
|
|
if (!$postType) { |
41
|
|
|
continue; |
42
|
|
|
} |
43
|
|
|
$elementType = 'post_'.$postType; |
44
|
|
|
$trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
45
|
|
|
$translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
46
|
|
|
if (!is_array($translations)) { |
47
|
|
|
$translations = []; |
48
|
|
|
} |
49
|
|
|
$newPostIds = array_merge( |
50
|
|
|
$newPostIds, |
51
|
|
|
array_column($translations, 'element_id') |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
return Arr::unique($newPostIds); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function isActive() |
61
|
|
|
{ |
62
|
|
|
return defined('ICL_SITEPRESS_VERSION'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function isEnabled() |
69
|
|
|
{ |
70
|
|
|
return $this->isActive() |
71
|
|
|
&& 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function isSupported() |
78
|
|
|
{ |
79
|
|
|
return $this->isActive() |
80
|
|
|
&& version_compare(ICL_SITEPRESS_VERSION, $this->supportedVersion, '>='); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|