RestoreSettingsRequest.php
1002 Bytes
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
<?php
namespace AC\Controller;
use AC\Capabilities;
use AC\ListScreenRepository\Storage\ListScreenRepository;
use AC\Message\Notice;
use AC\Registrable;
class RestoreSettingsRequest implements Registrable {
/**
* @var ListScreenRepository
*/
private $repository;
public function __construct( ListScreenRepository $repository ) {
$this->repository = $repository;
}
public function register() {
add_action( 'admin_init', [ $this, 'handle_request' ] );
}
public function handle_request() {
if ( ! current_user_can( Capabilities::MANAGE ) ) {
return;
}
if ( 'restore' !== filter_input( INPUT_POST, 'ac_action' ) ) {
return;
}
if ( ! wp_verify_nonce( filter_input( INPUT_POST, '_ac_nonce' ), 'restore' ) ) {
return;
}
foreach ( $this->repository->find_all() as $list_screen ) {
$this->repository->delete( $list_screen );
}
$notice = new Notice( __( 'Default settings successfully restored.', 'codepress-admin-columns' ) );
$notice->register();
}
}