Plugin Directory

Changeset 736889

Timestamp:
07/05/2013 10:50:34 PM (11 years ago)
Author:
mbijon
Message:

Update RIQ to v2.0: Adds main UX to Settings > Media, note to custom Admin page about future deprecation/UX-removal

Location:
wp-resized-image-quality/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • wp-resized-image-quality/trunk/readme.txt

    r672492 r736889  
    1 === WP Resized Image Quality Plugin ===
     1=== WP Resized Image Quality ===
    22Contributors: mbijon
    33Tags: image, thumbnail, compression, quality, YSlow, PageSpeed, bandwidth, jpeg, jpg, size, file, storage, uploader, uploaded, imagemagick, gd library
    44Requires at least: 2.7
    5 Tested up to: 3.5.1
    6 Stable tag: 1.0.3
     5Tested up to: 3.6-beta4
     6Stable tag: 2.0
     7
     8Get better uploaded quality or save bandwidth: Change the JPEG compression-level of uploaded images and thumbnails.
    79
    810== Description ==
     
    1012Get better uploaded quality or save bandwidth: Change the JPEG compression-level of uploaded images and thumbnails.
    1113
    12 The WP Resized Image Quality plugin lets you change the compression-level of uploaded images and thumbnails. Set it for maximum quality when you want images to look their best, or take advantage of lower quality settings to save bandwidth.
     14The WP Resized Image Quality plugin lets you change the compression-level of uploaded images and thumbnails. Set it for maximum quality when you want images to look their best, or take advantage of lower quality settings to save bandwidth.
    1315
    1416The admin page uses an easy slider to set the compression level, making this easier to use than other compression plugins or functions.php settings.
     
    2729== Frequently Asked Questions ==
    2830
     31
     32
     33
     34
    2935= What was the default image quality in WordPress? =
    3036
    31 The default image quality is 90%.
     37The default image is 90%.
    3238
    3339= What happens to uploaded images if I turn the plugin off? =
    3440
    35 After you deactivate the plugin all new images will use the default 90% compression setting. Images uploaded while the plugin was active will stay at their old compression level.
     41After you deactivate the custom compression setting will be removed and all new images will use WP's default 90% compression setting. Images uploaded while the plugin was active will stay at their old compression level.
     42
     43= Does this plugin compress PNG files? =
     44
     45Unfortunately, it doesn't. All the PNG compression tools I've found aren't standard on most servers. You would need root access and a more-complicated plugin to get PNG compression working.
    3646
    3747== Screenshots ==
    3848
    39 1. Admin page with one setting, simple enough
     491. No complicated media/compression interface. Just one slider added to the Settings > Admin page
     502. Admin page with one setting, simple enough
    4051
    4152== Changelog ==
    4253
     54
     55
     56
     57
    4358= 1.0.3 =
    44 * Fix WP.org screenshot display
     59* Fix WP.org screenshot display
    4560
    4661= 1.0.1 =
  • wp-resized-image-quality/trunk/templates/riq-admin-page-template.php

    r672048 r736889  
    1414<div class="wrap">
    1515        <form method="post">
    16                 <?php if ( function_exists('screen_icon') ) screen_icon(); ?>
    17                 <h2><?php _e( 'Image Quality', 'wp-resized-image-quality' ); ?></h2>
    18                 <table class="form-table">
    19                         <tr>
    20                                 <th>
    21                     <?php _e( 'JPEG Quality %', 'wp-resized-image-quality' ); ?>
    22                 </th>
    23                 <td>
    24                     <div>
    25                         <input type="text" class="riq-amount" id="riq-amount" style="border: 0; font-weight: bold;" />
     16            <?php if ( function_exists('screen_icon') ) screen_icon(); ?>
     17            <h2><?php _e( 'Image Quality', 'wp-resized-image-quality' ); ?></h2>
     18           
     19            <table class="form-table">
     20                <tr>
     21                    <td colspan="2">
     22                        <?php $sm_url = admin_url( 'options-media.php' ); ?>
     23                        <h3>Plugin Version 2.0, Update Note:</h3>
     24                        <p>The slider below was added to the <a href="<?php echo $sm_url; ?>">Settings &gt; Media page</a> in version 2.0.
    2625                        <br />
    27                         <?php _e( 'The default compression setting in WordPress is 90%', 'wp-resized-image-quality' ); ?>
    28                     </div>
    29                 </td>
    30                         </tr>
    31             <tr>
    32                 <td colspan="2">
    33                                         <div class="riq-slider" id="riq-slider" style="width:400px;"></div>
    34                     <input type="hidden" name="riq-integer" id="riq-integer" value="<?php echo $this->jpeg_quality; ?>" />
    35                 </td>
    36                         </tr>
    37                 </table>
     26                        In version 3.0 this screen will be removed and the slider will only be on the <a href="<?php echo $sm_url; ?>">Settings &gt; Media page</a>.</p>
     27                    </td>
     28                </tr>
     29                <tr>
     30                    <th>
     31                        <strong><?php _e( 'JPEG Quality %', 'wp-resized-image-quality' ); ?></strong>
     32                    </th>
     33                    <td>
     34                        <div>
     35                            <input type="text" class="riq-amount" id="riq-amount" style="border: 0; font-weight: bold;" />
     36                            <br />
     37                            <?php _e( 'The default compression setting in WordPress is 90%', 'wp-resized-image-quality' ); ?>
     38                        </div>
     39                    </td>
     40                </tr>
     41                <tr>
     42                    <td colspan="2">
     43                        <div class="riq-slider" id="riq-slider" style="width:400px;"></div>
     44                        <input type="hidden" name="riq-integer" id="riq-integer" value="<?php echo $this->jpeg_quality; ?>" />
     45                    </td>
     46                </tr>
     47            </table>
    3848        <p class="submit">
    3949            <input type="submit" name="riq-submit" id="riq-submit" class="button button-primary" value="Save Changes">
    4050            <input type="submit" name="riq-defaults" id="riq-defaults" class="button button-primary" value="Reset to Default">
    4151        </p>
     52
    4253        <?php
    4354            // Add WordPress nonce for security
  • wp-resized-image-quality/trunk/wp-resized-image-quality.php

    r672492 r736889  
    44Plugin URI: http://www.geekcoded.com/plugin/wp-resized-image-quality/
    55Description: Change the compression-level of uploaded images and thumbnails. Get better image quality or save bandwidth.
    6 Version: 1.0.3
     6Version:
    77Author: Mike Bijon, GeekCoded
    88Author URI: http://www.mbijon.com/about-mike-bijon/
     
    4848   
    4949    /**
    50      * Vesrion # of WP-Resized-Image-Quality
    51      */
    52     const RIQ_PLUGIN_VERSION = '1.0';
     50     * Veion # of WP-Resized-Image-Quality
     51     */
     52    const RIQ_PLUGIN_VERSION = '.0';
    5353   
    5454   
     
    5757     */
    5858    public function __construct() {
     59
    5960        add_action( 'init', array( $this, 'wp_init' ) );
    6061        add_action( 'admin_menu', array( $this, 'admin_page_menu' ) );
    6162        add_action( 'admin_enqueue_scripts', array( $this, 'admin_page_statics' ) );
     63
     64
     65
     66
    6267    }
    6368
     
    6671     */
    6772    public function wp_init() {
     73
    6874        // Setup data/array once
    6975        if ( ! is_array( $this->riq_options ) && false === ( get_transient( 'riq_jpeg_quality' ) ) )
     
    8288            plugins_url( 'js/riq-admin.js', __FILE__ ),
    8389            array( 'jquery', 'jquery-ui-slider' ),
    84             'riq_' . self::RIQ_PLUGIN_VERSION, //microtime(),
     90            'riq_' . self::RIQ_PLUGIN_VERSION,
    8591            true
    8692        );
     
    9298            'all'
    9399        );
    94     }
     100       
     101    }
     102   
    95103   
    96104    // Add submenu under Settings in WP-Admin       
    97105    public function admin_page_menu() {
     106
    98107        $options_page = add_options_page(
    99                     'Image Quality',
    100                     'Image Quality',
    101                     'manage_options',
    102                     'riq-admin',
    103                     array( $this, 'render_options_page' )
    104                 );
     108            'Image Quality',
     109            'Image Quality',
     110            'manage_options',
     111            'riq-admin',
     112            array( $this, 'render_options_page' )
     113        );
    105114       
    106115        // Add contextual help menu in WP-admin
    107116        //add_action("load-$admin_page", 'add_help_menu');
     117
    108118    }
    109119   
    110120    // For admin-only scripts
    111     public function admin_page_statics() {
    112         if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'riq-admin' ) {
     121    public function admin_page_statics( $hook ) {
     122       
     123        if ( $hook == 'options-media.php' || $hook == 'settings_page_riq-admin' ) {
    113124            // JS
    114125            wp_enqueue_script( 'jquery-ui-slider' );
     
    117128            // CSS
    118129            wp_enqueue_style( 'riq-jquery-ui' );
    119         }
    120     }
     130           
     131        }
     132       
     133    }
     134   
    121135   
    122136    // HTML output for WP-Admin: Settings > Image Quality
    123137    public function render_options_page() {
     138
    124139        // Security: Check that the user has the required capability
    125140        if ( ! current_user_can( 'manage_options' ) )
     
    135150        } elseif ( ! empty( $_POST['riq-integer'] ) ) {
    136151            wp_die( __( 'Invalid: Update without permissions. Please check your login and try again.', 'wp-resized-image-quality' ) );
     152
    137153        }
    138154       
     
    147163           
    148164            set_transient( 'riq_jpeg_quality', $jpeg_quality, 60 * 60 * 24 );
    149         }
     165           
     166        }
     167       
    150168        $this->jpeg_quality = $this->get_jpeg_quality_setting();
    151169       
    152170        // Include admin page/HTML output from separate file
    153         require_once( 'templates/riq-admin-page-template.php' );
    154     }
     171        require_once( dirname( __file__ ) . '/templates/riq-admin-page-template.php' );
     172    }
     173   
     174   
     175    // Register options for use in WP-Admin existing page: Settings > Media
     176    public function register_riq_media_option() {
     177       
     178        register_setting( 'media', 'riq_options', array( $this, 'sanitize_riq_media_option' ) );
     179       
     180        add_settings_field( 'riq-integer', 'JPEG Quality', array( $this, 'render_riq_media_option' ), 'media', 'default' );
     181       
     182    }
     183   
     184   
     185    // HTML output for simplified option in WP-Admin: Settings > Media
     186    public function render_riq_media_option() {
     187       
     188        // Get the whole reason this plugin exists
     189        if ( false === ( $jpeg_quality = get_transient( 'riq_jpeg_quality' ) ) ) {
     190            $this->riq_options = get_option( 'riq_options' );
     191           
     192            if ( array_key_exists( 'jpeg_quality', $this->riq_options ) )
     193                $jpeg_quality = $this->riq_options['jpeg_quality'];
     194            else
     195                $jpeg_quality = (int)90;
     196           
     197            set_transient( 'riq_jpeg_quality', $jpeg_quality, 60 * 60 * 24 );
     198           
     199        }
     200       
     201        $this->jpeg_quality = $this->get_jpeg_quality_setting();
     202       
     203        // Include admin page/HTML output from separate file
     204        require_once( dirname( __file__ ) . '/templates/riq-media-option-template.php' );
     205       
     206    }
     207   
     208   
     209    // Sanitization helper function for 'render_riq_media_option()'
     210    public function sanitize_riq_media_option( $riq_options ) {
     211       
     212        if ( ! empty( $_POST['riq-integer'] ) ) {
     213           
     214            $valid = array();
     215            $valid['jpeg_quality'] = intval( $_POST['riq-integer'] );
     216           
     217            // !!! Must delete transient, because WP's built-in save routine won't
     218            delete_transient( 'riq_jpeg_quality' );
     219           
     220            return $valid;
     221           
     222        } else {
     223           
     224            add_settings_error(
     225                'JPEG Quality',
     226                'riq_numeric_error',
     227                //'Invalid %, must be a number',
     228                print_r($riq_options),
     229                //$riq_options,
     230                'error'
     231            );
     232       
     233        }
     234       
     235    }
     236   
    155237   
    156238    // The whole reason this plugin exists
    157239    public function get_jpeg_quality_setting() {
     240
    158241        if ( false === ( $jpeg_quality = get_transient( 'riq_jpeg_quality' ) ) ) {
    159242            $this->riq_options = get_option( 'riq_options' );
     
    170253    }
    171254   
     255
     256
    172257    public function update_plugin_settings( $jpeg_quality = 90 ) {
     258
    173259        $this->riq_options['jpeg_quality'] = intval( $jpeg_quality );
    174260        update_option( 'riq_options', $this->riq_options );
     
    180266    }
    181267   
     268
    182269    // Contextual help menu
    183270    public function add_help_menu() {
     
    185272    }
    186273   
    187     /**
    188      * Deletes all plugin options
     274   
     275    /**
     276     * Deletes all plugin options & transient
    189277     */
    190278    public function plugin_deactivation( $network_wide ) {
     279
    191280        delete_option( 'riq_options' );
    192     }
     281        delete_transient( 'riq_jpeg_quality' );
     282       
     283    }
     284   
    193285}
    194286$riq = new WP_Resized_Image_Quality();
Note: See TracChangeset for help on using the changeset viewer.