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

wp-graphql / wp-graphql-woocommerce / 27452430870

13 Jun 2026 01:26AM UTC coverage: 91.8%. Remained the same
27452430870

Pull #1019

github

web-flow
Merge f03617ca3 into 2ce9424e1
Pull Request #1019: fix: address WordPress.org plugin review (rename + prefixing + headers)

1330 of 1587 new or added lines in 201 files covered. (83.81%)

1 existing line in 1 file now uncovered.

18528 of 20183 relevant lines covered (91.8%)

152.68 hits per line

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

45.65
/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;
5✔
26
                return wp_kses_post( trim( stripslashes( $value ) ) );
5✔
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'] ) ) {
1✔
41
                        return $value;
1✔
42
                } else {
NEW
43
                        throw new UserError( __( 'An invalid setting value was passed.', 'graphql-for-ecommerce' ), 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 ) ) {
×
NEW
63
                        throw new UserError( __( 'An invalid setting value was passed.', 'graphql-for-ecommerce' ), 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 ) ) {
×
NEW
88
                        throw new UserError( __( 'An invalid setting value was passed.', 'graphql-for-ecommerce' ), 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 static function validate_setting_checkbox_field( $value, $setting ) {
129
                if ( in_array( $value, [ 'yes', 'no' ], true ) ) {
1✔
130
                        return $value;
1✔
131
                } elseif ( empty( $value ) ) {
×
132
                        $value = isset( $setting['default'] ) ? $setting['default'] : 'no';
×
133
                        return $value;
×
134
                } else {
NEW
135
                        throw new UserError( __( 'An invalid setting value was passed.', 'graphql-for-ecommerce' ), 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;
1✔
149
                return wp_kses(
1✔
150
                        trim( stripslashes( $value ) ),
1✔
151
                        array_merge(
1✔
152
                                [
1✔
153
                                        'iframe' => [
1✔
154
                                                'src'   => true,
1✔
155
                                                'style' => true,
1✔
156
                                                'id'    => true,
1✔
157
                                                'class' => true,
1✔
158
                                        ],
1✔
159
                                ],
1✔
160
                                wp_kses_allowed_html( 'post' )
1✔
161
                        )
1✔
162
                );
1✔
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