TableScreen.php
1.74 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
86
87
88
89
90
91
92
93
<?php
namespace ACP\Search;
use AC;
use AC\Asset\Enqueueable;
use AC\Registerable;
use ACP;
use ACP\Search\Settings\HideOnScreen;
abstract class TableScreen implements Registerable {
/**
* @var AC\ListScreen
*/
protected $list_screen;
/**
* @var Enqueueable[]
*/
protected $assets;
public function __construct( AC\ListScreen $list_screen, array $assets ) {
$this->list_screen = $list_screen;
$this->assets = $assets;
}
public function register() {
add_action( 'ac/table_scripts', [ $this, 'scripts' ] );
add_action( 'admin_head', [ $this, 'hide_segments' ] );
add_action( 'admin_footer', [ $this, 'add_segment_modal' ] );
}
public function scripts() {
foreach ( $this->assets as $asset ) {
$asset->enqueue();
}
wp_enqueue_script( 'ac-select2' );
wp_enqueue_style( 'ac-select2' );
wp_enqueue_style( 'ac-jquery-ui' );
wp_enqueue_style( 'wp-pointer' );
}
/**
* Display the markup on the current list screen
*/
public function filters_markup() {
?>
<div id="ac-s"></div>
<?php
}
/**
* @return bool
*/
private function is_segment_hidden() {
return ( new HideOnScreen\SavedFilters() )->is_hidden( $this->list_screen );
}
public function hide_segments() {
if ( $this->is_segment_hidden() ) {
?>
<style>
.ac-button__segments {
display: none !important;
}
.ac-button__add-filter {
border-top-right-radius: 3px !important;
border-bottom-right-radius: 3px !important;
}
</style>
<?php
}
}
public function add_segment_modal() {
if ( $this->is_segment_hidden() ) {
return;
}
$view = new AC\View( [
'user_can_manage_segments' => current_user_can( AC\Capabilities::MANAGE ),
] );
echo $view->set_template( 'table/segment-modal' )->render();
}
}