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

wp-graphql / wp-graphql-woocommerce / 23675172456

28 Mar 2026 02:10AM UTC coverage: 70.983% (-18.4%) from 89.424%
23675172456

Pull #1003

github

web-flow
Merge 05339093d into 6fb7b226f
Pull Request #1003: devops: WC email template tests, COT cursor HPOS fix, checkout account auth

71 of 81 new or added lines in 5 files covered. (87.65%)

3346 existing lines in 124 files now uncovered.

12576 of 17717 relevant lines covered (70.98%)

55.38 hits per line

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

69.88
/includes/type/interface/class-wc-setting.php
1
<?php
2
/**
3
 * WPInterface Type - WCSetting
4
 *
5
 * Registers WCSetting interface with common fields shared
6
 * by all WC setting concrete types.
7
 *
8
 * @package WPGraphQL\WooCommerce\Type\WPInterface
9
 * @since   TBD
10
 */
11

12
namespace WPGraphQL\WooCommerce\Type\WPInterface;
13

14
/**
15
 * Class WC_Setting
16
 */
17
class WC_Setting {
18
        /**
19
         * Mapping of WC setting types to normalized enum values.
20
         *
21
         * @var array
22
         */
23
        private static $type_map = [
24
                'multi_select_countries'         => 'multiselect',
25
                'single_select_country'          => 'select',
26
                'single_select_page'             => 'select',
27
                'single_select_page_with_search' => 'select',
28
                'thumbnail_cropping'             => 'text',
29
        ];
30

31
        /**
32
         * Default setting type to GraphQL concrete type mapping.
33
         *
34
         * @var array
35
         */
36
        private static $default_graphql_type_map = [
37
                'multiselect'            => 'WCArraySetting',
38
                'relative_date_selector' => 'WCRelativeDateSetting',
39
                'image_width'            => 'WCImageWidthSetting',
40
        ];
41

42
        /**
43
         * Registers the WCSetting interface.
44
         *
45
         * @return void
46
         */
47
        public static function register_interface() {
48
                register_graphql_interface_type(
110✔
49
                        'WCSetting',
110✔
50
                        [
110✔
51
                                'eagerlyLoadType' => true,
110✔
52
                                'description'     => __( 'A WC setting object', 'wp-graphql-woocommerce' ),
110✔
53
                                'resolveType'     => [ self::class, 'resolve_type' ],
110✔
54
                                'fields'          => [
110✔
55
                                        'id'          => [
110✔
56
                                                'type'        => [ 'non_null' => 'ID' ],
110✔
57
                                                'description' => __( 'The globally unique identifier for the WC setting.', 'wp-graphql-woocommerce' ),
110✔
58
                                                'resolve'     => static function ( $source ) {
110✔
UNCOV
59
                                                        return $source['id'] ?? null;
×
60
                                                },
110✔
61
                                        ],
110✔
62
                                        'label'       => [
110✔
63
                                                'type'        => 'String',
110✔
64
                                                'description' => __( 'A human readable label for the setting used in user interfaces.', 'wp-graphql-woocommerce' ),
110✔
65
                                                'resolve'     => static function ( $source ) {
110✔
UNCOV
66
                                                        return $source['label'] ?? $source['title'] ?? null;
×
67
                                                },
110✔
68
                                        ],
110✔
69
                                        'groupId'     => [
110✔
70
                                                'type'        => 'String',
110✔
71
                                                'description' => __( 'The ID of the settings group this setting belongs to.', 'wp-graphql-woocommerce' ),
110✔
72
                                                'resolve'     => static function ( $source ) {
110✔
UNCOV
73
                                                        return $source['group_id'] ?? null;
×
74
                                                },
110✔
75
                                        ],
110✔
76
                                        'description' => [
110✔
77
                                                'type'        => 'String',
110✔
78
                                                'description' => __( 'A human readable description for the setting used in user interfaces.', 'wp-graphql-woocommerce' ),
110✔
79
                                                'resolve'     => static function ( $source ) {
110✔
UNCOV
80
                                                        return ! empty( $source['description'] ) ? $source['description'] : null;
×
81
                                                },
110✔
82
                                        ],
110✔
83
                                        'type'        => [
110✔
84
                                                'type'        => 'WCSettingTypeEnum',
110✔
85
                                                'description' => __( 'Type of setting.', 'wp-graphql-woocommerce' ),
110✔
86
                                                'resolve'     => static function ( $source ) {
110✔
UNCOV
87
                                                        $raw_type = $source['type'] ?? '';
×
UNCOV
88
                                                        return self::$type_map[ $raw_type ] ?? ( ! empty( $raw_type ) ? $raw_type : null );
×
89
                                                },
110✔
90
                                        ],
110✔
91
                                        'tip'         => [
110✔
92
                                                'type'        => 'String',
110✔
93
                                                'description' => __( 'Additional help text shown to the user about the setting', 'wp-graphql-woocommerce' ),
110✔
94
                                                'resolve'     => static function ( $source ) {
110✔
UNCOV
95
                                                        return ! empty( $source['desc_tip'] ) ? $source['desc_tip'] : ( ! empty( $source['tip'] ) ? $source['tip'] : null );
×
96
                                                },
110✔
97
                                        ],
110✔
98
                                        'placeholder' => [
110✔
99
                                                'type'        => 'String',
110✔
100
                                                'description' => __( 'Placeholder text to be displayed in text inputs.', 'wp-graphql-woocommerce' ),
110✔
101
                                                'resolve'     => static function ( $source ) {
110✔
UNCOV
102
                                                        return ! empty( $source['placeholder'] ) ? $source['placeholder'] : null;
×
103
                                                },
110✔
104
                                        ],
110✔
105
                                        'options'     => [
110✔
106
                                                'type'        => [ 'list_of' => 'String' ],
110✔
107
                                                'description' => __( 'Array of option key/value pairs for select and multiselect types.', 'wp-graphql-woocommerce' ),
110✔
108
                                                'resolve'     => static function ( $source ) {
110✔
UNCOV
109
                                                        if ( empty( $source['options'] ) || ! is_array( $source['options'] ) ) {
×
UNCOV
110
                                                                return null;
×
111
                                                        }
112

UNCOV
113
                                                        $options = [];
×
UNCOV
114
                                                        foreach ( $source['options'] as $key => $label ) {
×
UNCOV
115
                                                                $options[] = $key . ':' . $label;
×
116
                                                        }
117

UNCOV
118
                                                        return $options;
×
119
                                                },
110✔
120
                                        ],
110✔
121
                                ],
110✔
122
                        ]
110✔
123
                );
110✔
124
        }
125

126
        /**
127
         * Resolves a setting array to the correct concrete GraphQL type.
128
         *
129
         * @param array $source The setting data array.
130
         *
131
         * @return string The GraphQL type name.
132
         */
133
        public static function resolve_type( $source ) {
UNCOV
134
                $raw_type        = $source['type'] ?? '';
×
UNCOV
135
                $normalized_type = self::$type_map[ $raw_type ] ?? $raw_type;
×
UNCOV
136
                if ( empty( $normalized_type ) ) {
×
137
                        $normalized_type = 'text';
×
138
                }
139

140
                /**
141
                 * Filters the mapping of WC setting types to GraphQL concrete type names.
142
                 *
143
                 * Allows third-party plugins to register custom setting types and map them
144
                 * to their own GraphQL types that implement the WCSetting interface.
145
                 *
146
                 * @param array  $type_map        Map of WC setting type => GraphQL type name.
147
                 * @param string $normalized_type  The normalized setting type.
148
                 * @param array  $source           The raw setting data.
149
                 */
UNCOV
150
                $graphql_type_map = apply_filters(
×
UNCOV
151
                        'graphql_woocommerce_setting_type_map',
×
UNCOV
152
                        self::$default_graphql_type_map,
×
UNCOV
153
                        $normalized_type,
×
UNCOV
154
                        $source
×
UNCOV
155
                );
×
156

UNCOV
157
                return $graphql_type_map[ $normalized_type ] ?? 'WCStringSetting';
×
158
        }
159
}
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