WPML.php
1.95 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
<?php
namespace AC\ThirdParty;
use AC\ListScreenRepository\Storage;
use AC\Registrable;
/**
* WPML compatibility
*/
class WPML implements Registrable {
/**
* @var Storage
*/
private $storage;
/**
* @param Storage $storage
*/
public function __construct( Storage $storage ) {
$this->storage = $storage;
}
function register() {
// display correct flags on the overview screens
add_action( 'ac/table/list_screen', [ $this, 'replace_flags' ] );
// enable the translation of the column labels
add_action( 'ac/list_screens', [ $this, 'register_column_labels' ], 300 );
// enable the WPML translation of column headings
add_filter( 'ac/headings/label', [ $this, 'register_translated_label' ], 100 );
}
public function replace_flags() {
if ( ! class_exists( 'SitePress', false ) ) {
return;
}
$settings = get_option( 'icl_sitepress_settings' );
if ( ! isset( $settings['custom_posts_sync_option'] ) ) {
return;
}
$post_types = (array) $settings['custom_posts_sync_option'];
$post_types['post'] = 1;
$post_types['page'] = 1;
foreach ( $post_types as $post_type => $value ) {
if ( $value ) {
new WPMLColumn( $post_type );
}
}
}
// Create translatable column labels
public function register_column_labels() {
// don't load this unless required by WPML
if ( ! isset( $_GET['page'] ) || 'wpml-string-translation/menu/string-translation.php' !== $_GET['page'] ) {
return;
}
foreach ( $this->storage->find_all() as $list_screen ) {
foreach ( $list_screen->get_columns() as $column ) {
do_action( 'wpml_register_single_string', 'Admin Columns', $column->get_custom_label(), $column->get_custom_label() );
}
}
}
/**
* @param string $label
*
* @return string
*/
public function register_translated_label( $label ) {
if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
$label = apply_filters( 'wpml_translate_single_string', $label, 'Admin Columns', $label, ICL_LANGUAGE_CODE );
}
return $label;
}
}