class-wpml-media-add-to-basket.php
960 Bytes
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
<?php
class WPML_Media_Add_To_Basket implements IWPML_Action {
/**
* @var SitePress
*/
private $sitepress;
/**
* WPML_Media_Add_To_Basket constructor.
*/
public function __construct( SitePress $sitepress ) {
$this->sitepress = $sitepress;
}
public function add_hooks() {
add_filter(
'pre_update_option_' . $this->sitepress->get_wp_api()->constant( 'TranslationProxy_Basket::ICL_TRANSLATION_JOBS_BASKET' ),
array( $this, 'add_media' )
);
}
public function add_media( $data ) {
if ( ! empty( $data['post'] ) ) {
foreach ( $data['post'] as $post_id => $post ) {
if ( $media = $this->get_post_media( $post_id ) ) {
$data['post'][ $post_id ]['media-translation'] = $media;
}
}
}
return $data;
}
private function get_post_media( $post_id ) {
return isset( $_POST['post'][ $post_id ]['media-translation'] ) ?
array_map( 'intval', $_POST['post'][ $post_id ]['media-translation'] ) :
array();
}
}