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

wp-graphql / wp-graphql-woocommerce / 14788432316

01 May 2025 06:46PM UTC coverage: 83.59% (-0.03%) from 83.617%
14788432316

push

github

web-flow
Fix/recursive interface definitions (#934)

* fix: recursive interface definitions for Product, etc.

* devops: CI & Linter compliances met

* devops: lint-code.yml updated

---------

Co-authored-by: Geoff Taylor <geoff@axistaylor.com>

7 of 9 new or added lines in 8 files covered. (77.78%)

8 existing lines in 2 files now uncovered.

12424 of 14863 relevant lines covered (83.59%)

72.08 hits per line

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

4.35
/includes/data/mutation/class-settings-mutation.php
1
<?php
2
/**
3
 * Defines helper functions for executing mutations related to the WC Settings API.
4
 *
5
 * @package WPGraphQL\WooCommerce\Data\Mutation
6
 * @since 0.20.0
7
 */
8

9
namespace WPGraphQL\WooCommerce\Data\Mutation;
10

11
use GraphQL\Error\UserError;
12

13
/**
14
 * Class - Settings_Mutation
15
 */
16
class Settings_Mutation {
17
        /**
18
         * Validate a text value for a text based setting.
19
         *
20
         * @param string $value Value.
21
         * @param array  $setting Setting.
22
         * @return string
23
         */
24
        public static function validate_setting_text_field( $value, $setting ) {
25
                $value = is_null( $value ) ? '' : $value;
2✔
26
                return wp_kses_post( trim( stripslashes( $value ) ) );
2✔
27
        }
28

29
        /**
30
         * Validate select based settings.
31
         *
32
         * @param string $value Value.
33
         * @param array  $setting Setting.
34
         *
35
         * @throws \GraphQL\Error\UserError If an invalid setting value was passed.
36
         *
37
         * @return string
38
         */
39
        public static function validate_setting_select_field( $value, $setting ) {
40
                if ( array_key_exists( $value, $setting['options'] ) ) {
×
41
                        return $value;
×
42
                } else {
43
                        throw new UserError( __( 'An invalid setting value was passed.', 'wp-graphql-woocommerce' ), 400 );
×
44
                }
45
        }
46

47
        /**
48
         * Validate multiselect based settings.
49
         *
50
         * @param array $values Values.
51
         * @param array $setting Setting.
52
         *
53
         * @throws \GraphQL\Error\UserError If an invalid setting value was passed.
54
         *
55
         * @return array
56
         */
57
        public static function validate_setting_multiselect_field( $values, $setting ) {
58
                if ( empty( $values ) ) {
×
59
                        return [];
×
60
                }
61

62
                if ( ! is_array( $values ) ) {
×
63
                        throw new UserError( __( 'An invalid setting value was passed.', 'wp-graphql-woocommerce' ), 400 );
×
64
                }
65

66
                $final_values = [];
×
67
                foreach ( $values as $value ) {
×
68
                        if ( array_key_exists( $value, $setting['options'] ) ) {
×
69
                                $final_values[] = $value;
×
70
                        }
71
                }
72

73
                return $final_values;
×
74
        }
75

76
        /**
77
         * Validate image_width based settings.
78
         *
79
         * @param array $values Values.
80
         * @param array $setting Setting.
81
         *
82
         * @throws \GraphQL\Error\UserError If an invalid setting value was passed.
83
         *
84
         * @return string
85
         */
86
        public static function validate_setting_image_width_field( $values, $setting ) {
87
                if ( ! is_array( $values ) ) {
×
88
                        throw new UserError( __( 'An invalid setting value was passed.', 'wp-graphql-woocommerce' ), 400 );
×
89
                }
90

91
                $current = $setting['value'];
×
92
                if ( isset( $values['width'] ) ) {
×
93
                        $current['width'] = intval( $values['width'] );
×
94
                }
95
                if ( isset( $values['height'] ) ) {
×
96
                        $current['height'] = intval( $values['height'] );
×
97
                }
98
                if ( isset( $values['crop'] ) ) {
×
99
                        $current['crop'] = (bool) $values['crop'];
×
100
                }
101
                return $current;
×
102
        }
103

104
        /**
105
         * Validate radio based settings.
106
         *
107
         * @param string $value Value.
108
         * @param array  $setting Setting.
109
         *
110
         * @throws \GraphQL\Error\UserError If an invalid setting value was passed.
111
         *
112
         * @return string
113
         */
114
        public static function validate_setting_radio_field( $value, $setting ) {
115
                return self::validate_setting_select_field( $value, $setting );
×
116
        }
117

118
        /**
119
         * Validate checkbox based settings.
120
         *
121
         * @param string $value Value.
122
         * @param array  $setting Setting.
123
         *
124
         * @throws \GraphQL\Error\UserError If an invalid setting value was passed.
125
         *
126
         * @return string
127
         */
128
        public function validate_setting_checkbox_field( $value, $setting ) {
129
                if ( in_array( $value, [ 'yes', 'no' ], true ) ) {
×
130
                        return $value;
×
131
                } elseif ( empty( $value ) ) {
×
132
                        $value = isset( $setting['default'] ) ? $setting['default'] : 'no';
×
133
                        return $value;
×
134
                } else {
135
                        throw new UserError( __( 'An invalid setting value was passed.', 'wp-graphql-woocommerce' ), 400 );
×
136
                }
137
        }
138

139
        /**
140
         * Validate textarea based settings.
141
         *
142
         * @param string $value Value.
143
         * @param array  $setting Setting.
144
         *
145
         * @return string
146
         */
147
        public static function validate_setting_textarea_field( $value, $setting ) {
148
                $value = is_null( $value ) ? '' : $value;
×
149
                return wp_kses(
×
150
                        trim( stripslashes( $value ) ),
×
151
                        array_merge(
×
152
                                [
×
153
                                        'iframe' => [
×
154
                                                'src'   => true,
×
155
                                                'style' => true,
×
156
                                                'id'    => true,
×
157
                                                'class' => true,
×
158
                                        ],
×
159
                                ],
×
160
                                wp_kses_allowed_html( 'post' )
×
161
                        )
×
162
                );
×
163
        }
164
}
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