如何将自定义api(cURL调用)集成到WordPress子主题中

时间:2019-07-05 12:36:10

标签: wordpress curl wordpress-rest-api php-curl

如何将第三方API集成到wordpress主题。是否有用于cURL调用的预构建wordpress函数?

以下是带有参数的代码:

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => {{API_URL}},
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => false,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "host: {{API_HOST}}"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

0 个答案:

没有答案