class-wpml-tm-page-builders-hooks.php
3.14 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
class WPML_TM_Page_Builders_Hooks {
/* @var WPML_TM_Page_Builders $worker */
private $worker;
/** @var SitePress $sitepress */
private $sitepress;
/**
* WPML_TM_Page_Builders constructor.
*
* @param WPML_TM_Page_Builders $worker
*/
public function __construct( WPML_TM_Page_Builders $worker = null, SitePress $sitepress ) {
$this->worker = $worker;
$this->sitepress = $sitepress;
}
public function init_hooks() {
add_filter( 'wpml_tm_translation_job_data', array( $this, 'translation_job_data_filter' ), 10, 3 );
add_action( 'wpml_pro_translation_completed', array( $this, 'pro_translation_completed_action' ), 10, 3 );
add_filter( 'wpml_tm_adjust_translation_fields', array( $this, 'adjust_translation_fields_filter' ), 10, 2 );
add_filter( 'wpml_tm_job_layout', array( $this, 'job_layout_filter' ) );
add_filter( 'wpml_link_to_translation', array( $this, 'link_to_translation_filter' ), 20, 4 );
add_filter( 'wpml_get_translatable_types', array( $this, 'remove_shortcode_strings_type_filter' ), 11);
}
/**
* @param array $translation_package
* @param mixed $post
* @param bool $isOriginal
*
* @return array
*/
public function translation_job_data_filter( array $translation_package, $post, $isOriginal = false ) {
$worker = $this->get_worker();
return $worker->translation_job_data_filter( $translation_package, $post, $isOriginal );
}
/**
* @param int $new_post_id
* @param array $fields
* @param stdClass $job
*/
public function pro_translation_completed_action( $new_post_id, array $fields, stdClass $job ) {
$worker = $this->get_worker();
$worker->pro_translation_completed_action( $new_post_id, $fields, $job );
}
/**
* Filter translation fields.
*
* @param array $fields Translation fields.
* @param stdClass $job Translation job.
*
* @return array
*/
public function adjust_translation_fields_filter( array $fields, $job ) {
$worker = $this->get_worker();
$fields = $worker->adjust_translation_fields_filter( $fields, $job );
return $fields;
}
/**
* @param array $layout
*
* @return array
*/
public function job_layout_filter( array $layout ) {
$worker = $this->get_worker();
return $worker->job_layout_filter( $layout );
}
/**
* @param string $link
* @param int $post_id
* @param string $lang
* @param int $trid
*
* @return string
*/
public function link_to_translation_filter( $link, $post_id, $lang, $trid ) {
$worker = $this->get_worker();
return $worker->link_to_translation_filter( $link, $post_id, $lang, $trid );
}
/**
* Remove "Page Builder ShortCode Strings" from translation dashboard filters
*
* @param array $types
*
* @return mixed
*/
public function remove_shortcode_strings_type_filter( $types ) {
if ( array_key_exists( 'page-builder-shortcode-strings', $types ) ) {
unset( $types['page-builder-shortcode-strings'] );
}
return $types;
}
/**
* @return WPML_TM_Page_Builders
*/
private function get_worker() {
if ( ! $this->worker ) {
$this->worker = new WPML_TM_Page_Builders( $this->sitepress );
}
return $this->worker;
}
}