3 * @package WPSEO\Admin|Google_Search_Console
7 * Class WPSEO_GSC_Bulk_Action
9 class WPSEO_GSC_Bulk_Action {
12 * Setting the listener on the bulk action post
14 public function __construct() {
15 if ( wp_verify_nonce( filter_input( INPUT_POST, 'wpseo_gsc_nonce' ), 'wpseo_gsc_nonce' ) ) {
16 $this->handle_bulk_action();
21 * Handles the bulk action when there is an action posted
23 private function handle_bulk_action() {
24 if ( $bulk_action = $this->determine_bulk_action() ) {
25 $this->run_bulk_action( $bulk_action, $this->posted_issues() );
27 wp_redirect( filter_input( INPUT_POST, '_wp_http_referer' ) );
33 * Determine which bulk action is selected and return that value
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' ) ) {
43 // If posted action is the selected one below the table, return that value.
44 if ( $action = filter_input( INPUT_POST, 'action2' ) ) {
52 * Get the posted issues and return them
56 private function posted_issues() {
57 if ( $issues = filter_input( INPUT_POST, 'wpseo_crawl_issues', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ) ) {
61 // Fallback if issues are empty.
66 * Runs the bulk action
68 * @param string $bulk_action
69 * @param array $issues
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 );
81 * Marks the issue as fixed
83 * @param string $issue
87 private function action_mark_as_fixed( $issue ) {
88 new WPSEO_GSC_Marker( $issue );