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

wp-graphql / wp-graphql-woocommerce / 23659243833

27 Mar 2026 05:31PM UTC coverage: 89.384% (+0.2%) from 89.165%
23659243833

Pull #1002

github

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

515 of 570 new or added lines in 11 files covered. (90.35%)

31 existing lines in 4 files now uncovered.

15795 of 17671 relevant lines covered (89.38%)

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

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

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

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

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