• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql / #943

11 Feb 2025 10:07PM UTC coverage: 83.028% (-0.2%) from 83.19%
#943

push

php-coveralls

web-flow
Merge pull request #3306 from wp-graphql/release/v1.32.0

release: v1.32.0

66 of 113 new or added lines in 5 files covered. (58.41%)

1 existing line in 1 file now uncovered.

13057 of 15726 relevant lines covered (83.03%)

299.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.18
/src/Type/ObjectType/MediaDetails.php
1
<?php
2

3
namespace WPGraphQL\Type\ObjectType;
4

5
class MediaDetails {
6

7
        /**
8
         * Register the MediaDetails type to the Schema
9
         *
10
         * @return void
11
         */
12
        public static function register_type() {
13
                register_graphql_object_type(
590✔
14
                        'MediaDetails',
590✔
15
                        [
590✔
16
                                'description' => __( 'File details for a Media Item', 'wp-graphql' ),
590✔
17
                                'fields'      => [
590✔
18
                                        'width'    => [
590✔
19
                                                'type'        => 'Int',
590✔
20
                                                'description' => __( 'The width of the mediaItem', 'wp-graphql' ),
590✔
21
                                        ],
590✔
22
                                        'height'   => [
590✔
23
                                                'type'        => 'Int',
590✔
24
                                                'description' => __( 'The height of the mediaItem', 'wp-graphql' ),
590✔
25
                                        ],
590✔
26
                                        'file'     => [
590✔
27
                                                'type'        => 'String',
590✔
28
                                                'description' => __( 'The filename of the mediaItem', 'wp-graphql' ),
590✔
29
                                                'resolve'     => static function ( $media_details ) {
590✔
30
                                                        return ! empty( $media_details['file'] ) ? basename( $media_details['file'] ) : null;
9✔
31
                                                },
590✔
32
                                        ],
590✔
33
                                        'filePath' => [
590✔
34
                                                'type'        => 'String',
590✔
35
                                                'description' => __( 'The path to the mediaItem relative to the uploads directory', 'wp-graphql' ),
590✔
36
                                                'resolve'     => static function ( $media_details ) {
590✔
37
                                                        // Get the upload directory info
38
                                                        $upload_dir           = wp_upload_dir();
1✔
39
                                                        $relative_upload_path = wp_make_link_relative( $upload_dir['baseurl'] );
1✔
40

41
                                                        if ( ! empty( $media_details['file'] ) ) {
1✔
42
                                                                return path_join( $relative_upload_path, $media_details['file'] );
1✔
43
                                                        }
44

NEW
45
                                                        return null;
×
46
                                                },
590✔
47
                                        ],
590✔
48
                                        'sizes'    => [
590✔
49
                                                'type'        => [
590✔
50
                                                        'list_of' => 'MediaSize',
590✔
51
                                                ],
590✔
52
                                                'args'        => [
590✔
53
                                                        'exclude' => [ // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
590✔
54
                                                                'type'        => [ 'list_of' => 'MediaItemSizeEnum' ],
590✔
55
                                                                'description' => __( 'The sizes to exclude. Will take precedence over `include`.', 'wp-graphql' ),
590✔
56
                                                        ],
590✔
57
                                                        'include' => [
590✔
58
                                                                'type'        => [ 'list_of' => 'MediaItemSizeEnum' ],
590✔
59
                                                                'description' => __( 'The sizes to include. Can be overridden by `exclude`.', 'wp-graphql' ),
590✔
60
                                                        ],
590✔
61
                                                ],
590✔
62
                                                'description' => __( 'The available sizes of the mediaItem', 'wp-graphql' ),
590✔
63
                                                'resolve'     => static function ( $media_details, array $args ) {
590✔
64
                                                        // Bail early.
65
                                                        if ( empty( $media_details['sizes'] ) ) {
8✔
66
                                                                return null;
×
67
                                                        }
68

69
                                                        // If the include arg is set, only include the sizes specified.
70
                                                        if ( ! empty( $args['include'] ) ) {
8✔
71
                                                                $media_details['sizes'] = array_intersect_key( $media_details['sizes'], array_flip( $args['include'] ) );
1✔
72
                                                        }
73

74
                                                        // If the exclude arg is set, exclude the sizes specified.
75
                                                        if ( ! empty( $args['exclude'] ) ) {
8✔
76
                                                                $media_details['sizes'] = array_diff_key( $media_details['sizes'], array_flip( $args['exclude'] ) );
1✔
77
                                                        }
78

79
                                                        $sizes = [];
8✔
80

81
                                                        foreach ( $media_details['sizes'] as $size_name => $size ) {
8✔
82
                                                                $size['ID']   = $media_details['ID'];
8✔
83
                                                                $size['name'] = $size_name;
8✔
84
                                                                $sizes[]      = $size;
8✔
85
                                                        }
86

87
                                                        return ! empty( $sizes ) ? $sizes : null;
8✔
88
                                                },
590✔
89
                                        ],
590✔
90
                                        'meta'     => [
590✔
91
                                                'type'        => 'MediaItemMeta',
590✔
92
                                                'description' => __( 'Meta information associated with the mediaItem', 'wp-graphql' ),
590✔
93
                                                'resolve'     => static function ( $media_details ) {
590✔
94
                                                        return ! empty( $media_details['image_meta'] ) ? $media_details['image_meta'] : null;
5✔
95
                                                },
590✔
96
                                        ],
590✔
97
                                ],
590✔
98
                        ]
590✔
99
                );
590✔
100
        }
101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc