PluginProbe ʕ •ᴥ•ʔ
Smush – Image Optimization, Compression, Lazy Load, WebP & CDN / 3.14.1
Smush – Image Optimization, Compression, Lazy Load, WebP & CDN v3.14.1
4.1.2 4.1.1 4.1.0 4.0.3 4.0.2 2.8.1 2.9.1 3.0.0 3.0.1 3.0.2 3.1.1 3.10.1 3.10.2 3.10.3 3.11.1 3.12.3 3.12.4 3.12.5 3.12.6 3.13.0 3.13.1 3.13.2 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.2 3.16.4 3.16.5 3.16.6 3.17.0 3.17.1 3.18.0 3.18.1 3.2.0.1 3.2.1 3.2.2.1 3.2.4 3.20.0 3.21.1 3.22.1 3.22.3 3.23.0 3.23.1 3.23.2 3.23.3 3.23.4 3.24.0 3.24.0-beta.2 3.3.0 3.3.1 3.3.2 3.4.1 3.4.2 3.6.1 3.6.3 3.7.0 3.7.1 3.7.2 3.7.3 3.8.2 3.8.3 3.8.4 3.8.5 3.8.7 3.8.8 3.9.0 3.9.1 3.9.11 3.9.2 3.9.4 3.9.5 3.9.8 3.9.9 trunk 1.0.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.2 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.5.1 1.6.5.2 1.6.5.3 1.6.5.4 1.7 1.7.1 1.7.1.1 2.0 2.0.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.6.2 2.0.6.3 2.0.6.5 2.0.7 2.0.7.1 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.2 2.3 2.3.1 2.4 2.4.2 2.4.3 2.4.4 2.4.5 2.5.2 2.5.3 2.6.1 2.6.2 2.6.3 2.7 2.7.1 2.7.4 2.7.4.1 2.7.5 2.7.6 2.7.8 2.7.8.1 2.7.9.1 2.8.0 2.8.0.1
wp-smushit / core / s3 / class-s3-media-item-size.php
wp-smushit / core / s3 Last commit date
class-s3-controller.php 2 years ago class-s3-media-item-size.php 2 years ago class-wp-offload-media-api.php 2 years ago
class-s3-media-item-size.php
54 lines
1 <?php
2
3 namespace Smush\Core\S3;
4
5 use Smush\Core\File_System;
6 use Smush\Core\Media\Media_Item_Size;
7
8 class S3_Media_Item_Size extends Media_Item_Size {
9 private $file_size;
10 /**
11 * @var File_System
12 */
13 private $fs;
14
15 public function __construct( $key, $attachment_id, $dir, $base_url, $wp_size_metadata ) {
16 parent::__construct( $key, $attachment_id, $dir, $base_url, $wp_size_metadata );
17
18 $this->fs = new File_System();
19 }
20
21 /**
22 * The media item always uses local paths, which is fine for most cases because we download the files for our operations.
23 * But to cover any edge cases, this method returns the remote path (filtered by WP offload media). The remote path supports read operations like filesize() and file_exists()
24 */
25 public function get_file_path() {
26 $local_file_path = parent::get_file_path();
27 if ( $this->fs->file_exists( $local_file_path ) ) {
28 return $local_file_path;
29 }
30
31 $size_file_name = $this->get_file_name();
32 $attached_file = get_attached_file( $this->get_attachment_id() );
33 $attached_file_name = wp_basename( $attached_file );
34 $maybe_remote_path = str_replace( $attached_file_name, $size_file_name, $attached_file );
35
36 return $this->fs->file_exists( $maybe_remote_path )
37 ? $maybe_remote_path
38 : $local_file_path;
39 }
40
41 /**
42 * Because for some reason WP Offload media removes the size {@see \DeliciousBrains\WP_Offload_Media\Items\Media_Library_Item::update_filesize_after_download_local}
43 *
44 * @return int
45 */
46 public function get_filesize() {
47 if ( is_null( $this->file_size ) || $this->file_size === 0 ) {
48 $this->file_size = $this->fs->filesize( $this->get_file_path() );
49 }
50
51 return $this->file_size;
52 }
53 }
54