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

wp-graphql / wp-graphql-woocommerce / 23661591439

27 Mar 2026 06:30PM UTC coverage: 89.39% (+0.2%) from 89.165%
23661591439

Pull #1002

github

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

575 of 643 new or added lines in 21 files covered. (89.42%)

15806 of 17682 relevant lines covered (89.39%)

140.84 hits per line

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

93.62
/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   TBD
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(
277✔
26
                        'updateWCSettings',
277✔
27
                        [
277✔
28
                                'inputFields'         => self::get_input_fields(),
277✔
29
                                'outputFields'        => self::get_output_fields(),
277✔
30
                                'mutateAndGetPayload' => self::mutate_and_get_payload(),
277✔
31
                        ]
277✔
32
                );
277✔
33
        }
34

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

53
        /**
54
         * Defines the mutation output field configuration
55
         *
56
         * @return array
57
         */
58
        public static function get_output_fields() {
59
                return [
277✔
60
                        'settings' => [
277✔
61
                                'type'        => [ 'list_of' => 'WCSetting' ],
277✔
62
                                'description' => __( 'The updated settings.', 'wp-graphql-woocommerce' ),
277✔
63
                                'resolve'     => static function ( $payload ) {
277✔
64
                                        return $payload['settings'];
1✔
65
                                },
277✔
66
                        ],
277✔
67
                ];
277✔
68
        }
69

70
        /**
71
         * Defines the mutation data modification closure.
72
         *
73
         * @return callable
74
         */
75
        public static function mutate_and_get_payload() {
76
                return static function ( $input ) {
277✔
77
                        if ( ! \wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
1✔
NEW
78
                                throw new UserError( __( 'Sorry, you cannot update settings.', 'wp-graphql-woocommerce' ) );
×
79
                        }
80

81
                        $group_id   = $input['group'];
1✔
82
                        $controller = new \WC_REST_Setting_Options_Controller();
1✔
83
                        $updated    = [];
1✔
84

85
                        foreach ( $input['settings'] as $setting_input ) {
1✔
86
                                $setting_id = $setting_input['id'];
1✔
87
                                $value      = $setting_input['value'];
1✔
88

89
                                /** @var array|\WP_Error $setting */
90
                                $setting = $controller->get_setting( $group_id, $setting_id );
1✔
91
                                if ( is_wp_error( $setting ) ) {
1✔
NEW
92
                                        throw new UserError( $setting->get_error_message() );
×
93
                                }
94

95
                                $validated = Setting_Update::validate_value( $value, $setting );
1✔
96
                                Setting_Update::save_setting( $setting, $validated );
1✔
97

98
                                /** @var array|\WP_Error $refreshed */
99
                                $refreshed = $controller->get_setting( $group_id, $setting_id );
1✔
100
                                if ( is_wp_error( $refreshed ) ) {
1✔
NEW
101
                                        throw new UserError( $refreshed->get_error_message() );
×
102
                                }
103

104
                                $updated[] = $refreshed;
1✔
105
                        }
106

107
                        return [ 'settings' => $updated ];
1✔
108
                };
277✔
109
        }
110
}
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