Display Recent WordPress Posts Widget – "We cannot load blog data at this time"
-
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
- The topic ‘Display Recent WordPress Posts Widget – "We cannot load blog data at this time"’ is closed to new replies.