Hi keithdukella,
Sorry for the inconvenience,
For getting data from JSON source we are using curl and if users using SSL they have to adopt it. For such cases, we create a hook that you can use in the functions.php file of the theme or child theme.
function filterCURLOptions($data, $ch, $url){
$new_ch = curl_init();
$timeout = 5;
$agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0';
curl_setopt($new_ch, CURLOPT_URL, $url);
curl_setopt($new_ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($new_ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($new_ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($new_ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($new_ch, CURLOPT_USERAGENT, $agent);
curl_setopt($new_ch, CURLOPT_REFERER, site_url());
curl_setopt($new_ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
if (curl_error($ch)) {
$error = curl_error($ch);
curl_close($ch);
throw new Exception($error);
}
if (strpos($data, '<title>Moved Temporarily</title>')) {
throw new Exception(__('wpDataTables was unable to read your Google Spreadsheet, probably it is not published correctly. <br> You can publish it by going to <b>File -> Publish to the web</b> ', 'wpdatatables'));
}
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] === 404) {
return NULL;
}
return $data;
}
add_filter('wpdatatables_curl_get_data','filterCURLOptions', 10, 3);
Let me know is it working.
Best regards.
Sorry if I am mistaken but I was having the same issue and the snippet above did not work for me. I believe that $new_ch should be consistently used in the code. For example, instead of $data = curl_exec($ch), it should be:
$data = curl_exec($new_ch);
And then $new_ch should be used instead of $ch throughout the rest of the function. I think the issue I was having was that the $new_ch option was being changed to allow the self-signed certificate but then the curl command was being run on the unchanged instance.
Again, if I am wrong I apologize! I don’t want to cause confusion.
Hi stirrell42,
Yes you are right. I apologize for providing code with those mistake.
Here is the right one:
function filterCURLOptions($data, $ch, $url){
$new_ch = curl_init();
$timeout = 5;
$agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0';
curl_setopt($new_ch, CURLOPT_URL, $url);
curl_setopt($new_ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($new_ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($new_ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($new_ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($new_ch, CURLOPT_USERAGENT, $agent);
curl_setopt($new_ch, CURLOPT_REFERER, site_url());
curl_setopt($new_ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($new_ch);
if (curl_error($new_ch)) {
$error = curl_error($new_ch);
curl_close($new_ch);
throw new Exception($error);
}
if (strpos($data, '<title>Moved Temporarily</title>')) {
throw new Exception(__('wpDataTables was unable to read your Google Spreadsheet, probably it is not published correctly. <br> You can publish it by going to <b>File -> Publish to the web</b> ', 'wpdatatables'));
}
$info = curl_getinfo($new_ch);
curl_close($new_ch);
if ($info['http_code'] === 404) {
return NULL;
}
return $data;
}
add_filter('wpdatatables_curl_get_data','filterCURLOptions', 10, 3);
Thank you for notice.
Best regards.
Hi keithdukella,
We didn’t receive feedback for a while, so we suppose that our suggestion help you out, so we will mark it as resolved.
Thank you for understanding
Best regards.