Plugin Directory

source: codepress-admin-columns/trunk/classes/Controller/RestoreSettingsRequest.php @ 2293580

Last change on this file since 2293580 was 2293580, checked in by tschutter, 5 years ago

trunk

File size: 911 bytes
Line 
1<?php
2
3namespace AC\Controller;
4
5use AC\ListScreenRepository\Storage\ListScreenRepository;
6use AC\Message\Notice;
7use AC\Registrable;
8
9class 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.