HW Image Widget example

This is an example of the responsive, user friendly HW Image Widget available for WordPress 3.5 and up. Its free for download from WordPress.org.

Did you know it sports the TinyMCE WYSIWYG editor for the text?

WEB ARTISAN

Development by Håkan Wennerberg

Export comments to Disqus not working?

Symptom:
You just installed Disqus commenting system and need to export existing WordPress comments to the service. However, the export “hangs” in WordPress admin leaving that wait icon spinning forever.

Cause:
When clicking that export comments button in WordPress admin Disqus plugin it calls WordPress once for every post. The WordPress server then makes a HTTP-request to Disqus and that request has a timeout setting by default of 5 seconds. If it timeouts, the export “hangs”.

Solution:
You need to increase the WordPress HTTP request timeout value. It defaults to 5 seconds in /wp-includes/class-http.php. Below is the WordPress code to set defaults (line 70 in WordPress 3.8):

$defaults = array(
    'method' => 'GET',
    'timeout' => apply_filters( 'http_request_timeout', 5),
    'redirection' => apply_filters( 'http_request_redirection_count', 5),
    'httpversion' => apply_filters( 'http_request_version', '1.0'),
    'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ),
    'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false ),
    'blocking' => true,
    'headers' => array(),
    'cookies' => array(),
    'body' => null,
    'compress' => false,
    'decompress' => true,
    'sslverify' => true,
    'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt',
    'stream' => false,
    'filename' => null,
    'limit_response_size' => null,
);

As you can see there is a filter named http_request_timeout that can be used to alter this value. Put snippet below in a plugin or theme:

function custom_timeout($current_timeout)
{
    // New timeout.
    return 30;
}
add_filter('http_request_timeout', 'custom_timeout');
Written by Håkan Wennerberg

Håkan (also known as PuffyThePirateBoy) is a systems architect based in Lundsbrunn, Sweden. Currently focusing on web development, Håkan is passionate about all aspects of web engineering ranging from back-end system infrastructure to front-end UX.

Outside of work, Håkan has a (slight) obsession about motorcycles and constantly trying to figure out how to get money for a bike, and what model it should be :)

Comments

Feel free to leave a comment using the form below.

Leave a Comment

Your email address will not be published. Required fields are marked *