Addon.php
1.34 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
<?php
namespace ACP\ThirdParty\Polylang;
use AC;
use AC\Registrable;
use ACP\ListScreen\Post;
use ACP\ThirdParty\Polylang;
class Addon implements Registrable {
public function register() {
( new ColumnGroup() )->register();
add_action( 'ac/column_types', [ $this, 'add_columns' ] );
add_action( 'ac/table/list_screen', [ $this, 'register_column_replacement' ] );
add_action( 'ac/admin_scripts', [ $this, 'admin_style' ] );
}
public function register_column_replacement( AC\ListScreen $list_screen ) {
if ( ! $this->is_active() ) {
return;
}
$replacement = new ColumnReplacement( $list_screen );
$replacement->register();
}
public function admin_style() {
add_action( 'admin_head', function () {
?>
<style>
.ac-column.ac-<?= Polylang\Column\Language::TYPE ?> .ac-column-setting--label,
.ac-column.ac-<?= Polylang\Column\Language::TYPE ?> .ac-column-setting--width,
.ac-column.ac-<?= Polylang\Column\Language::TYPE ?> .ac-column-setting--export {
display: none !important;
}
</style>
<?php
} );
}
public function add_columns( AC\ListScreen $list_screen ) {
if ( $this->is_active() && $list_screen instanceof Post ) {
$list_screen->register_column_type( new Polylang\Column\Language() );
}
}
/**
* @return bool
*/
private function is_active() {
return defined( 'POLYLANG_VERSION' );
}
}