@@ -270,26 +270,72 @@ public function getSizes()
270
270
return $ sizes ;
271
271
}
272
272
273
- public function checkIsImage ($ string )
273
+ /**
274
+ * Check if provided url is image.
275
+ *
276
+ * @param string $url
277
+ *
278
+ * @return false|int
279
+ */
280
+ public function checkIsImage ($ url )
274
281
{
275
- if (!is_string ($ string )) {
282
+ if (!is_string ($ url )) {
276
283
return false ;
277
284
}
278
285
279
- $ re = '/(\.png|jpg|jpeg|gif)$/ ' ;
286
+ $ allowed_image_mime_types_regex = $ this ->get_allowed_specific_mime_types_regex ('image ' );
287
+
288
+ if ($ allowed_image_mime_types_regex === '' ) {
289
+ return false ;
290
+ }
280
291
281
- return preg_match ($ re , strtolower ($ string ));
292
+ return preg_match ($ allowed_image_mime_types_regex , strtolower ($ url ));
282
293
}
283
294
284
- public function checkIsVideo ($ string )
295
+ /**
296
+ * Check if provided url is video.
297
+ *
298
+ * @param string $url
299
+ *
300
+ * @return false|int
301
+ */
302
+ public function checkIsVideo ($ url )
285
303
{
286
- if (!is_string ($ string )) {
304
+ if (!is_string ($ url )) {
305
+ return false ;
306
+ }
307
+
308
+ $ allowed_video_mime_types_regex = $ this ->get_allowed_specific_mime_types_regex ('video ' );
309
+
310
+ if ($ allowed_video_mime_types_regex === '' ) {
287
311
return false ;
288
312
}
289
313
290
- $ re = '/(\.mp4|avi|flv|wmv|mov)$/ ' ;
314
+ return preg_match ($ allowed_video_mime_types_regex , strtolower ($ url ));
315
+ }
316
+
317
+ /**
318
+ * Get allowed specific MIME types that can be loaded to the media library.
319
+ *
320
+ * @param string $type
321
+ *
322
+ * @return string
323
+ */
324
+ public function get_allowed_specific_mime_types_regex ($ type )
325
+ {
326
+ // Get all allowed MIME types
327
+ $ all_mime_types = get_allowed_mime_types ();
328
+
329
+ // Filter to include only image MIME types
330
+ $ all_mime_types = array_filter ($ all_mime_types , function ($ mime_type ) use ($ type ) {
331
+ return strpos ($ mime_type , $ type . '/ ' ) === 0 ;
332
+ });
333
+
334
+ if (empty ($ all_mime_types )) {
335
+ return '' ;
336
+ }
291
337
292
- return preg_match ( $ re , strtolower ( $ string )) ;
338
+ return ' /(\. ' . implode ( ' | ' , array_keys ( $ all_mime_types )) . ' )$/ ' ;
293
339
}
294
340
295
341
/**
0 commit comments