I have written a wordpress plugin, but it does not seem to be sending the data to cyberpanel. Can anyone help me out?
<?php
/*
Plugin Name: CyberPanel User Creation
Description: Creates a CyberPanel user when a new WordPress user is registered.
Version: 1.0
Author: Secret
*/
function cyberpanel_create_user($user_id) {
// Get the user data
$user = get_userdata($user_id);
$username = $user->user_login;
$password = $user->user_pass;
$email = $user->user_email;
// $domainName = "";
$packageType = "Default";
// CyberPanel API endpoint
$url = "https://cp.supernovadatacentre.com/cloudAPI/";
// API credentials
$api_token = "secret";
// Request payload
$data = array(
"username" => $username,
"password" => $password,
"email" => $email,
"domainName" => $domainName,
"packageType" => $packageType
);
// HTTP headers
$headers = array(
"Content-Type: application/json",
"Authorization: Bearer " . $api_token
);
// Initialize a new cURL session
$curl = curl_init();
// Set the cURL options
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => $headers
));
// Execute the cURL request
$response = curl_exec($curl);
// Get the HTTP status code
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// Close the cURL session
curl_close($curl);
// Check if the request was successful
if ($status_code == 200) {
error_log("CyberPanel user created successfully.");
} else {
error_log("Error creating CyberPanel user: $response");
}
}
add_action('user_register', 'cyberpanel_create_user', 10, 1);
?>