我正在尝试设置一个多站点,每次添加新站点时,都会在Cloudflare中添加一个DNS记录。到目前为止,代码仍在运行,但我在尝试将子域值解析到变量上时遇到了问题。
这是迄今为止的代码:
function create_cloudflare_dns_record() {
//$current_site = \'\'.$get_blog_details->siteurl.\'\';
//$current_site = \'\'.$substr( $current_site, -8).\'\';
//$current_site = \'\'.explode(\'.\', $current_site).\'\';
/* Cloudflare.com | APİv4 | Api Ayarları */
$apikey = \'778***************************c37\'; // Cloudflare Global API
$email = \'al******@***********.com\'; // Cloudflare Email Adress
$domain = \'mer*****.com\'; // zone_name // Cloudflare Domain Name
$zoneid = \'ecc**********************1e1\'; // zone_id // Cloudflare Domain Zone ID
//$current_site = \'\'.$get_sites->path.\'\';
$current_site = explode(\'.\', $_SERVER[\'HTTP_HOST\']);
// $_SERVER[\'HTTP_HOST\']
// A-record oluşturur DNS sistemi için.
$ch = curl_init("https://api.cloudflare.com/client/v4/zones/".$zoneid."/dns_records");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
\'X-Auth-Email: \'.$email.\'\',
\'X-Auth-Key: \'.$apikey.\'\',
\'Cache-Control: no-cache\',
// \'Content-Type: multipart/form-data; charset=utf-8\',
\'Content-Type:application/json\',
\'purge_everything: true\'
));
// -d curl parametresi.
$data = array(
\'type\' => \'CNAME\',
\'name\' => \'\'.$current_site.\'\',
\'content\' => \'mer***.com\',
\'zone_name\' => \'\'.$domain.\'\',
\'zone_id\' => \'\'.$zoneid.\'\',
\'proxied\' => true,
\'ttl\' => \'120\'
);
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
//curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data_string));
$sonuc = curl_exec($ch);
/*
//print_r($sonuc);
*/
curl_close($ch);
}
add_action( \'wp_insert_site\', \'create_cloudflare_dns_record\' );
在函数的begining处对$current\\u站点进行的三次不同尝试都没有产生任何结果。
如果手动替换$current\\u site的值,则代码正常工作。
非常感谢您的帮助。