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

wp-graphql / wp-graphql-woocommerce / 27386231983

12 Jun 2026 12:25AM UTC coverage: 91.791%. Remained the same
27386231983

Pull #1019

github

web-flow
Merge 46a421a18 into 01876f534
Pull Request #1019: fix: address WordPress.org plugin review (rename + prefixing + headers)

1327 of 1584 new or added lines in 200 files covered. (83.78%)

1 existing line in 1 file now uncovered.

18505 of 20160 relevant lines covered (91.79%)

151.6 hits per line

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

94.34
/includes/mutation/class-settings-update.php
1
<?php
2
/**
3
 * Mutation - updateWCSettings
4
 *
5
 * Registers mutation for batch updating WooCommerce settings within a group.
6
 *
7
 * @package WPGraphQL\WooCommerce\Mutation
8
 * @since   1.0.0
9
 */
10

11
namespace WPGraphQL\WooCommerce\Mutation;
12

13
use GraphQL\Error\UserError;
14

15
/**
16
 * Class Settings_Update
17
 */
18
class Settings_Update {
19
        /**
20
         * Registers mutation
21
         *
22
         * @return void
23
         */
24
        public static function register_mutation() {
25
                register_graphql_mutation(
296✔
26
                        'updateWCSettings',
296✔
27
                        [
296✔
28
                                'inputFields'         => self::get_input_fields(),
296✔
29
                                'outputFields'        => self::get_output_fields(),
296✔
30
                                'mutateAndGetPayload' => self::mutate_and_get_payload(),
296✔
31
                        ]
296✔
32
                );
296✔
33
        }
34

35
        /**
36
         * Defines the mutation input field configuration
37
         *
38
         * @return array
39
         */
40
        public static function get_input_fields() {
41
                return [
296✔
42
                        'group'    => [
296✔
43
                                'type'        => [ 'non_null' => 'String' ],
296✔
44
                                'description' => static function () {
296✔
45
                                        return __( 'Settings group ID.', 'graphql-for-ecommerce' );
2✔
46
                                },
296✔
47
                        ],
296✔
48
                        'settings' => [
296✔
49
                                'type'        => [ 'non_null' => [ 'list_of' => 'WCSettingInput' ] ],
296✔
50
                                'description' => static function () {
296✔
51
                                        return __( 'Settings to update.', 'graphql-for-ecommerce' );
2✔
52
                                },
296✔
53
                        ],
296✔
54
                ];
296✔
55
        }
56

57
        /**
58
         * Defines the mutation output field configuration
59
         *
60
         * @return array
61
         */
62
        public static function get_output_fields() {
63
                return [
296✔
64
                        'settings' => [
296✔
65
                                'type'        => [ 'list_of' => 'WCSetting' ],
296✔
66
                                'description' => static function () {
296✔
67
                                        return __( 'The updated settings.', 'graphql-for-ecommerce' );
2✔
68
                                },
296✔
69
                                'resolve'     => static function ( $payload ) {
296✔
70
                                        return $payload['settings'];
1✔
71
                                },
296✔
72
                        ],
296✔
73
                ];
296✔
74
        }
75

76
        /**
77
         * Defines the mutation data modification closure.
78
         *
79
         * @return callable
80
         */
81
        public static function mutate_and_get_payload() {
82
                return static function ( $input ) {
296✔
83
                        if ( ! \wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
1✔
NEW
84
                                throw new UserError( __( 'Sorry, you cannot update settings.', 'graphql-for-ecommerce' ) );
×
85
                        }
86

87
                        $group_id   = $input['group'];
1✔
88
                        $controller = new \WC_REST_Setting_Options_Controller();
1✔
89
                        $updated    = [];
1✔
90

91
                        foreach ( $input['settings'] as $setting_input ) {
1✔
92
                                $setting_id = $setting_input['id'];
1✔
93
                                $value      = $setting_input['value'];
1✔
94

95
                                /** @var array|\WP_Error $setting */
96
                                $setting = $controller->get_setting( $group_id, $setting_id );
1✔
97
                                if ( is_wp_error( $setting ) ) {
1✔
98
                                        throw new UserError( $setting->get_error_message() );
×
99
                                }
100

101
                                $validated = Setting_Update::validate_value( $value, $setting );
1✔
102
                                Setting_Update::save_setting( $setting, $validated );
1✔
103

104
                                /** @var array|\WP_Error $refreshed */
105
                                $refreshed = $controller->get_setting( $group_id, $setting_id );
1✔
106
                                if ( is_wp_error( $refreshed ) ) {
1✔
107
                                        throw new UserError( $refreshed->get_error_message() );
×
108
                                }
109

110
                                $updated[] = $refreshed;
1✔
111
                        }
112

113
                        return [ 'settings' => $updated ];
1✔
114
                };
296✔
115
        }
116
}
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