Line | |
---|
1 | <?php |
---|
2 | |
---|
3 | namespace AC\Controller; |
---|
4 | |
---|
5 | use AC\ListScreenRepository\Storage\ListScreenRepository; |
---|
6 | use AC\Message\Notice; |
---|
7 | use AC\Registrable; |
---|
8 | |
---|
9 | class RestoreSettingsRequest implements Registrable { |
---|
10 | |
---|
11 | /** |
---|
12 | * @var ListScreenRepository |
---|
13 | */ |
---|
14 | private $repository; |
---|
15 | |
---|
16 | public function __construct( ListScreenRepository $repository ) { |
---|
17 | $this->repository = $repository; |
---|
18 | } |
---|
19 | |
---|
20 | public function register() { |
---|
21 | add_action( 'admin_init', [ $this, 'handle_request' ] ); |
---|
22 | } |
---|
23 | |
---|
24 | public function handle_request() { |
---|
25 | if ( 'restore' !== filter_input( INPUT_POST, 'ac_action' ) ) { |
---|
26 | return; |
---|
27 | } |
---|
28 | |
---|
29 | if ( ! wp_verify_nonce( filter_input( INPUT_POST, '_ac_nonce' ), 'restore' ) ) { |
---|
30 | return; |
---|
31 | } |
---|
32 | |
---|
33 | foreach ( $this->repository->find_all() as $list_screen ) { |
---|
34 | $this->repository->delete( $list_screen ); |
---|
35 | } |
---|
36 | |
---|
37 | $notice = new Notice( __( 'Default settings successfully restored.', 'codepress-admin-columns' ) ); |
---|
38 | $notice->register(); |
---|
39 | } |
---|
40 | |
---|
41 | } |
---|
Note: See
TracBrowser for help on using the repository browser.