Thanks, that's what I was doing right now, although I doubt they've sneaked in a virus/hack, but I'm not ruling it out either.This plugin isn't in the WordPress repository, I only posted it here. So yes please try installing from scratch and also try scanning your installation for viruses/hacks.
Minor code improvements
What's the criteria to include or exclude a node?gigipmc updated XFCoder :: Latest XF Threads Widget for WordPress with a new update entry:
1.0.4.2
Read the rest of this update entry...
I don't need this but I wonder if this is doable if the API key was "by widget instance" instead of a single general one for them all.This is almost exactly what I'm looking for with one exception -- is there a way to make this specific to a single forum? I would like to have three instances of the widget for three different forums.
function xfcoder_threads_api_get($endpoint, array $params = [])
{
$ret = (object) [
'success' => false,
'message' => '',
'data' => [],
'args' => func_get_args()
];
$wpOption = get_option('xfcoder_threads');
if ( empty($wpOption['api_url']) || !filter_var($wpOption['api_url'], FILTER_VALIDATE_URL) ) {
$ret->message = 'Invalid API URL';
$ret->data = $wpOption;
return $ret;
}
if ( empty($wpOption['api_key']) || !is_scalar($wpOption['api_key']) ) {
$ret->message = 'Invalid API key';
$ret->data = $wpOption;
return $ret;
}
// Build the request URL
$url = rtrim($wpOption['api_url'], '/') . "/$endpoint" . ( $params ? '?' . http_build_query($params) : '' );
// ---- BEGIN ADDED CODE FOR CACHING WITH TRANSIENT ----
// Create a unique transient key based on the endpoint + query params
$transient_key = 'xfcoder_threads_' . md5($url);
// Check if we have a cached response already
$cached = get_transient($transient_key);
if ( $cached !== false ) {
// If cached response is available, return it directly
return $cached;
}
// ---- END ADDED CODE FOR CACHING WITH TRANSIENT ----
// Prepare the request arguments with the API key
$args = [
'headers' => [
'XF-Api-Key' => $wpOption['api_key']
]
];
// Make the remote request
$response = wp_remote_get($url, $args);
if ( is_wp_error($response) ) {
$ret->message = 'Received erroneous response';
$ret->data = $response->get_error_messages();
return $ret;
}
if ( !is_array($response) || empty($response['response']) ) {
$ret->message = 'Received invalid response';
$ret->data = strlen($response) > 100 ? substr($response, 0, 100).'...' : $response;
return $ret;
}
if ( $response['response']['code'] != 200 ) {
$ret->message = 'Received response error ' . $response['response']['code'] . ': ' . $response['response']['message'];
if ( ($data = json_decode(wp_remote_retrieve_body($response))) && !empty($data->errors) ) {
$ret->data = $data->errors;
}
return $ret;
}
// If everything went fine, decode the response and set success = true
$ret->success = true;
$ret->data = json_decode(wp_remote_retrieve_body($response));
// ---- BEGIN ADDED CODE FOR CACHING WITH TRANSIENT ----
// Store the full $ret object in a transient for 5 minutes
set_transient($transient_key, $ret, 5 * MINUTE_IN_SECONDS);
// ---- END ADDED CODE FOR CACHING WITH TRANSIENT ----
return $ret;
}
Increased fetch timeout to 30s from the default WP 5s, to allow results to appear on slow servers
We use essential cookies to make this site work, and optional cookies to enhance your experience.