PluginProbe
Admin Columns / 7.1.4
Admin Columns v7.1.4
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 All 113 releases
codepress-admin-columns / classes / ThirdParty / WPML.php
WPML.php
113 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\ThirdParty;
6
7 use AC;
8 use AC\ListScreenRepository\Storage;
9 use AC\Registerable;
10
11 /**
12 * WPML compatibility
13 */
14 class WPML implements Registerable
15 {
16 private Storage $storage;
17
18 public function __construct(Storage $storage)
19 {
20 $this->storage = $storage;
21 }
22
23 public function register(): void
24 {
25 // Display correct flags on the list tables
26 add_action('ac/table/list_screen', [$this, 'replace_flags']);
27
28 // Enable the translation of the column labels
29 add_action('init', [$this, 'register_column_labels'], 300);
30
31 // Enable the WPML translation of column headings
32 add_filter('ac/column/heading/label', [$this, 'register_translated_label'], 100);
33 }
34
35 public function replace_flags(): void
36 {
37 if (! class_exists('SitePress', false)) {
38 return;
39 }
40
41 $settings = get_option('icl_sitepress_settings');
42
43 $post_types = $settings['custom_posts_sync_option'] ?? [];
44
45 if (! $post_types) {
46 return;
47 }
48
49 $post_types = (array)$post_types;
50 $post_types['post'] = 1;
51 $post_types['page'] = 1;
52
53 foreach ($post_types as $post_type => $value) {
54 if ($value) {
55 new WPMLColumn((string)$post_type);
56 }
57 }
58 }
59
60 private function is_translation_page(): bool
61 {
62 $page = $_GET['page'] ?? null;
63
64 return 'wpml-string-translation/menu/string-translation.php' === $page;
65 }
66
67 // Create translatable column labels
68 public function register_column_labels(): void
69 {
70 if (! $this->is_translation_page()) {
71 return;
72 }
73
74 foreach ($this->storage->find_all() as $list_screen) {
75 /**
76 * @var AC\Column $column
77 */
78 foreach ($list_screen->get_columns() as $column) {
79 $setting = $column->get_setting('label');
80
81 if (! $setting) {
82 continue;
83 }
84
85 $label = $setting->get_input()->get_value();
86
87 do_action(
88 'wpml_register_single_string',
89 'Admin Columns',
90 $label,
91 $label
92 );
93 }
94 }
95 }
96
97 public function register_translated_label($label)
98 {
99 if (defined('ICL_LANGUAGE_CODE')) {
100 $label = apply_filters(
101 'wpml_translate_single_string',
102 $label,
103 'Admin Columns',
104 $label,
105 constant('ICL_LANGUAGE_CODE')
106 );
107 }
108
109 return $label;
110 }
111
112 }
113