]> _ Git - couzy.git/blob
14f192cf448dc3430bcd3ccf066546ca179f13fa
[couzy.git] /
1 <?php
2 /**
3  * @package WPSEO\Admin|Google_Search_Console
4  */
5
6 /**
7  * Class WPSEO_GSC_Bulk_Action
8  */
9 class WPSEO_GSC_Bulk_Action {
10
11         /**
12          * Setting the listener on the bulk action post
13          */
14         public function __construct() {
15                 if ( wp_verify_nonce( filter_input( INPUT_POST, 'wpseo_gsc_nonce' ), 'wpseo_gsc_nonce' ) ) {
16                         $this->handle_bulk_action();
17                 }
18         }
19
20         /**
21          * Handles the bulk action when there is an action posted
22          */
23         private function handle_bulk_action() {
24                 if ( $bulk_action = $this->determine_bulk_action() ) {
25                         $this->run_bulk_action( $bulk_action, $this->posted_issues() );
26
27                         wp_redirect( filter_input( INPUT_POST, '_wp_http_referer' ) );
28                         exit;
29                 }
30         }
31
32         /**
33          * Determine which bulk action is selected and return that value
34          *
35          * @return string|bool
36          */
37         private function determine_bulk_action() {
38                 // If posted action is the selected one above the table, return that value.
39                 if ( $action = filter_input( INPUT_POST, 'action' ) ) {
40                         return $action;
41                 }
42
43                 // If posted action is the selected one below the table, return that value.
44                 if ( $action = filter_input( INPUT_POST, 'action2' ) ) {
45                         return $action;
46                 }
47
48                 return false;
49         }
50
51         /**
52          * Get the posted issues and return them
53          *
54          * @return array
55          */
56         private function posted_issues() {
57                 if ( $issues = filter_input( INPUT_POST, 'wpseo_crawl_issues', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ) ) {
58                         return $issues;
59                 }
60
61                 // Fallback if issues are empty.
62                 return array();
63         }
64
65         /**
66          * Runs the bulk action
67          *
68          * @param string $bulk_action
69          * @param array  $issues
70          */
71         private function run_bulk_action( $bulk_action, $issues ) {
72                 switch ( $bulk_action ) {
73                         case 'mark_as_fixed' :
74                                 array_map( array( $this, 'action_mark_as_fixed' ), $issues );
75
76                                 break;
77                 }
78         }
79
80         /**
81          * Marks the issue as fixed
82          *
83          * @param string $issue
84          *
85          * @return string
86          */
87         private function action_mark_as_fixed( $issue ) {
88                 new WPSEO_GSC_Marker( $issue );
89
90                 return $issue;
91         }
92
93 }