Plugin Directory

Changeset 3407383


Ignore:
Timestamp:
12/01/2025 11:55:47 PM (4 months ago)
Author:
kubiq
Message:

4.5

  • tested on WP 6.9
  • performance optimization - load DB tables only when needed
  • sorting by filesize in convert screen
Location:
png-to-jpg/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • png-to-jpg/trunk/png-to-jpg.php

    r3059378 r3407383  
    44    Plugin URI: https://wp-speedup.eu
    55    Description: Convert PNG images to JPG, free up web space and speed up your webpage
    6     Version: 4.4
     6    Version: 4.5
    77    Author: KubiQ
    88    Author URI: https://www.paypal.me/jakubnovaksl
     
    1111*/
    1212
    13 /*
    14 ** TODO
    15 ** - restore PNG version?
    16 */
    17 
    1813class png_to_jpg{
    1914    var $plugin_admin_page;
    2015    var $settings;
    21     var $db_tables;
    2216    var $tab;
    2317    var $image;
     
    4034        add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
    4135        add_filter( 'wp_loaded', array( $this, 'convert_png_from_media_library' ), 10, 2 );
     36
     37        add_filter( 'posts_clauses', function( $clauses, $query ){
     38            global $wpdb;
     39            if( is_admin() ){
     40                $direction = $query->get('sort_filesize');
     41                if( in_array( $direction, [ 'asc', 'desc' ] ) ){
     42                    $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS mt_filesize ON {$wpdb->posts}.ID = mt_filesize.post_id AND mt_filesize.meta_key = '_wp_attachment_metadata' ";
     43                    $clauses['orderby'] = "CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(mt_filesize.meta_value, 's:8:\"filesize\";i:', -1), ';', 1) AS UNSIGNED) " . strtoupper( $direction );
     44                }
     45            }
     46            return $clauses;
     47        }, 10, 2 );
    4248    }
    4349
     
    190196        global $wpdb;
    191197        $this->settings = get_option('png_to_jpg_settings');
    192         $this->db_tables = $wpdb->get_col('SHOW TABLES');
    193198    }
    194199
     
    348353        wp_enqueue_media();
    349354        $paged = isset( $_GET['paged'] ) && intval( $_GET['paged'] ) ? intval( $_GET['paged'] ) : 1;
    350         $query_images = new WP_Query(array(
     355        $args = [
    351356            'post_type' => 'attachment',
    352357            'post_mime_type' => 'image/png',
     
    354359            'posts_per_page' => $this->settings['general']['images_per_page'],
    355360            'paged' => $paged,
    356         )); ?>
     361        ];
     362        if( ! empty( $_GET['order'] ) ){
     363            $args['sort_filesize'] = $_GET['order'] == 'asc' ? 'asc' : 'desc';
     364        }
     365        $query_images = new WP_Query( $args ); ?>
    357366        <div class="below-h2 error"><p><strong><?php _e( 'Do you have BACKUP? This operation will alter your original images and cannot be undone!', 'png_to_jpg' ) ?></strong></p></div>
    358367        <div class="below-h2 error">
     
    395404                <tr>
    396405                    <th class="check-column"><input type="checkbox"></th>
     406
    397407                    <th><?php _e('Media') ?></th>
    398                     <th><?php _e( 'Filesize', 'png_to_jpg' ) ?></th>
     408
     409
     410                    <th scope="col" id="filesize" class="manage-column column-filesize column-primary <?php echo empty( $_GET['order'] ) ? 'sortable' : ( $_GET['order'] == 'asc' ? 'sorted asc' : 'sorted desc' ) ?>" abbr="Filesize">
     411                        <a href="?page=<?php echo basename( __FILE__ ) ?>&amp;tab=convert&amp;order=<?php echo empty( $_GET['order'] ) || $_GET['order'] == 'asc' ? 'desc' : 'asc' ?>">
     412                            <span><?php _e( 'Filesize', 'png_to_jpg' ) ?></span>
     413                            <span class="sorting-indicators">
     414                                <span class="sorting-indicator asc" aria-hidden="true"></span>
     415                                <span class="sorting-indicator desc" aria-hidden="true"></span>
     416                            </span>
     417                        </a>
     418                    </th>
     419
    399420                    <?php if( isset( $this->settings['general']['autodetect'] ) ): ?>
    400421                        <th><?php _e( 'Has transparency', 'png_to_jpg' ) ?></th>
     
    829850        global $wpdb;
    830851
     852        $db_tables = $wpdb->get_col('SHOW TABLES');
     853
    831854        $old_name = basename( $this->image['link'] );
    832855        $old_name_clean = substr( $old_name, 0, -4 );
     
    896919            // Yoast SEO: wp_yoast_seo_links
    897920            $table_name = $wpdb->prefix.'yoast_seo_links';
    898             if( in_array( $table_name, $this->db_tables ) ){
     921            if( in_array( $table_name, $db_tables ) ){
    899922                $wpdb->query("
    900923                    UPDATE $table_name
     
    905928            // Revolution Slider: wp_revslider_slides
    906929            $table_name = $wpdb->prefix.'revslider_slides';
    907             if( in_array( $table_name, $this->db_tables ) ){
     930            if( in_array( $table_name, $db_tables ) ){
    908931                $wpdb->query("
    909932                    UPDATE $table_name
     
    919942            // Revolution Slider: wp_revslider_static_slides
    920943            $table_name = $wpdb->prefix.'revslider_static_slides';
    921             if( in_array( $table_name, $this->db_tables ) ){
     944            if( in_array( $table_name, $db_tables ) ){
    922945                $wpdb->query("
    923946                    UPDATE $table_name
     
    928951            // Toolset Types: wp_toolset_post_guid_id
    929952            $table_name = $wpdb->prefix.'toolset_post_guid_id';
    930             if( in_array( $table_name, $this->db_tables ) ){
     953            if( in_array( $table_name, $db_tables ) ){
    931954                $wpdb->query("
    932955                    UPDATE $table_name
     
    937960            // Fancy Product Designer: wp_fpd_products
    938961            $table_name = $wpdb->prefix.'fpd_products';
    939             if( in_array( $table_name, $this->db_tables ) ){
     962            if( in_array( $table_name, $db_tables ) ){
    940963                $wpdb->query("
    941964                    UPDATE $table_name
     
    946969            // Fancy Product Designer: wp_fpd_views
    947970            $table_name = $wpdb->prefix.'fpd_views';
    948             if( in_array( $table_name, $this->db_tables ) ){
     971            if( in_array( $table_name, $db_tables ) ){
    949972                $wpdb->query("
    950973                    UPDATE $table_name
     
    960983            // Broken Link Checker: wp_blc_instances
    961984            $table_name = $wpdb->prefix.'blc_instances';
    962             if( in_array( $table_name, $this->db_tables ) ){
     985            if( in_array( $table_name, $db_tables ) ){
    963986                $wpdb->query("
    964987                    UPDATE $table_name
     
    974997            // Broken Link Checker: wp_blc_links
    975998            $table_name = $wpdb->prefix.'blc_links';
    976             if( in_array( $table_name, $this->db_tables ) ){
     999            if( in_array( $table_name, $db_tables ) ){
    9771000                $wpdb->query("
    9781001                    UPDATE $table_name
     
    9981021            // FV Player
    9991022            $table_name = $wpdb->prefix.'fv_player_videos';
    1000             if( in_array( $table_name, $this->db_tables ) ){
     1023            if( in_array( $table_name, $db_tables ) ){
    10011024                $wpdb->query("
    10021025                    UPDATE $table_name
  • png-to-jpg/trunk/readme.txt

    r3059378 r3407383  
    22Contributors: kubiq
    33Donate link: https://www.paypal.me/jakubnovaksl
    4 Tags: png, jpg, optimize, save space, convert, image, media
     4Tags: optimize, save space, convert, image, media
    55Requires at least: 3.0.1
    6 Tested up to: 6.5
    7 Stable tag: 4.4
     6Tested up to: 6.9
     7Stable tag: 4.5
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3232
    3333== Changelog ==
     34
     35= 4.5 =
     36* tested on WP 6.9
     37* performance optimization - load DB tables only when needed
     38* sorting by filesize in convert screen
    3439
    3540= 4.4 =
Note: See TracChangeset for help on using the changeset viewer.