WordPress.org

Plugin Directory

Changeset 682166


Ignore:
Timestamp:
03/15/13 06:32:21 (13 months ago)
Author:
alexdunae
Message:

Allow setting request timeout

Location:
wp-smushit/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-smushit/trunk/readme.txt

    r682162 r682166  
    3737Sometimes the Smush.it service goes down or is under heavy load. If the plugin has difficulty connecting to Smush.it then automatically smushing is temporarily disabled (currently for 6 hours). You can always re-enable it via the `Media > Settings` screen or manually smush the image from the Media Library. 
    3838 
     39You can also define how long you want to wait for the Smush.it server to respond. 
     40 
    3941= NextGEN Gallery = 
    4042NextGEN user?  Also download the <a href="http://wordpress.org/extend/plugins/wp-smushit-nextgen-gallery-integration/">WP Smush.it NextGEN Integration</a> plugin. 
     
    6567* check image size before uploading (1 MB limit) 
    6668* attempt to smush more than one image before bailing (kind thanks to <a href="http://wordpress.org/support/profile/xrampage16">xrampage16</a>) 
     69* allow setting timeout value under `Media > Settings` (default is 60 seconds) 
    6770 
    6871= 1.6.2 = 
  • wp-smushit/trunk/settings.php

    r549334 r682166  
    22 
    33  /* 
    4    
     4 
    55    Each service has a setting specifying whether it should be used automatically on upload. 
    6      
     6 
    77    Values are: 
    88      -1  Don't use (until manually enabled via Media > Settings) 
    99      0   Use automatically 
    1010      n   Any other number is a Unix timestamp indicating when the service can be used again 
    11    
     11 
    1212  */ 
    13    
     13 
    1414  define('WP_SMUSHIT_AUTO_OK', 0); 
    1515  define('WP_SMUSHIT_AUTO_NEVER', -1); 
     
    1818  function wp_smushit_register_settings() { 
    1919    add_settings_section( 'wp_smushit_settings', 'WP Smush.it', 'wp_smushit_settings_cb', 'media' ); 
    20     add_settings_field( 'wp_smushit_smushit_auto', 'Use Smush.it on upload?', 'wp_smushit_smushit_auto_cb', 'media', 'wp_smushit_settings' ); 
    21     register_setting( 'media', 'wp_smushit_smushit_auto'); 
     20    add_settings_field( 'wp_smushit_smushit_auto', 'Use Smush.it on upload?', 'wp_smushit_render_auto_opts',  'media', 'wp_smushit_settings' ); 
     21    add_settings_field( 'wp_smushit_smushit_timeout', 'How many seconds should we wait for a response from Smush.it?', 'wp_smushit_render_timeout_opts', 'media', 'wp_smushit_settings' ); 
     22    register_setting( 'media', 'wp_smushit_smushit_auto'); 
     23    register_setting( 'media', 'wp_smushit_smushit_timeout'); 
    2224  } 
    2325  add_action('admin_init', 'wp_smushit_register_settings'); 
     
    2628  } 
    2729 
    28   function wp_smushit_smushit_auto_cb() { 
    29     wp_smushit_render_auto_opts( 'wp_smushit_smushit_auto' ); 
    30   } 
    31    
    32   function wp_smushit_render_auto_opts( $key ) { 
     30  function wp_smushit_render_auto_opts() { 
     31    $key = 'wp_smushit_smushit_auto'; 
    3332    $val = intval( get_option( $key, WP_SMUSHIT_AUTO_OK ) ); 
    34     printf( "<select name='%1\$s' id='%1\$s'>",  esc_attr( $key ) ); 
    35     echo '<option value=' . WP_SMUSHIT_AUTO_OK . ' ' . selected( WP_SMUSHIT_AUTO_OK, $val ) . '>Automatically process on upload</option>'; 
    36     echo '<option value=' . WP_SMUSHIT_AUTO_NEVER . ' ' . selected( WP_SMUSHIT_AUTO_NEVER, $val ) . '>Do not process on upload</option>'; 
     33    printf( "<select name='%1\$s' id='%1\$s'>",  esc_attr( $key ) ); 
     34    echo '<option value=' . WP_SMUSHIT_AUTO_OK . ' ' . selected( WP_SMUSHIT_AUTO_OK, $val ) . '>Automatically process on upload</option>'; 
     35    echo '<option value=' . WP_SMUSHIT_AUTO_NEVER . ' ' . selected( WP_SMUSHIT_AUTO_NEVER, $val ) . '>Do not process on upload</option>'; 
    3736 
    3837    if ( $val > 0 ) { 
    39       printf( '<option value="%d" selected="selected">Temporarily disabled until %s</option>', $val, date( 'M j, Y \a\t H:i', $val ) ); 
     38      printf( '<option value="%d" selected="selected">Temporarily disabled until %s</option>', $val, date( 'M j, Y \a\t H:i', $val ) ); 
    4039    } 
    41     echo '</select>'; 
     40    echo '</select>'; 
     41  } 
     42 
     43  function wp_smushit_render_timeout_opts( $key ) { 
     44    $key = 'wp_smushit_smushit_timeout'; 
     45    $val = intval( get_option( $key, WP_SMUSHIT_AUTO_OK ) ); 
     46    printf( "<input type='text' name='%1\$s' id='%1\$s' value='%2\%d'>",  esc_attr( $key ), intval( get_option( $key, 60 ) ) ); 
    4247  } 
    4348 
  • wp-smushit/trunk/wp-smushit.php

    r682161 r682166  
    2929 
    3030define('WP_SMUSHIT_AUTO', intval(get_option('wp_smushit_smushit_auto', 0))); 
     31define('WP_SMUSHIT_TIMEOUT', intval(get_option('wp_smushit_smushit_timeout', 60))); 
    3132require( dirname(__FILE__) . '/settings.php' ); 
    3233 
     
    306307    $finished = FALSE; 
    307308    do { 
    308       $response = wp_remote_get($req, array('user-agent' => WP_SMUSHIT_UA, 'timeout' => 20)); 
     309      $response = wp_remote_get($req, array('user-agent' => WP_SMUSHIT_UA, 'timeout' => WP_SMUSHIT_TIMEOUT)); 
    309310      if ( is_wp_error( $response ) ) { 
    310311        $count++; 
Note: See TracChangeset for help on using the changeset viewer.