Addon.php
2.3 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
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace ACP\Editing;
use AC;
use AC\Asset\Location;
use AC\ListScreenRepository\Storage;
use AC\Registrable;
use AC\Request;
use ACP;
use ACP\Settings\ListScreen\HideOnScreenCollection;
class Addon implements Registrable {
/**
* @var Storage
*/
private $storage;
/**
* @var Location\Absolute
*/
private $location;
/** @var Request */
private $request;
public function __construct( Storage $storage, Location\Absolute $location, Request $request ) {
$this->storage = $storage;
$this->location = $location;
$this->request = $request;
}
public function register() {
add_action( 'ac/column/settings', [ $this, 'register_column_settings' ] );
add_action( 'ac/table/list_screen', [ $this, 'register_table_screen' ] );
add_action( 'wp_ajax_acp_editing_request', [ $this, 'ajax_edit_request' ] );
add_action( 'acp/admin/settings/hide_on_screen', [ $this, 'add_hide_on_screen' ], 10, 2 );
}
public function add_hide_on_screen( HideOnScreenCollection $collection, AC\ListScreen $list_screen ) {
if ( $list_screen instanceof ListScreen ) {
$collection->add( new Admin\HideOnScreen\InlineEdit() )
->add( new Admin\HideOnScreen\BulkEdit(), 20 );
}
}
public function ajax_edit_request() {
check_ajax_referer( 'ac-ajax' );
$factory = new RequestHandlerFactory( $this->storage );
$factory->create( $this->request )
->handle( $this->request );
}
/**
* @param AC\ListScreen $list_screen
*/
public function register_table_screen( AC\ListScreen $list_screen ) {
if ( ! $list_screen instanceof ListScreen ) {
return;
}
$editable_data = ( new EditableDataFactory() )->create( $list_screen );
if ( ! $editable_data ) {
return;
}
$table_screen = new TableScreen(
$list_screen,
$editable_data,
$this->location,
new Preference\EditState(),
$this->request
);
$table_screen->register();
}
public function register_column_settings( AC\Column $column ) {
( new ColumnInlineSettingsSetter() )->register( $column );
( new ColumnBulkSettingsSetter() )->register( $column );
}
/**
* @return bool
* @deprecated 5.1
*/
public function is_editing_active() {
_deprecated_function( __METHOD__, '5.1' );
return false;
}
/**
* @deprecated 4.5.4
*/
public function helper() {
_deprecated_function( __METHOD__, '4.5.4' );
}
}