MediaLibraryAssistant
3 months ago
AdvancedCustomFields.php
3 months ago
NinjaForms.php
3 months ago
WPML.php
3 months ago
WPMLColumn.php
3 months ago
WooCommerce.php
3 months ago
WPML.php
111 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\ThirdParty; |
| 4 | |
| 5 | use AC; |
| 6 | use AC\ListScreenRepository\Storage; |
| 7 | use AC\Registerable; |
| 8 | |
| 9 | /** |
| 10 | * WPML compatibility |
| 11 | */ |
| 12 | class WPML implements Registerable |
| 13 | { |
| 14 | |
| 15 | private Storage $storage; |
| 16 | |
| 17 | public function __construct(Storage $storage) |
| 18 | { |
| 19 | $this->storage = $storage; |
| 20 | } |
| 21 | |
| 22 | public function register(): void |
| 23 | { |
| 24 | // Display correct flags on the list tables |
| 25 | add_action('ac/table/list_screen', [$this, 'replace_flags']); |
| 26 | |
| 27 | // Enable the translation of the column labels |
| 28 | add_action('init', [$this, 'register_column_labels'], 300); |
| 29 | |
| 30 | // Enable the WPML translation of column headings |
| 31 | add_filter('ac/column/heading/label', [$this, 'register_translated_label'], 100); |
| 32 | } |
| 33 | |
| 34 | public function replace_flags(): void |
| 35 | { |
| 36 | if ( ! class_exists('SitePress', false)) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | $settings = get_option('icl_sitepress_settings'); |
| 41 | |
| 42 | $post_types = $settings['custom_posts_sync_option'] ?? []; |
| 43 | |
| 44 | if ( ! $post_types) { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | $post_types = (array)$post_types; |
| 49 | $post_types['post'] = 1; |
| 50 | $post_types['page'] = 1; |
| 51 | |
| 52 | foreach ($post_types as $post_type => $value) { |
| 53 | if ($value) { |
| 54 | new WPMLColumn((string)$post_type); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | private function is_translation_page(): bool |
| 60 | { |
| 61 | $page = $_GET['page'] ?? null; |
| 62 | |
| 63 | return 'wpml-string-translation/menu/string-translation.php' === $page; |
| 64 | } |
| 65 | |
| 66 | // Create translatable column labels |
| 67 | public function register_column_labels(): void |
| 68 | { |
| 69 | if ( ! $this->is_translation_page()) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | foreach ($this->storage->find_all() as $list_screen) { |
| 74 | /** |
| 75 | * @var AC\Column $column |
| 76 | */ |
| 77 | foreach ($list_screen->get_columns() as $column) { |
| 78 | $setting = $column->get_setting('label'); |
| 79 | |
| 80 | if ( ! $setting) { |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | $label = $setting->get_input()->get_value(); |
| 85 | |
| 86 | do_action( |
| 87 | 'wpml_register_single_string', |
| 88 | 'Admin Columns', |
| 89 | $label, |
| 90 | $label |
| 91 | ); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | public function register_translated_label($label) |
| 97 | { |
| 98 | if (defined('ICL_LANGUAGE_CODE')) { |
| 99 | $label = apply_filters( |
| 100 | 'wpml_translate_single_string', |
| 101 | $label, |
| 102 | 'Admin Columns', |
| 103 | $label, |
| 104 | constant('ICL_LANGUAGE_CODE') |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | return $label; |
| 109 | } |
| 110 | |
| 111 | } |