|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Modules; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Database\OptionManager; |
|
6
|
|
|
|
|
7
|
|
|
class Polylang |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param int|string $postId |
|
11
|
|
|
* @return array |
|
12
|
|
|
*/ |
|
13
|
|
|
public function getPost( $postId ) |
|
14
|
|
|
{ |
|
15
|
|
|
if( $this->isEnabled() ) { |
|
16
|
|
|
$polylangPostId = pll_get_post( $postId, pll_get_post_language( get_the_ID() )); |
|
|
|
|
|
|
17
|
|
|
} |
|
18
|
|
|
if( !empty( $polylangPostId )) { |
|
19
|
|
|
$postId = $polylangPostId; |
|
20
|
|
|
} |
|
21
|
|
|
return get_post( intval( $postId )); |
|
|
|
|
|
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @return array |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getPostIds( array $postIds ) |
|
28
|
|
|
{ |
|
29
|
|
|
if( !$this->isEnabled() ) { |
|
30
|
|
|
return $postIds; |
|
31
|
|
|
} |
|
32
|
|
|
$newPostIds = []; |
|
33
|
|
|
foreach( $this->cleanIds( $postIds ) as $postId ) { |
|
34
|
|
|
$newPostIds = array_merge( |
|
35
|
|
|
$newPostIds, |
|
36
|
|
|
array_values( pll_get_post_translations( $postId )) |
|
|
|
|
|
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
return $this->cleanIds( $newPostIds ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return bool |
|
44
|
|
|
*/ |
|
45
|
|
|
public function isActive() |
|
46
|
|
|
{ |
|
47
|
|
|
return function_exists( 'PLL' ) |
|
48
|
|
|
&& function_exists( 'pll_get_post' ) |
|
49
|
|
|
&& function_exists( 'pll_get_post_language' ) |
|
50
|
|
|
&& function_exists( 'pll_get_post_translations' ); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return bool |
|
55
|
|
|
*/ |
|
56
|
|
|
public function isEnabled() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->isActive() |
|
59
|
|
|
&& glsr( OptionManager::class )->get( 'settings.general.support.polylang' ) == 'yes'; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
|
|
public function isSupported() |
|
66
|
|
|
{ |
|
67
|
|
|
return defined( 'POLYLANG_VERSION' ) |
|
68
|
|
|
&& version_compare( POLYLANG_VERSION, '2.3', '>=' ); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return array |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function cleanIds( array $postIds ) |
|
75
|
|
|
{ |
|
76
|
|
|
return array_filter( array_unique( $postIds )); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|