• 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

78.57
/src/Type/ObjectType/MediaSize.php
1
<?php
2

3
namespace WPGraphQL\Type\ObjectType;
4

5
class MediaSize {
6

7
        /**
8
         * Register the MediaSize
9
         *
10
         * @return void
11
         */
12
        public static function register_type() {
13
                register_graphql_object_type(
590✔
14
                        'MediaSize',
590✔
15
                        [
590✔
16
                                'description' => __( 'Details of an available size for a media item', 'wp-graphql' ),
590✔
17
                                'fields'      => [
590✔
18
                                        'name'      => [
590✔
19
                                                'type'        => 'String',
590✔
20
                                                'description' => __( 'The referenced size name', 'wp-graphql' ),
590✔
21
                                        ],
590✔
22
                                        'file'      => [
590✔
23
                                                'type'        => 'String',
590✔
24
                                                'description' => __( 'The filename of the referenced size', 'wp-graphql' ),
590✔
25
                                        ],
590✔
26
                                        'filePath'  => [
590✔
27
                                                'type'        => 'String',
590✔
28
                                                'description' => __( 'The path of the file for the referenced size (default size is full)', 'wp-graphql' ),
590✔
29
                                                'resolve'     => static function ( $image ) {
590✔
NEW
30
                                                        if ( ! empty( $image['ID'] ) ) {
×
NEW
31
                                                                $original_file  = get_attached_file( absint( $image['ID'] ) );
×
NEW
32
                                                                $attachment_url = wp_get_attachment_url( $image['ID'] );
×
33

NEW
34
                                                                if ( ! empty( $original_file ) && ! empty( $image['file'] ) && ! empty( $attachment_url ) ) {
×
35
                                                                        // Return the relative path for the specific size
NEW
36
                                                                        return path_join( dirname( wp_make_link_relative( $attachment_url ) ), $image['file'] );
×
37
                                                                }
NEW
38
                                                        } elseif ( ! empty( $image['file'] ) ) {
×
NEW
39
                                                                return wp_make_link_relative( $image['file'] );
×
40
                                                        }
41

NEW
42
                                                        return null;
×
43
                                                },
590✔
44
                                        ],
590✔
45
                                        'width'     => [
590✔
46
                                                'type'        => 'String',
590✔
47
                                                'description' => __( 'The width of the referenced size', 'wp-graphql' ),
590✔
48
                                        ],
590✔
49
                                        'height'    => [
590✔
50
                                                'type'        => 'String',
590✔
51
                                                'description' => __( 'The height of the referenced size', 'wp-graphql' ),
590✔
52
                                        ],
590✔
53
                                        'mimeType'  => [
590✔
54
                                                'type'        => 'String',
590✔
55
                                                'description' => __( 'The mime type of the referenced size', 'wp-graphql' ),
590✔
56
                                                'resolve'     => static function ( $image ) {
590✔
57
                                                        return ! empty( $image['mime-type'] ) ? $image['mime-type'] : null;
5✔
58
                                                },
590✔
59
                                        ],
590✔
60
                                        'fileSize'  => [
590✔
61
                                                'type'        => 'Int',
590✔
62
                                                'description' => __( 'The filesize of the resource', 'wp-graphql' ),
590✔
63
                                                'resolve'     => static function ( $image ) {
590✔
64
                                                        if ( ! empty( $image['ID'] ) && ! empty( $image['file'] ) ) {
×
65
                                                                $original_file = get_attached_file( absint( $image['ID'] ) );
×
66
                                                                $filesize_path = ! empty( $original_file ) ? path_join( dirname( $original_file ), $image['file'] ) : null;
×
67

68
                                                                return ! empty( $filesize_path ) ? filesize( $filesize_path ) : null;
×
69
                                                        }
70

71
                                                        return null;
×
72
                                                },
590✔
73
                                        ],
590✔
74
                                        'sourceUrl' => [
590✔
75
                                                'type'        => 'String',
590✔
76
                                                'description' => __( 'The url of the referenced size', 'wp-graphql' ),
590✔
77
                                                'resolve'     => static function ( $image ) {
590✔
78
                                                        $src_url = null;
6✔
79

80
                                                        if ( ! empty( $image['ID'] ) ) {
6✔
81
                                                                $src = wp_get_attachment_image_src( absint( $image['ID'] ), $image['name'] );
6✔
82
                                                                if ( ! empty( $src ) ) {
6✔
83
                                                                        $src_url = $src[0];
6✔
84
                                                                }
85
                                                        } elseif ( ! empty( $image['file'] ) ) {
×
86
                                                                $src_url = $image['file'];
×
87
                                                        }
88

89
                                                        return $src_url;
6✔
90
                                                },
590✔
91
                                        ],
590✔
92
                                ],
590✔
93
                        ]
590✔
94
                );
590✔
95
        }
96
}
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