XFCoder :: Latest XF Threads Widget for WordPress

XFCoder :: Latest XF Threads Widget for WordPress 1.0.4.3

No permission to download
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.
 
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.
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.

Sorry for the inconvenience, I'll see if reinstalling from 0 solves it and that ghost "update" doesn't appear again.

Greetings and thanks for your attention
 
Hello again,

I have redone the installation from 0, I have checked the entire system in search of some type of modification, unknown access, etc...

Once I have made sure that nobody has accessed the system and that there are no viruses or hacks, first of all I have emptied all kinds of existing cache, I have even generated a new API key from the forum administration for the WordPress plugin.

But the problem is still the same, it only loads the latest threads, new forum posts don't load.

Can you think of what may be happening? It's not a big problem for me either, since I can leave a single widget with the latest themes, but all this already has me intrigued.

I don't use any type of proxy or anything that could interfere in between.

I have already regenerated the widget a couple of times, but all without success, the only thing that occurs to me is that the cron task in charge of pushing the changes is not doing it, I will also check it in the meantime.

I will now look at group permissions and other plugins in case any of them might be causing this problem, the WorPress version I use is the most recent.

I'm sorry for the inconvenience
Regards
 
This is an excellent plug in. I'm really surprised it's not a paid add on. Grab it before the author changes his mind!

I wanted a way to make the forum community more obvious on my WP homepage. Take a look at it in action. You'll need a scroll down a little bit first: https://rtshq.net
 
That depends on the permissions for your API key. If you selected a guest key, then only nodes visible to guests are shown. If you want to show a more specific set of nodes, you can create a user on your site, assign him the specific node permissions you need, and then create an API key based on that user.
 
Working beautifully with a user with it's on group where it can't view nodes.
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.
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.

Cheers!
 
The add-on doesn't currently support distinct API keys per widget instance.
 
Last edited:
Plugins like this don't ship with built-in caching mechanisms. You can configure Cloudflare to cache api/ GET requests more aggressively, set up WordPress to cache widget content, or implement any other caching solution at the network, server, or software level.
 
Np, I think I managed if anyone wants it, 5 mins in transient:

PHP:
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;
}
 
Back
Top Bottom