• I activated the JetPack “Display Recent WordPress Posts Widget” feature on my multi-site and found that I was sporadically getting the “‘We cannot load blog data at this time” message coming up.

    Doing a little debugging of mine own I found that this error message was being thrown in the “get_site_info” function in the jetpack->modules->widgets->wordpress-post-widget.php file (line 41).

    Initially the function looks to see if there is site info data in the cache (line 44):

    $data_from_cache = get_transient( 'display_posts_post_info_' . $site_hash );

    If it does not find the site info in the cache the function goes out to retrieve it (lines 46 – 51)

    if ( false === $data_from_cache ) {
    $response = wp_remote_get( sprintf( 'https://public-api.wordpress.com/rest/v1.1/sites/%s', urlencode( $site ) ) );
    set_transient( 'display_posts_site_info_' . $site_hash, $response, 10 * MINUTE_IN_SECONDS );
    } else {
    $response = $data_from_cache;
    }

    The issue is that the objects returned from these two calls are not formed the same way. The call to api.wordpress.com returns the properly formatted response, so if the function pulls the data from that it will show the posts as expected. If the function tries to pull from the cached information it will fail at one of the following isset validations and return a null thus throwing the “We cannot load blog data at this time” error.

    My quick bandaid was to set the $data_from_cache to false prior to the checks on line 46.

    A better long term solution would be to properly parse out the cache and the api responses.

    Hope this helps.

    John

    https://www.ads-software.com/plugins/jetpack/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Thanks for the report!

    If the function tries to pull from the cached information it will fail at one of the following isset validations and return a null

    Could you let me know which one, so I can run some more tests?

    Thanks!

    Thread Starter jwrightspplus

    (@jwrightspplus)

    About line 61 or so…

    if ( !isset( $site_info->ID ) ) {
    			return false;
    		}

    If you look at the two different object created by get_transient function does not have an ID field where as the object created by the wp_remote_get function does.

    Hope this helps.

    John

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    I ran some tests, and I don’t notice any difference between the object I get from the cached transient and the one I get by querying for the data live.

    Would you mind doing a var_dump() of the 2 objects you get on your end, and posting the results here or in a Gist so I can take a closer look?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Recent WordPress Posts Widget – "We cannot load blog data at this time"’ is closed to new replies.