A
A
Alexander Kiselev2021-05-14 19:50:09
PHP
Alexander Kiselev, 2021-05-14 19:50:09

Why is curl not working on wordpress?

I developed a code that collects messages in the discussion of the VK group, and broadcasts to my site via the vk API.
Without cms systems, everything works fine, flies.
But as soon as I upload to the site with WP, errors immediately appear.
The site itself is built on the Elementor constructor. I output all the code through 2 shortcodes:

function commentsVKoriginal1()
{
    $token = "xxxxxxxxxx"; // access_token
    $group_id = xxxxxxxx; // ID Группы
    $topic_id = xxxxxxxxx; // ID Топика

    for ($i = 0; $i <= 12; $i++) {
        $get = curl('https://api.vk.com/method/board.getComments?group_id=' . $group_id . '&topic_id=' . $topic_id . '&extended=1' . '&offset=' . $i . '&sort=desc' . '&count=1&v=5.60&access_token=' . $token);
        $jsonGet = json_decode($get, true);

        $user_id = $jsonGet['response']['items'][0]['from_id']; // ID Автора
        $comments_id = $jsonGet['response']['items'][0]['id']; // ID комментария
        $date = $jsonGet['response']['items'][0]['date']; // Дата в unixtime
        $text = $jsonGet['response']['items'][0]['text']; // Текст
        $attachments = $jsonGet['response']['items'][0]['attachments']; // Прикрепленные файлы к записи
        $photo = $jsonGet['response']['profiles'][0]['photo_50']; // Фото Автора (50,100 и т.д.)
        $fname = $jsonGet['response']['profiles'][0]['first_name']; // Имя Автора
        $lname = $jsonGet['response']['profiles'][0]['last_name']; // Фамилия Автора
        $prov1 = gmdate("Y-m-d", $date);
        $prov2 = gmdate("Y-m-d", 1970 - 01 - 01);

        if ($prov1 == $prov2) {
            false;
        } else {
            ?>
            <div class="bp_post clear_fix ">
                <a class="bp_thumb" href="https://vk.com/id<?php echo $user_id; ?>">
                    <img class="bp_img" alt="<?php echo $fname . " " . $lname; ?>" src="<?php echo $photo; ?>">
                </a>
                <div class="bp_info">
                    <div class="bp_author_wrap">
                        <a class="bp_author"
                           href="https://vk.com/id<?php echo $user_id; ?>"><?php echo $fname . " " . $lname; ?></a>
                        <a class="bp_date"><?php echo gmdate("Y-m-d", $date); ?></a>
                        <span class="bp_topic"></span>
                    </div>
                    <div class="bp_content" id="">
                        <div class="bp_text"><?php echo $text; ?></div>
                        <div>
                            <?php
                            // проверяем, есть ли прикрепленые файлы в записи, далее берем только изображения, можно вывести опрос и т.п.
                            if ($attachments) {
                                foreach ($attachments as $attach) {
                                    echo '<a href="' . $attach['photo']['photo_1280'] . '" target="_blank">';
                                    echo '<img src="' . $attach['photo']['photo_604'] . '"height="223" style="margin:5px;">';
                                    echo '</a>';
                                }
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>

            <?
        }
    }
}


add_shortcode('commentsVKoriginal1', 'commentsVKoriginal1');
function curl23($url)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}

add_shortcode('commentsVKoriginal2', 'curl23');

Error screen:
609ea925cd71e237401768.png
The curl library itself is connected on the server. Maybe there is some kind of feature with VP? New to this cms.
PS Swears at the line:
$get = curl('https://api.vk.com/method/board.getComments?group_id=' . $group_id . '&topic_id=' . $topic_id . '&extended=1' . '&offset=' . $i . '&sort=desc' . '&count=1&v=5.60&access_token=' . $token);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
galaxy, 2021-05-14
@v1r_56

Is there a curl() function in nature?
In the curl extension, no.
And your function is called differently:

add_shortcode('commentsVKoriginal1', 'commentsVKoriginal1');
function curl23($url)
{

P
Puma Thailand, 2021-05-14
@opium

you need to install the php-curl extension probably

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question