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

wp-graphql / wp-graphql-woocommerce / 23661591439

27 Mar 2026 06:30PM UTC coverage: 89.39% (+0.2%) from 89.165%
23661591439

Pull #1002

github

web-flow
Merge 440d92338 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%)

15806 of 17682 relevant lines covered (89.39%)

140.84 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();
277✔
24
                self::register_concrete_types();
277✔
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(
277✔
34
                        'WCRelativeDate',
277✔
35
                        [
277✔
36
                                'eagerlyLoadType' => true,
277✔
37
                                'description'     => __( 'A relative date value with a number and unit.', 'wp-graphql-woocommerce' ),
277✔
38
                                'fields'          => [
277✔
39
                                        'number' => [
277✔
40
                                                'type'        => 'Int',
277✔
41
                                                'description' => __( 'The number of periods.', 'wp-graphql-woocommerce' ),
277✔
42
                                                'resolve'     => static function ( $source ) {
277✔
43
                                                        $number = $source['number'] ?? '';
1✔
44
                                                        return '' !== $number ? absint( $number ) : null;
1✔
45
                                                },
277✔
46
                                        ],
277✔
47
                                        'unit'   => [
277✔
48
                                                'type'        => 'String',
277✔
49
                                                'description' => __( 'The period unit (days, weeks, months, years).', 'wp-graphql-woocommerce' ),
277✔
50
                                        ],
277✔
51
                                ],
277✔
52
                        ]
277✔
53
                );
277✔
54

55
                register_graphql_object_type(
277✔
56
                        'WCImageWidth',
277✔
57
                        [
277✔
58
                                'eagerlyLoadType' => true,
277✔
59
                                'description'     => __( 'An image width value with dimensions and crop flag.', 'wp-graphql-woocommerce' ),
277✔
60
                                'fields'          => [
277✔
61
                                        'width'  => [
277✔
62
                                                'type'        => 'Int',
277✔
63
                                                'description' => __( 'Image width in pixels.', 'wp-graphql-woocommerce' ),
277✔
64
                                        ],
277✔
65
                                        'height' => [
277✔
66
                                                'type'        => 'Int',
277✔
67
                                                'description' => __( 'Image height in pixels.', 'wp-graphql-woocommerce' ),
277✔
68
                                        ],
277✔
69
                                        'crop'   => [
277✔
70
                                                'type'        => 'Boolean',
277✔
71
                                                'description' => __( 'Whether to crop the image.', 'wp-graphql-woocommerce' ),
277✔
72
                                                'resolve'     => static function ( $source ) {
277✔
NEW
73
                                                        return ! empty( $source['crop'] );
×
74
                                                },
277✔
75
                                        ],
277✔
76
                                ],
277✔
77
                        ]
277✔
78
                );
277✔
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(
277✔
88
                        'WCStringSetting',
277✔
89
                        [
277✔
90
                                'eagerlyLoadType' => true,
277✔
91
                                'description'     => __( 'A WC setting with a string value.', 'wp-graphql-woocommerce' ),
277✔
92
                                'interfaces'      => [ 'WCSetting' ],
277✔
93
                                'fields'          => [
277✔
94
                                        'value'   => [
277✔
95
                                                'type'        => 'String',
277✔
96
                                                'description' => __( 'Setting value.', 'wp-graphql-woocommerce' ),
277✔
97
                                                'resolve'     => static function ( $source ) {
277✔
98
                                                        $value = $source['value'] ?? null;
12✔
99
                                                        return is_scalar( $value ) ? (string) $value : null;
12✔
100
                                                },
277✔
101
                                        ],
277✔
102
                                        'default' => [
277✔
103
                                                'type'        => 'String',
277✔
104
                                                'description' => __( 'Default value for the setting.', 'wp-graphql-woocommerce' ),
277✔
105
                                                'resolve'     => static function ( $source ) {
277✔
106
                                                        $value = $source['default'] ?? null;
4✔
107
                                                        return ! empty( $value ) && is_scalar( $value ) ? (string) $value : null;
4✔
108
                                                },
277✔
109
                                        ],
277✔
110
                                ],
277✔
111
                        ]
277✔
112
                );
277✔
113

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

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

160
                register_graphql_object_type(
277✔
161
                        'WCImageWidthSetting',
277✔
162
                        [
277✔
163
                                'eagerlyLoadType' => true,
277✔
164
                                'description'     => __( 'A WC setting with an image width value.', 'wp-graphql-woocommerce' ),
277✔
165
                                'interfaces'      => [ 'WCSetting' ],
277✔
166
                                'fields'          => [
277✔
167
                                        'value'   => [
277✔
168
                                                'type'        => 'WCImageWidth',
277✔
169
                                                'description' => __( 'Setting value as image dimensions.', 'wp-graphql-woocommerce' ),
277✔
170
                                        ],
277✔
171
                                        'default' => [
277✔
172
                                                'type'        => 'WCImageWidth',
277✔
173
                                                'description' => __( 'Default value as image dimensions.', 'wp-graphql-woocommerce' ),
277✔
174
                                        ],
277✔
175
                                ],
277✔
176
                        ]
277✔
177
                );
277✔
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