a['total_images'] += ! empty( $meta['sizes'] ) ? count( $meta['sizes'] ) : 0; $smush_data['size_before'] += ! empty( $meta['stats']['size_before'] ) ? (int) $meta['stats']['size_before'] : 0; $smush_data['size_after'] += ! empty( $meta['stats']['size_after'] ) ? (int) $meta['stats']['size_after'] : 0; } } } } $smush_data['bytes'] = $smush_data['size_before'] - $smush_data['size_after']; // Update the offset. $offset += $this->query_limit; // Compare the Offset value to total images. if ( ! empty( $this->total_count ) && $this->total_count <= $offset ) { $query_next = false; } } // Add directory smush image bytes. if ( ! empty( $this->dir_stats['bytes'] ) && $this->dir_stats['bytes'] > 0 ) { $smush_data['bytes'] += $this->dir_stats['bytes']; } // Add directory smush image total size. if ( ! empty( $this->dir_stats['orig_size'] ) && $this->dir_stats['orig_size'] > 0 ) { $smush_data['size_before'] += $this->dir_stats['orig_size']; } // Add directory smush saved size. if ( ! empty( $this->dir_stats['image_size'] ) && $this->dir_stats['image_size'] > 0 ) { $smush_data['size_after'] += $this->dir_stats['image_size']; } // Add directory smushed images. if ( ! empty( $this->dir_stats['optimised'] ) && $this->dir_stats['optimised'] > 0 ) { $smush_data['total_images'] += $this->dir_stats['optimised']; } // Resize Savings. $smush_data['resize_count'] = $this->get_savings( 'resize', false, false, true ); $resize_savings = $this->get_savings( 'resize', false ); $smush_data['resize_savings'] = ! empty( $resize_savings['bytes'] ) ? $resize_savings['bytes'] : 0; // Conversion Savings. $conversion_savings = $this->get_savings( 'pngjpg', false ); $smush_data['conversion_savings'] = ! empty( $conversion_savings['bytes'] ) ? $conversion_savings['bytes'] : 0; if ( ! isset( $smush_data['bytes'] ) || $smush_data['bytes'] < 0 ) { $smush_data['bytes'] = 0; } // Add the resize savings to bytes. $smush_data['bytes'] += $smush_data['resize_savings']; $smush_data['size_before'] += $resize_savings['size_before']; $smush_data['size_after'] += $resize_savings['size_after']; // Add Conversion Savings. $smush_data['bytes'] += $smush_data['conversion_savings']; $smush_data['size_before'] += $conversion_savings['size_before']; $smush_data['size_after'] += $conversion_savings['size_after']; if ( $smush_data['size_before'] > 0 ) { $smush_data['percent'] = ( $smush_data['bytes'] / $smush_data['size_before'] ) * 100; } // Round off precentage. $smush_data['percent'] = round( $smush_data['percent'], 1 ); $smush_data['human'] = size_format( $smush_data['bytes'], 1 ); // Setup Smushed attachment IDs. $this->smushed_attachments = ! empty( $smush_data['id'] ) ? $smush_data['id'] : ''; // Super Smushed attachment count. $this->super_smushed = $supersmushed; // Remove ids from stats. unset( $smush_data['id'] ); // Update cache. update_option( 'smush_global_stats', $smush_data, false ); return $smush_data; } /** * Returns remaining count * * @return int */ private function remaining_count() { $resmush_count = count( $this->resmush_ids ); $remaining_count = $this->total_count - $this->smushed_count - $this->skipped_count; // Just a failsafe - can't have remaining value be a negative value. $remaining_count = $remaining_count > 0 ? $remaining_count : 0; // Check if the resmush count is equal to remaining count. if ( $resmush_count > 0 && ( $resmush_count !== $this->smushed_count || 0 === absint( $remaining_count ) ) ) { return $resmush_count + $remaining_count; } return $remaining_count; } /** * Return the number of skipped attachments. * * @since 3.0 * * @param bool $force Force data refresh. * * @return array */ private function skipped_count( $force ) { $images = wp_cache_get( 'skipped_images', 'wp-smush' ); if ( ! $force && $images ) { return $images; } global $wpdb; $images = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='wp-smush-ignore-bulk'" ); // Db call ok. wp_cache_set( 'skipped_images', $images, 'wp-smush' ); return $images; } }