-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathListScreenDelete.php
56 lines (41 loc) · 1.25 KB
/
ListScreenDelete.php
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
declare(strict_types=1);
namespace AC\RequestHandler\Ajax;
use AC\Capabilities;
use AC\ListScreenRepository\Storage;
use AC\Nonce;
use AC\Request;
use AC\RequestAjaxHandler;
use AC\Response;
use AC\Type\ListScreenId;
class ListScreenDelete implements RequestAjaxHandler
{
private $storage;
public function __construct(Storage $storage)
{
$this->storage = $storage;
}
public function handle(): void
{
if ( ! current_user_can(Capabilities::MANAGE)) {
return;
}
$request = new Request();
$response = new Response\Json();
if ( ! (new Nonce\Ajax())->verify($request)) {
$response->error();
}
$list_screen = $this->storage->find(new ListScreenId($request->get('list_id')));
if ( ! $list_screen) {
$response->error();
}
$this->storage->delete($list_screen);
do_action('acp/list_screen/deleted', $list_screen);
$response->set_message(
sprintf(
__('Table view %s successfully deleted.', 'codepress-admin-columns'),
sprintf('<strong>"%s"</strong>', esc_html($list_screen->get_title() ?: $list_screen->get_label()))
)
)->success();
}
}