Files
torebki-fabiola.pl/wp-content/plugins/woocommerce-dhl/classes/class-ajax-request.php
2026-03-05 13:07:40 +01:00

79 lines
1.3 KiB
PHP

<?php
/**
* Class WPDesk_WooCommerce_DHL_Select_Parcels_Via_Ajax
*/
class WPDesk_WooCommerce_DHL_Ajax_Request {
/**
* @var string
*/
private $city;
/**
* @var string
*/
private $code;
/**
* @var string
*/
private $country;
/**
* @var array
*/
private $request;
/** @var string Query arg is also defined in JS var */
const NONCE_ARG = 'security';
/**
* WPDesk_WooCommerce_DHL_Ajax_Request constructor.
*
* @param string $nonce_name
* @param array $request
*/
public function __construct( $nonce_name, $request ) {
$this->request = $request;
if( check_ajax_referer( $nonce_name, self::NONCE_ARG, false ) ) {
$this->country = $this->validate('country' );
$this->city = $this->validate('city' );
$this->code = $this->validate('code' );
}
}
/**
* @param string $name
*/
private function validate( $name ) {
if( isset( $this->request[ $name ] ) ) {
return sanitize_text_field( wp_unslash( $this->request[ $name ] ) );
}
}
/**
* @return string
*/
public function getCity() {
return (string) $this->city;
}
/**
* @return string
*/
public function getCode() {
return (string) $this->code;
}
/**
* @return string
*/
public function getCountry() {
return (string) $this->country;
}
}