PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.4.5
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.4.5
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / functions / attachments.php

attachments.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.4.5, at inc/functions/attachments.php

94 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
3
4 /*
5 * Get all mime type which could be optimized by Imagify.
6 *
7 * @since 1.3
8 *
9 * @return array $mime_type The mime type.
10 */
11 function get_imagify_mime_type() {
12 $mime_type = array(
13 'image/jpeg',
14 'image/png',
15 'image/gif'
16 );
17
18 return $mime_type;
19 }
20
21 /*
22 * Get the backup path of a specific attachement.
23 *
24 * @since 1.0
25 *
26 * @param int $file_path The attachment path.
27 * @return string $backup_path The backup path.
28 */
29 function get_imagify_attachment_backup_path( $file_path ) {
30 $upload_dir = wp_upload_dir();
31 $upload_basedir = trailingslashit( $upload_dir['basedir'] );
32 $backup_dir = $upload_basedir . 'backup/';
33
34 /**
35 * Filter the backup directory path
36 *
37 * @since 1.0
38 *
39 * @param string $backup_dir The backup directory path
40 */
41 $backup_dir = apply_filters( 'imagify_backup_directory', $backup_dir );
42 $backup_dir = trailingslashit( $backup_dir );
43
44 $backup_path = str_replace( $upload_basedir, $backup_dir, $file_path );
45 return $backup_path;
46 }
47
48 /*
49 * Retrieve file path for an attachment based on filename.
50 *
51 * @since 1.4.5
52 *
53 * @param int $filename The filename.
54 * @return string|false $file_path The file path to where the attached file should be, false otherwise.
55 */
56 function get_imagify_attached_file( $filename ) {
57 $file_path = false;
58
59 // If the file is relative, prepend upload dir.
60 if ( $filename && 0 !== strpos( $filename, '/' ) && ! preg_match( '|^.:\\\|', $filename ) && ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) {
61 $file_path = $uploads['basedir'] . "/$filename";
62 }
63
64 return $file_path;
65 }
66
67 /*
68 * Retrieve the URL for an attachment based on filename.
69 *
70 * @since 1.4.5
71 *
72 * @param int $filename The filename.
73 * @return string|false $url Attachment URL, otherwise false.
74 */
75 function get_imagify_attachment_url( $filename ) {
76 $url = '';
77
78 // Get upload directory.
79 if ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) {
80 // Check that the upload base exists in the file location.
81 if ( 0 === strpos( $filename, $uploads['basedir'] ) ) {
82 // Replace file location with url location.
83 $url = str_replace( $uploads['basedir'], $uploads['baseurl'], $filename );
84 } elseif ( false !== strpos( $filename, 'wp-content/uploads' ) ) {
85 // Get the directory name relative to the basedir (back compat for pre-2.7 uploads)
86 $url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $filename ) ) . basename( $filename );
87 } else {
88 // It's a newly-uploaded file, therefore $file is relative to the basedir.
89 $url = $uploads['baseurl'] . "/$filename";
90 }
91 }
92
93 return $url;
94 }