WordPress.org

Plugin Directory

Changeset 549334


Ignore:
Timestamp:
05/26/12 19:40:27 (2 years ago)
Author:
alexdunae
Message:

Automatically disable smushing for a period of time when an error has occurred.

Location:
wp-smushit/trunk
Files:
2 edited

Legend:

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

    r549329 r549334  
    11<?php 
    22 
     3  /* 
     4   
     5    Each service has a setting specifying whether it should be used automatically on upload. 
     6     
     7    Values are: 
     8      -1  Don't use (until manually enabled via Media > Settings) 
     9      0   Use automatically 
     10      n   Any other number is a Unix timestamp indicating when the service can be used again 
     11   
     12  */ 
     13   
     14  define('WP_SMUSHIT_AUTO_OK', 0); 
     15  define('WP_SMUSHIT_AUTO_NEVER', -1); 
     16 
     17 
    318  function wp_smushit_register_settings() { 
    4     add_settings_section( 'wp_smushit_settings', 
    5             'WP Smush.it', 
    6             'wp_smushit_settings_section_callback_function', 
    7             'media' ); 
    8  
    9         add_settings_field( 'wp_smushit_auto', 
    10             'Automatic smushing', 
    11             'wp_smushit_auto_setting_callback_function', 
    12             'media', 
    13             'wp_smushit_settings' ); 
    14  
    15     register_setting( 'media', 'wp_smushit_auto'); 
     19    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'); 
    1622  } 
    1723  add_action('admin_init', 'wp_smushit_register_settings'); 
    1824 
    19   function wp_smushit_settings_section_callback_function() { 
     25  function wp_smushit_settings_cb() { 
    2026  } 
    2127 
    22   function wp_smushit_auto_setting_callback_function() { 
    23     echo '<input name="wp_smushit_auto" id="wp_smushit_auto" type="checkbox" value="1" class="code" ' . checked( 1, get_option('wp_smushit_auto'), false ) . ' /> Automatically process images on upload?'; 
     28  function wp_smushit_smushit_auto_cb() { 
     29    wp_smushit_render_auto_opts( 'wp_smushit_smushit_auto' ); 
    2430  } 
     31   
     32  function wp_smushit_render_auto_opts( $key ) { 
     33    $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>'; 
     37 
     38    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 ) ); 
     40    } 
     41    echo '</select>'; 
     42  } 
     43 
     44  // default is 6hrs 
     45  function wp_smushit_temporarily_disable( $seconds = 21600) { 
     46    update_option( 'wp_smushit_smushit_auto', time() + $seconds ); 
     47  } 
  • wp-smushit/trunk/wp-smushit.php

    r549330 r549334  
    55Description: Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress. 
    66Author: Dialect 
    7 Version: 1.5.0 
     7Version: 1.6.0 
    88Author URI: http://dialect.ca/ 
    99*/ 
     
    1616    require_once(ABSPATH . 'wp-admin/includes/file.php'); 
    1717} 
    18  
    19  
    2018 
    2119/** 
     
    2927define('WP_SMUSHIT_PLUGIN_DIR', dirname(plugin_basename(__FILE__))); 
    3028 
    31 define('WP_SMUSHIT_AUTO', intval(get_option('wp_smushit_auto', 1))); 
     29define('WP_SMUSHIT_AUTO', intval(get_option('wp_smushit_smushit_auto', 0))); 
    3230require( dirname(__FILE__) . '/settings.php' ); 
    3331 
     
    3634 */ 
    3735 
    38 if (WP_SMUSHIT_AUTO !== 0) { 
     36if (WP_SMUSHIT_AUTO == WP_SMUSHIT_AUTO_OK) { 
    3937  add_filter('wp_generate_attachment_metadata', 'wp_smushit_resize_from_meta_data', 10, 2); 
    4038} 
     
    5654} 
    5755add_action( 'admin_menu', 'wp_smushit_admin_menu' ); 
    58  
    59  
    6056 
    6157 
     
    299295 
    300296        if( is_wp_error( $response ) ) { 
    301             wp_die( $response ); 
     297          wp_smushit_temporarily_disable(); 
     298          $msg = 'Automatic smushing has been disabled temporarily due to an error. ' . $response->get_error_message(); 
     299            wp_die( $msg ); 
    302300        } 
    303301 
Note: See TracChangeset for help on using the changeset viewer.