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

wp-graphql / wp-graphql-woocommerce / 23663706692

27 Mar 2026 07:25PM UTC coverage: 89.424% (+0.3%) from 89.165%
23663706692

Pull #1002

github

web-flow
Merge 49b913dda into 66f840efc
Pull Request #1002: feat: WC Settings API, compatibility refactor, HPOS fix

575 of 643 new or added lines in 21 files covered. (89.42%)

15812 of 17682 relevant lines covered (89.42%)

284.73 hits per line

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

96.3
/includes/type/object/class-wc-setting-type.php
1
<?php
2
/**
3
 * WPObject Types - WC_Setting_Type
4
 *
5
 * Registers WCSetting concrete implementations and helper types.
6
 *
7
 * @package WPGraphQL\WooCommerce\Type\WPObject
8
 * @since   0.20.0
9
 */
10

11
namespace WPGraphQL\WooCommerce\Type\WPObject;
12

13
/**
14
 * Class WC_Setting_Type
15
 */
16
class WC_Setting_Type {
17
        /**
18
         * Registers WCSetting concrete types and helper object types.
19
         *
20
         * @return void
21
         */
22
        public static function register() {
23
                self::register_helper_types();
560✔
24
                self::register_concrete_types();
560✔
25
        }
26

27
        /**
28
         * Registers helper object types used by setting value fields.
29
         *
30
         * @return void
31
         */
32
        private static function register_helper_types() {
33
                register_graphql_object_type(
560✔
34
                        'WCRelativeDate',
560✔
35
                        [
560✔
36
                                'eagerlyLoadType' => true,
560✔
37
                                'description'     => __( 'A relative date value with a number and unit.', 'wp-graphql-woocommerce' ),
560✔
38
                                'fields'          => [
560✔
39
                                        'number' => [
560✔
40
                                                'type'        => 'Int',
560✔
41
                                                'description' => __( 'The number of periods.', 'wp-graphql-woocommerce' ),
560✔
42
                                                'resolve'     => static function ( $source ) {
560✔
43
                                                        $number = $source['number'] ?? '';
2✔
44
                                                        return '' !== $number ? absint( $number ) : null;
2✔
45
                                                },
560✔
46
                                        ],
560✔
47
                                        'unit'   => [
560✔
48
                                                'type'        => 'String',
560✔
49
                                                'description' => __( 'The period unit (days, weeks, months, years).', 'wp-graphql-woocommerce' ),
560✔
50
                                        ],
560✔
51
                                ],
560✔
52
                        ]
560✔
53
                );
560✔
54

55
                register_graphql_object_type(
560✔
56
                        'WCImageWidth',
560✔
57
                        [
560✔
58
                                'eagerlyLoadType' => true,
560✔
59
                                'description'     => __( 'An image width value with dimensions and crop flag.', 'wp-graphql-woocommerce' ),
560✔
60
                                'fields'          => [
560✔
61
                                        'width'  => [
560✔
62
                                                'type'        => 'Int',
560✔
63
                                                'description' => __( 'Image width in pixels.', 'wp-graphql-woocommerce' ),
560✔
64
                                        ],
560✔
65
                                        'height' => [
560✔
66
                                                'type'        => 'Int',
560✔
67
                                                'description' => __( 'Image height in pixels.', 'wp-graphql-woocommerce' ),
560✔
68
                                        ],
560✔
69
                                        'crop'   => [
560✔
70
                                                'type'        => 'Boolean',
560✔
71
                                                'description' => __( 'Whether to crop the image.', 'wp-graphql-woocommerce' ),
560✔
72
                                                'resolve'     => static function ( $source ) {
560✔
NEW
73
                                                        return ! empty( $source['crop'] );
×
74
                                                },
560✔
75
                                        ],
560✔
76
                                ],
560✔
77
                        ]
560✔
78
                );
560✔
79
        }
80

81
        /**
82
         * Registers concrete setting types that implement the WCSetting interface.
83
         *
84
         * @return void
85
         */
86
        private static function register_concrete_types() {
87
                register_graphql_object_type(
560✔
88
                        'WCStringSetting',
560✔
89
                        [
560✔
90
                                'eagerlyLoadType' => true,
560✔
91
                                'description'     => __( 'A WC setting with a string value.', 'wp-graphql-woocommerce' ),
560✔
92
                                'interfaces'      => [ 'WCSetting' ],
560✔
93
                                'fields'          => [
560✔
94
                                        'value'   => [
560✔
95
                                                'type'        => 'String',
560✔
96
                                                'description' => __( 'Setting value.', 'wp-graphql-woocommerce' ),
560✔
97
                                                'resolve'     => static function ( $source ) {
560✔
98
                                                        $value = $source['value'] ?? null;
24✔
99
                                                        return is_scalar( $value ) ? (string) $value : null;
24✔
100
                                                },
560✔
101
                                        ],
560✔
102
                                        'default' => [
560✔
103
                                                'type'        => 'String',
560✔
104
                                                'description' => __( 'Default value for the setting.', 'wp-graphql-woocommerce' ),
560✔
105
                                                'resolve'     => static function ( $source ) {
560✔
106
                                                        $value = $source['default'] ?? null;
8✔
107
                                                        return ! empty( $value ) && is_scalar( $value ) ? (string) $value : null;
8✔
108
                                                },
560✔
109
                                        ],
560✔
110
                                ],
560✔
111
                        ]
560✔
112
                );
560✔
113

114
                register_graphql_object_type(
560✔
115
                        'WCArraySetting',
560✔
116
                        [
560✔
117
                                'eagerlyLoadType' => true,
560✔
118
                                'description'     => __( 'A WC setting with an array value.', 'wp-graphql-woocommerce' ),
560✔
119
                                'interfaces'      => [ 'WCSetting' ],
560✔
120
                                'fields'          => [
560✔
121
                                        'value'   => [
560✔
122
                                                'type'        => [ 'list_of' => 'String' ],
560✔
123
                                                'description' => __( 'Setting value as a list of strings.', 'wp-graphql-woocommerce' ),
560✔
124
                                                'resolve'     => static function ( $source ) {
560✔
NEW
125
                                                        $value = $source['value'] ?? null;
×
NEW
126
                                                        return is_array( $value ) ? array_values( $value ) : null;
×
127
                                                },
560✔
128
                                        ],
560✔
129
                                        'default' => [
560✔
130
                                                'type'        => [ 'list_of' => 'String' ],
560✔
131
                                                'description' => __( 'Default value as a list of strings.', 'wp-graphql-woocommerce' ),
560✔
132
                                                'resolve'     => static function ( $source ) {
560✔
NEW
133
                                                        $value = $source['default'] ?? null;
×
NEW
134
                                                        return is_array( $value ) ? array_values( $value ) : null;
×
135
                                                },
560✔
136
                                        ],
560✔
137
                                ],
560✔
138
                        ]
560✔
139
                );
560✔
140

141
                register_graphql_object_type(
560✔
142
                        'WCRelativeDateSetting',
560✔
143
                        [
560✔
144
                                'eagerlyLoadType' => true,
560✔
145
                                'description'     => __( 'A WC setting with a relative date value.', 'wp-graphql-woocommerce' ),
560✔
146
                                'interfaces'      => [ 'WCSetting' ],
560✔
147
                                'fields'          => [
560✔
148
                                        'value'   => [
560✔
149
                                                'type'        => 'WCRelativeDate',
560✔
150
                                                'description' => __( 'Setting value as a relative date.', 'wp-graphql-woocommerce' ),
560✔
151
                                        ],
560✔
152
                                        'default' => [
560✔
153
                                                'type'        => 'WCRelativeDate',
560✔
154
                                                'description' => __( 'Default value as a relative date.', 'wp-graphql-woocommerce' ),
560✔
155
                                        ],
560✔
156
                                ],
560✔
157
                        ]
560✔
158
                );
560✔
159

160
                register_graphql_object_type(
560✔
161
                        'WCImageWidthSetting',
560✔
162
                        [
560✔
163
                                'eagerlyLoadType' => true,
560✔
164
                                'description'     => __( 'A WC setting with an image width value.', 'wp-graphql-woocommerce' ),
560✔
165
                                'interfaces'      => [ 'WCSetting' ],
560✔
166
                                'fields'          => [
560✔
167
                                        'value'   => [
560✔
168
                                                'type'        => 'WCImageWidth',
560✔
169
                                                'description' => __( 'Setting value as image dimensions.', 'wp-graphql-woocommerce' ),
560✔
170
                                        ],
560✔
171
                                        'default' => [
560✔
172
                                                'type'        => 'WCImageWidth',
560✔
173
                                                'description' => __( 'Default value as image dimensions.', 'wp-graphql-woocommerce' ),
560✔
174
                                        ],
560✔
175
                                ],
560✔
176
                        ]
560✔
177
                );
560✔
178
        }
179
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc