BaseDynamicContent.php
1.7 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
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
<?php
namespace WPML\Compatibility;
use SitePress;
abstract class BaseDynamicContent implements \IWPML_DIC_Action, \IWPML_Backend_Action, \IWPML_Frontend_Action {
/** @var SitePress */
private $sitepress;
/**
* @param SitePress $sitepress
*/
public function __construct( SitePress $sitepress ) {
$this->sitepress = $sitepress;
}
/**
* Add filters and actions.
*/
public function add_hooks() {
if ( $this->sitepress->is_setup_complete() ) {
add_filter( 'wpml_pb_shortcode_decode', [ $this, 'decode_dynamic_content' ], 10, 2 );
add_filter( 'wpml_pb_shortcode_encode', [ $this, 'encode_dynamic_content' ], 10, 2 );
}
}
/**
* Sets dynamic content to be translatable.
*
* @param string $string The decoded string so far.
* @param string $encoding The encoding used.
*
* @return string|array
*/
abstract public function decode_dynamic_content( $string, $encoding );
/**
* Rebuilds dynamic content with translated strings.
*
* @param string|array $string The field array or string.
* @param string $encoding The encoding used.
*
* @return string
*/
abstract public function encode_dynamic_content( $string, $encoding );
/**
* Check if a certain field contains dynamic content.
*
* @param string $string The string to check.
*
* @return bool
*/
abstract protected function is_dynamic_content( $string );
/**
* Decode a dynamic-content field.
*
* @param string $string The string to decode.
*
* @return array
*/
abstract protected function decode_field( $string );
/**
* Encode a dynamic-content field.
*
* @param array $field The field to encode.
*
* @return string
*/
abstract protected function encode_field( $field );
}