wpml_frontend_cookie_setting = $wpml_frontend_cookie_setting; } public function add_hooks() { add_action( 'wp_ajax_wpml_update_cookie_setting', array( $this, 'update_cookie_setting' ) ); } public function update_cookie_setting() { if ( ! $this->is_valid_request() ) { wp_send_json_error(); } else { if( array_key_exists( WPML_Cookie_Setting::COOKIE_SETTING_FIELD, $_POST ) ) { $store_frontend_cookie = filter_var( $_POST[ WPML_Cookie_Setting::COOKIE_SETTING_FIELD ], FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE ); $this->wpml_frontend_cookie_setting->set_setting( $store_frontend_cookie ); } else { $this->wpml_frontend_cookie_setting->set_setting( 0 ); } wp_send_json_success(); } } /** * @return bool */ private function is_valid_request() { $valid_request = false; if ( array_key_exists( 'nonce', $_POST ) ) { $valid_request = wp_verify_nonce( $_POST['nonce'], self::NONCE_COOKIE_SETTING ); } return $valid_request; } }