3 * @package WPSEO\Admin|Google_Search_Console
12 * Setting the AJAX hooks for GSC
14 public function __construct() {
15 add_action( 'wp_ajax_wpseo_mark_fixed_crawl_issue', array( $this, 'ajax_mark_as_fixed' ) );
16 add_action( 'wp_ajax_wpseo_gsc_create_redirect_url', array( $this, 'ajax_create_redirect' ) );
17 add_action( 'wp_ajax_wpseo_dismiss_gsc', array( $this, 'dismiss_notice' ) );
21 * This method will be access by an AJAX request and will mark an issue as fixed.
23 * First it will do a request to the Google API
25 public function ajax_mark_as_fixed( ) {
26 if ( $this->valid_nonce() ) {
27 $marker = new WPSEO_GSC_Marker( filter_input( INPUT_POST, 'url' ) );
29 wp_die( $marker->get_response() );
36 * Handling the request to create a new redirect from the issued URL
38 public function ajax_create_redirect() {
39 if ( $this->valid_nonce() && class_exists( 'WPSEO_URL_Redirect_Manager' ) && defined( 'WPSEO_PREMIUM_PATH' ) ) {
40 $redirect_manager = new WPSEO_URL_Redirect_Manager();
42 $old_url = filter_input( INPUT_POST, 'old_url' );
44 // Creates the redirect.
45 if ( $redirect_manager->create_redirect( $old_url, filter_input( INPUT_POST, 'new_url' ), filter_input( INPUT_POST, 'type' ) ) ) {
46 if ( filter_input( INPUT_POST, 'mark_as_fixed' ) === 'true' ) {
47 new WPSEO_GSC_Marker( $old_url );
58 * Handle the AJAX request and dismiss the GSC notice
60 public function dismiss_notice() {
61 check_ajax_referer( 'dismiss-gsc-notice' );
63 update_user_meta( get_current_user_id(), 'wpseo_dismissed_gsc_notice', true );
69 * Check if posted nonce is valid and return true if it is
73 private function valid_nonce() {
74 return wp_verify_nonce( filter_input( INPUT_POST, 'ajax_nonce' ), 'wpseo-gsc-ajax-security' );