PluginProbe
Image Source Control Lite – Show Image Credits and Captions / trunk
Image Source Control Lite – Show Image Credits and Captions vtrunk
3.12.0 3.11.0 trunk 1.1 1.1.1 1.1.2 1.1.2.1 1.1.3 1.10 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.2 1.2.0.1 1.2.0.2 1.2.0.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.4.1 1.3.5 All 110 releases
image-source-control-isc / includes / media-type-checker.php

media-type-checker.php in Image Source Control Lite – Show Image Credits and Captions trunk, at includes/media-type-checker.php

59 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ISC;
4
5 /**
6 * Class to check media types
7 */
8 class Media_Type_Checker {
9
10 /**
11 * Check if an attachment is an image
12 *
13 * @param int|\WP_Post $attachment Attachment ID or post object.
14 *
15 * @return bool True if the attachment is an image, false otherwise.
16 */
17 public static function is_image( $attachment ): bool {
18 if ( ! is_int( $attachment ) && ! $attachment instanceof \WP_Post ) {
19 return false;
20 }
21
22 $mime_type = get_post_mime_type( $attachment );
23 if ( ! $mime_type ) {
24 return false;
25 }
26
27 return strpos( $mime_type, 'image/' ) === 0;
28 }
29
30 /**
31 * Check the images-only option
32 *
33 * @return bool True if images-only is enabled, false otherwise.
34 */
35 public static function enabled_images_only_option(): bool {
36 $options = \ISC\Plugin::get_options();
37
38 // Check if images_only is enabled
39 return ! empty( $options['images_only'] );
40 }
41
42 /**
43 * Check if we should process this attachment based on settings
44 *
45 * @param int|\WP_Post $attachment Attachment ID or post object.
46 *
47 * @return bool True if we should process this attachment, false otherwise.
48 */
49 public static function should_process_attachment( $attachment ): bool {
50 // If images_only is enabled, only process images
51 if ( self::enabled_images_only_option() ) {
52 return self::is_image( $attachment );
53 }
54
55 // Otherwise process all attachments
56 return true;
57 }
58 }
59