MediaLibraryAssistant
2 days ago
AdvancedCustomFields.php
2 days ago
NinjaForms.php
2 days ago
WPML.php
2 days ago
WPMLColumn.php
2 days ago
WooCommerce.php
2 days ago
WPMLColumn.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\ThirdParty; |
| 6 | |
| 7 | /** |
| 8 | * WPML: display correct flags on the overview screens |
| 9 | */ |
| 10 | class WPMLColumn |
| 11 | { |
| 12 | public const COLUMN_NAME = 'icl_translations'; |
| 13 | |
| 14 | private ?string $column = null; |
| 15 | |
| 16 | public function __construct(string $post_type) |
| 17 | { |
| 18 | add_filter( |
| 19 | "manage_{$post_type}_posts_columns", |
| 20 | [$this, 'store_wpml_column'], |
| 21 | 11 // priority just after WPML set's it's column |
| 22 | ); |
| 23 | add_filter( |
| 24 | "manage_edit-{$post_type}_columns", |
| 25 | [$this, 'replace_wpml_column'], |
| 26 | 201 // priority just after AC overwrite all columns |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | public function store_wpml_column($columns) |
| 31 | { |
| 32 | if (empty($this->column) && isset($columns[self::COLUMN_NAME])) { |
| 33 | $this->column = (string)$columns[self::COLUMN_NAME]; |
| 34 | } |
| 35 | |
| 36 | return $columns; |
| 37 | } |
| 38 | |
| 39 | public function replace_wpml_column($columns) |
| 40 | { |
| 41 | if ($this->column && isset($columns[self::COLUMN_NAME])) { |
| 42 | $columns[self::COLUMN_NAME] = $this->column; |
| 43 | } |
| 44 | |
| 45 | return $columns; |
| 46 | } |
| 47 | } |
| 48 |