@@ -74,6 +74,13 @@ class Optml_Attachment_Model {
74
74
*/
75
75
private $ is_remote_attachment ;
76
76
77
+ /**
78
+ * The attachment mime type.
79
+ *
80
+ * @var string
81
+ */
82
+ private $ mime_type ;
83
+
77
84
/**
78
85
* The attachment metadata.
79
86
*
@@ -91,11 +98,9 @@ class Optml_Attachment_Model {
91
98
public function __construct ( int $ attachment_id ) {
92
99
$ this ->attachment_id = $ attachment_id ;
93
100
$ this ->attachment_metadata = wp_get_attachment_metadata ( $ this ->attachment_id );
101
+ $ this ->mime_type = get_post_mime_type ( $ attachment_id );
94
102
95
- $ mime_type = get_post_mime_type ( $ attachment_id );
96
- $ is_image = strpos ( $ mime_type , 'image ' ) !== false ;
97
-
98
- $ this ->main_attachment_url = $ is_image ? wp_get_original_image_url ( $ attachment_id ) : wp_get_attachment_url ( $ attachment_id );
103
+ $ this ->main_attachment_url = $ this ->is_image () ? wp_get_original_image_url ( $ attachment_id ) : wp_get_attachment_url ( $ attachment_id );
99
104
$ this ->origianal_attached_file_path = $ this ->setup_original_attached_file ();
100
105
$ this ->dir_path = dirname ( $ this ->origianal_attached_file_path );
101
106
$ this ->is_scaled = isset ( $ this ->attachment_metadata ['original_image ' ] );
@@ -286,4 +291,18 @@ public function get_metadata_prefix_path() {
286
291
public function can_be_renamed_or_replaced () {
287
292
return ! $ this ->is_remote_attachment ;
288
293
}
294
+
295
+ /**
296
+ * Get the attachment mime type.
297
+ */
298
+ public function get_attachment_mimetype () {
299
+ return $ this ->mime_type ;
300
+ }
301
+
302
+ /**
303
+ * Check if the attachment is an image.
304
+ */
305
+ public function is_image () {
306
+ return strpos ( $ this ->mime_type , 'image ' ) !== false ;
307
+ }
289
308
}
0 commit comments