Hooks.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
<?php
namespace WPML\PB\Shutdown;
class Hooks implements \IWPML_Frontend_Action, \IWPML_Backend_Action, \IWPML_DIC_Action {
const PRIORITY_REGISTER_STRINGS = 10;
const PRIORITY_SAVE_TRANSLATIONS_TO_POST = 20;
const PRIORITY_TRANSLATE_MEDIA = 30;
/** @var \WPML_PB_Integration $pbIntegration */
private $pbIntegration;
public function __construct( \WPML_PB_Integration $pbIntegration ) {
$this->pbIntegration = $pbIntegration;
}
public function add_hooks() {
add_action( 'shutdown', [ $this, 'registerStrings' ], self::PRIORITY_REGISTER_STRINGS );
add_action( 'shutdown', [ $this->pbIntegration, 'save_translations_to_post' ], self::PRIORITY_SAVE_TRANSLATIONS_TO_POST );
add_action( 'shutdown', [ $this, 'translateMedias' ], self::PRIORITY_TRANSLATE_MEDIA );
}
/**
* This applies only on original posts.
*/
public function registerStrings() {
foreach( $this->pbIntegration->get_save_post_queue() as $post ) {
$this->pbIntegration->register_all_strings_for_translation( $post );
}
}
/**
* This applies only on post translations.
*/
public function translateMedias() {
if ( defined( 'WPML_MEDIA_VERSION' ) ) {
foreach( $this->pbIntegration->get_save_post_queue() as $post ) {
$this->pbIntegration->translate_media( $post );
}
}
}
}