class-wpml-tm-unsent-jobs.php
1.64 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
<?php
/**
* Class WPML_TM_Unsent_Jobs_Notice
*
* @group unsent-jobs-notification
*/
class WPML_TM_Unsent_Jobs {
/**
* @var WPML_TM_Blog_Translators
*/
private $blog_translators;
/**
* @var SitePress
*/
private $sitepress;
/**
* WPML_TM_Unsent_Jobs constructor.
*
* @param WPML_TM_Blog_Translators $blog_translators
* @param SitePress $sitepress
*/
public function __construct( WPML_TM_Blog_Translators $blog_translators, SitePress $sitepress ) {
$this->blog_translators = $blog_translators;
$this->sitepress = $sitepress;
}
public function add_hooks() {
add_action( 'wpml_tm_assign_job_notification', array( $this, 'prepare_unsent_job_for_notice' ) );
add_action( 'wpml_tm_new_job_notification', array( $this, 'prepare_unsent_job_for_notice' ), 10, 2 );
add_action( 'wpml_tm_local_string_sent', array( $this, 'prepare_unsent_job_for_notice' ) );
}
/**
* @param WPML_Translation_Job $job
* @param null $translator_id
*/
public function prepare_unsent_job_for_notice( WPML_Translation_Job $job, $translator_id = null ) {
if ( $translator_id ) {
$translators = array( get_userdata( $translator_id ) );
} else {
$translators = $this->blog_translators->get_blog_translators(
array(
'from' => $job->get_source_language_code(),
'to' => $job->get_language_code(),
)
);
}
foreach ( $translators as $translator ) {
$args = array(
'job' => $job,
'event' => WPML_User_Jobs_Notification_Settings::is_new_job_notification_enabled( $translator->ID ) ? 'sent' : 'unsent',
);
do_action( 'wpml_tm_jobs_translator_notification', $args );
}
}
}