| Server IP : 13.126.101.145 / Your IP : 216.73.217.37 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ip-11-115-0-196 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 10:54:48 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.3.17 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/rentals_updated/wp-content/plugins/api_manager/includes/ |
Upload File : |
<?php
if (!defined('ABSPATH')) exit; // Exit if accessed directly
class Billdesk_Endpoint {
// Constructor to register the custom endpoint
public function __construct() {
add_action('init', [$this, 'register_custom_endpoint']);
}
// Register a custom endpoint
public function register_custom_endpoint() {
add_rewrite_rule('^billdesk-endpoint/?$', 'index.php?billdesk_endpoint=1', 'top');
add_filter('query_vars', [$this, 'add_query_var']);
add_action('template_redirect', [$this, 'handle_custom_endpoint']);
}
// Add custom query var for detection
public function add_query_var($query_vars) {
$query_vars[] = 'billdesk_endpoint';
return $query_vars;
}
// Handle requests to the custom endpoint
public function handle_custom_endpoint() {
if (get_query_var('billdesk_endpoint') != 1) {
return;
}
// Include WordPress functions for DB
global $wpdb;
header('Content-Type: application/json');
// Parse the incoming data
$request_body = file_get_contents('php://input');
// $data = json_decode($request_body, true);
if (empty($request_body)) {
header('HTTP/1.0 400 Bad Request');
echo json_encode(['error' => 'Invalid data: Missing Data']);
exit;
}
// Sanitize data
// $data = sanitize_text_field($data);
// Database table name
$table_name = $wpdb->prefix . 'billdesk_ref_data';
// Ensure the table exists
$wpdb->query("
CREATE TABLE IF NOT EXISTS $table_name (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
code LONGTEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (id)
) " . $wpdb->get_charset_collate()
);
// Insert the data
$inserted = $wpdb->insert($table_name, [
'code' => $request_body,
'created_at' => current_time('mysql')
]);
// Return the response
if ($inserted) {
header('Content-Type: application/json');
echo json_encode(['success' => 'Data saved successfully']);
} else {
header('HTTP/1.0 500 Internal Server Error');
echo json_encode(['error' => 'Failed to save data']);
}
exit;
}
}
// Initialize the endpoint
new Billdesk_Endpoint();