Как получить доступ к атрибуту шорткода WordPress в curl? - PullRequest
0 голосов
/ 06 декабря 2018

Я пытаюсь разрешить атрибуту шорткода gplace_id изменить URL-адрес, вызываемый функцией curl.Но когда я это делаю, это ломается.Однако, когда я определяю значение по умолчанию, это работает.Есть мысли?

Я думаю, что это как-то связано с приоритетом, и что мне, вероятно, следует назвать это в отдельной функции?Есть идеи с этим?

    $atts = shortcode_atts(array(
        'gplace_id' => '',
        'format' => '', // column, list
        'wrapper_class' => '',
        'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" height="44" width="44"> <g fill="none" fill-rule="evenodd"> <path d="M482.56 261.36c0-16.73-1.5-32.83-4.29-48.27H256v91.29h127.01c-5.47 29.5-22.1 54.49-47.09 71.23v59.21h76.27c44.63-41.09 70.37-101.59 70.37-173.46z" fill="#4285f4"></path> <path d="M256 492c63.72 0 117.14-21.13 156.19-57.18l-76.27-59.21c-21.13 14.16-48.17 22.53-79.92 22.53-61.47 0-113.49-41.51-132.05-97.3H45.1v61.15c38.83 77.13 118.64 130.01 210.9 130.01z" fill="#34a853"></path> <path d="M123.95 300.84c-4.72-14.16-7.4-29.29-7.4-44.84s2.68-30.68 7.4-44.84V150.01H45.1C29.12 181.87 20 217.92 20 256c0 38.08 9.12 74.13 25.1 105.99l78.85-61.15z" fill="#fbbc05"></path> <path d="M256 113.86c34.65 0 65.76 11.91 90.22 35.29l67.69-67.69C373.03 43.39 319.61 20 256 20c-92.25 0-172.07 52.89-210.9 130.01l78.85 61.15c18.56-55.78 70.59-97.3 132.05-97.3z" fill="#ea4335"></path> <path d="M20 20h472v472H20V20z"></path> </g> </svg>',
        'star_color' => '#e3661a',
    ), $atts);

    // define api details array
    $api = array(
        'key' => esc_attr(get_option('hm5sr_google_api_key')),
        'place_id' => $atts['gplace_id'],
        'timeout' => 60,
        'verify_ssl' => true,
        'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6',
        'cookie' => 'cookies.txt',
    );
    $api['url'] = 'https://maps.googleapis.com/maps/api/place/details/json?key='.$api['key'].'&placeid='.$api['place_id'];

    // call api
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $api['url']);
    curl_setopt($ch, CURLOPT_USERAGENT, $api['user_agent']);
    curl_setopt($ch, CURLOPT_TIMEOUT, $api['timeout']);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $api['verify_ssl']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $api['cookie']);
    $output = curl_exec($ch);
    curl_close($ch);

    // decode json api output
    $data = json_decode($output, true);

    // get api values
    $reviews = $data['result']['reviews'];
...