WordPress.org

Plugin Directory

Changeset 682179


Ignore:
Timestamp:
03/15/13 07:08:28 (13 months ago)
Author:
alexdunae
Message:

Better check for repetitive errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-smushit/trunk/wp-smushit.php

    r682170 r682179  
    2727define('WP_SMUSHIT_PLUGIN_DIR', dirname(plugin_basename(__FILE__))); 
    2828define('WP_SMUSHIT_MAX_BYTES', 1048576); 
     29 
     30// The number of images (including generated sizes) that can return errors before abandoning all hope. 
     31// N.B. this doesn't work with the bulk uploader, since it creates a new HTTP request 
     32// for each image.  It does work with the bulk smusher, though. 
     33define('WP_SMUSHIT_ERRORS_BEFORE_QUITTING', 3 * count(get_intermediate_image_sizes())); 
    2934 
    3035define('WP_SMUSHIT_AUTO', intval(get_option('wp_smushit_smushit_auto', 0))); 
     
    133138    // $file_path = realpath($file); 
    134139 
     140  static $error_count = 0; 
     141 
     142  if ( $error_count >= WP_SMUSHIT_ERRORS_BEFORE_QUITTING ) { 
     143    $msg = __("Did not smush due to previous errors", WP_SMUSHIT_DOMAIN); 
     144    return array($file, $msg); 
     145  } 
     146 
    135147    $file_path = $file; 
    136148    // check that the file exists 
     
    169181    $data = wp_smushit_post($file_url); 
    170182 
    171     if ( FALSE === $data ) 
     183    if ( FALSE === $data ) { 
     184    $error_count++; 
    172185        return array($file, __('Error posting to Smush.it', WP_SMUSHIT_DOMAIN)); 
     186  } 
    173187 
    174188    // make sure the response looks like JSON -- added 2008-12-19 when 
     
    304318 
    305319    if ( function_exists('wp_remote_get') ) { 
    306     $count = 0; 
    307     $finished = FALSE; 
    308     do { 
    309       $response = wp_remote_get($req, array('user-agent' => WP_SMUSHIT_UA, 'timeout' => WP_SMUSHIT_TIMEOUT)); 
    310       if ( is_wp_error( $response ) ) { 
    311         $count++; 
    312       } else { 
    313         $finished = TRUE; 
    314       } 
    315       if ($count == 3) { 
    316         //$msg = 'Automatic smushing has been disabled temporarily due to an error. ' . $response->get_error_message() .' - url | '. $file_url; 
    317         //wp_die( $msg ); 
    318         $response = FALSE; 
    319         $finished = TRUE; 
    320       } 
    321     } while (!$finished); 
    322  
    323     if ( !$response ) { 
     320    $response = wp_remote_get($req, array('user-agent' => WP_SMUSHIT_UA, 'timeout' => WP_SMUSHIT_TIMEOUT)); 
     321    if ( !$response || is_wp_error($response)) { 
    324322      $data = FALSE; 
    325323    } else { 
     
    329327        wp_die( __('WP Smush.it requires WordPress 2.8 or greater', WP_SMUSHIT_DOMAIN) ); 
    330328    } 
     329 
     330  $data = FALSE; 
    331331 
    332332    return $data; 
Note: See TracChangeset for help on using the changeset viewer.