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

wp-graphql / wp-graphql / 14716683875

28 Apr 2025 07:58PM UTC coverage: 84.287% (+1.6%) from 82.648%
14716683875

push

github

actions-user
release: merge develop into master for v2.3.0

15905 of 18870 relevant lines covered (84.29%)

257.23 hits per line

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

83.52
/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() {
593✔
13
                register_graphql_object_type(
593✔
14
                        'MediaSize',
593✔
15
                        [
593✔
16
                                'description' => static function () {
593✔
17
                                        return __( 'Details of an available size for a media item', 'wp-graphql' );
15✔
18
                                },
593✔
19
                                'fields'      => static function () {
593✔
20
                                        return [
127✔
21
                                                'name'      => [
127✔
22
                                                        'type'        => 'String',
127✔
23
                                                        'description' => static function () {
127✔
24
                                                                return __( 'The referenced size name', 'wp-graphql' );
15✔
25
                                                        },
127✔
26
                                                ],
127✔
27
                                                'file'      => [
127✔
28
                                                        'type'        => 'String',
127✔
29
                                                        'description' => static function () {
127✔
30
                                                                return __( 'The filename of the referenced size', 'wp-graphql' );
15✔
31
                                                        },
127✔
32
                                                ],
127✔
33
                                                'filePath'  => [
127✔
34
                                                        'type'        => 'String',
127✔
35
                                                        'description' => static function () {
127✔
36
                                                                return __( 'The path of the file for the referenced size (default size is full)', 'wp-graphql' );
15✔
37
                                                        },
127✔
38
                                                        'resolve'     => static function ( $image ) {
127✔
39
                                                                if ( ! empty( $image['ID'] ) ) {
×
40
                                                                        $original_file  = get_attached_file( absint( $image['ID'] ) );
×
41
                                                                        $attachment_url = wp_get_attachment_url( $image['ID'] );
×
42

43
                                                                        if ( ! empty( $original_file ) && ! empty( $image['file'] ) && ! empty( $attachment_url ) ) {
×
44
                                                                                // Return the relative path for the specific size
45
                                                                                return path_join( dirname( wp_make_link_relative( $attachment_url ) ), $image['file'] );
×
46
                                                                        }
47
                                                                } elseif ( ! empty( $image['file'] ) ) {
×
48
                                                                        return wp_make_link_relative( $image['file'] );
×
49
                                                                }
50

51
                                                                return null;
×
52
                                                        },
127✔
53
                                                ],
127✔
54
                                                'width'     => [
127✔
55
                                                        'type'        => 'String',
127✔
56
                                                        'description' => static function () {
127✔
57
                                                                return __( 'The width of the referenced size', 'wp-graphql' );
15✔
58
                                                        },
127✔
59
                                                ],
127✔
60
                                                'height'    => [
127✔
61
                                                        'type'        => 'String',
127✔
62
                                                        'description' => static function () {
127✔
63
                                                                return __( 'The height of the referenced size', 'wp-graphql' );
15✔
64
                                                        },
127✔
65
                                                ],
127✔
66
                                                'mimeType'  => [
127✔
67
                                                        'type'        => 'String',
127✔
68
                                                        'description' => static function () {
127✔
69
                                                                return __( 'The mime type of the referenced size', 'wp-graphql' );
15✔
70
                                                        },
127✔
71
                                                        'resolve'     => static function ( $image ) {
127✔
72
                                                                return ! empty( $image['mime-type'] ) ? $image['mime-type'] : null;
5✔
73
                                                        },
127✔
74
                                                ],
127✔
75
                                                'fileSize'  => [
127✔
76
                                                        'type'        => 'Int',
127✔
77
                                                        'description' => static function () {
127✔
78
                                                                return __( 'The filesize of the resource', 'wp-graphql' );
15✔
79
                                                        },
127✔
80
                                                        'resolve'     => static function ( $image ) {
127✔
81
                                                                if ( ! empty( $image['ID'] ) && ! empty( $image['file'] ) ) {
×
82
                                                                        $original_file = get_attached_file( absint( $image['ID'] ) );
×
83
                                                                        $filesize_path = ! empty( $original_file ) ? path_join( dirname( $original_file ), $image['file'] ) : null;
×
84

85
                                                                        return ! empty( $filesize_path ) ? filesize( $filesize_path ) : null;
×
86
                                                                }
87

88
                                                                return null;
×
89
                                                        },
127✔
90
                                                ],
127✔
91
                                                'sourceUrl' => [
127✔
92
                                                        'type'        => 'String',
127✔
93
                                                        'description' => static function () {
127✔
94
                                                                return __( 'The url of the referenced size', 'wp-graphql' );
15✔
95
                                                        },
127✔
96
                                                        'resolve'     => static function ( $image ) {
127✔
97
                                                                $src_url = null;
6✔
98

99
                                                                if ( ! empty( $image['ID'] ) ) {
6✔
100
                                                                        $src = wp_get_attachment_image_src( absint( $image['ID'] ), $image['name'] );
6✔
101
                                                                        if ( ! empty( $src ) ) {
6✔
102
                                                                                $src_url = $src[0];
6✔
103
                                                                        }
104
                                                                } elseif ( ! empty( $image['file'] ) ) {
×
105
                                                                        $src_url = $image['file'];
×
106
                                                                }
107

108
                                                                return $src_url;
6✔
109
                                                        },
127✔
110
                                                ],
127✔
111
                                        ];
127✔
112
                                },
593✔
113
                        ]
593✔
114
                );
593✔
115
        }
116
}
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

© 2025 Coveralls, Inc