Base.php
1.28 KB
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
<?php
namespace WPML\PB\Gutenberg\ConvertIdsInBlock;
use WPML\Convert\Ids;
class Base {
/**
* @param array $block
*
* @return array
*/
public function convert( array $block ) {
return $block;
}
/**
* @see Ids::convert(), supports string lists with any separator.
*
* @param array|int|string $ids
* @param string $elementSlug e.g. "page", "category", ...
* @param string|null $elementType "post" or "taxonomy".
*
* @return array|int
*/
public static function convertIds( $ids, $elementSlug, $elementType = null ) {
// In this context, it's probably better to always fall back to original.
// But for backward compatibility, we'll decide that based on the translation mode
// when the $elementType is explicitly passed.
$fallbackToOriginal = $elementType ? self::isDisplayedAsTranslated( $elementSlug, $elementType ) : true;
return Ids::convert( $ids, $elementSlug, $fallbackToOriginal );
}
/**
* @param string $slug
* @param string $type
*
* @return bool
*/
private static function isDisplayedAsTranslated( $slug, $type ) {
/** @var \SitePress $sitepress */
global $sitepress;
return 'post' === $type
? $sitepress->is_display_as_translated_post_type( $slug )
: $sitepress->is_display_as_translated_taxonomy( $slug );
}
}