Код: Выделить всё
class Class_dashboard {
public function __construct() {
$this->display_latest_post();
add_action('rest_api_init', array($this, 'lincense_register_routes'));
}
public function lincense_register_routes() {
register_rest_route('license/v2', '/verify/', array(
'methods' => 'POST',
'callback' => array($this, 'verify_license_key'),
'permission_callback' => '__return_true',
));
}
public function verify_license_key(WP_REST_Request $request) {
header("Access-Control-Allow-Origin: *"); // Allow requests from any origin
header("Access-Control-Allow-Methods: POST, GET");
header("Access-Control-Allow-Headers: Content-Type");
$license_key = sanitize_text_field($request->get_param('license_key'));
//$license_key === '06078F5C173B8B98BFA8';
global $wpdb;
$table_name = $wpdb->prefix . 'woo_license_item';
$result = $wpdb->get_row(
$wpdb->prepare("SELECT * FROM $table_name WHERE licenseKey = %s", $license_key)
);
if ($result) {
// Check if the license is active and not expired
//if ($result->keystatus === 'close' && (empty($result->expiration_date) || strtotime($result->expiration_date) > time())) {
if ($result->keystatus === 'close') {
return new WP_REST_Response(array('status' => 'valid', 'message' => 'License is valid'), 200);
} else {
return new WP_REST_Response(array('status' => 'expired', 'message' => 'License has expired'), 200);
}
} else {
return new WP_REST_Response(array('status' => 'invalid', 'message' => 'License key not found'), 200);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... oesnt-work