FileName.php
1.14 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
<?php
namespace ACP\Export\RequestHandler\Ajax;
use AC\ListScreenRepository;
use AC\Nonce;
use AC\Request;
use AC\Type\ListScreenId;
use ACP\RequestAjaxHandler;
class FileName implements RequestAjaxHandler {
/**
* @var ListScreenRepository
*/
private $list_screen_repository;
public function __construct( ListScreenRepository $list_screen_repository ) {
$this->list_screen_repository = $list_screen_repository;
}
public function handle() {
$request = new Request();
if ( ! ( new Nonce\Ajax() )->verify( $request ) ) {
wp_send_json_error();
}
$id = (string) $request->filter( 'layout', null, FILTER_SANITIZE_FULL_SPECIAL_CHARS );
if ( ! ListScreenId::is_valid_id( $id ) ) {
wp_send_json_error();
}
$list_screen = $this->list_screen_repository->find(
new ListScreenId( $id )
);
if ( ! $list_screen ) {
wp_send_json_error();
}
// This hook allows you to change the default generated CSV filename.
$file_name = apply_filters(
'acp/export/file_name',
(string) $request->filter( 'file_name', null, FILTER_SANITIZE_FULL_SPECIAL_CHARS ),
$list_screen
);
wp_send_json_success( (string) $file_name );
}
}