From b665f5e1c60fa75e9aa342cd704a55890f3075f7 Mon Sep 17 00:00:00 2001 From: Justin Shreve Date: Wed, 7 Sep 2016 15:24:04 -0700 Subject: [PATCH] Setting IDs do not need to be unique across the entire system.. just the group. --- ...ss-wc-rest-settings-options-controller.php | 2 +- tests/unit-tests/api/settings.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/includes/api/class-wc-rest-settings-options-controller.php b/includes/api/class-wc-rest-settings-options-controller.php index 9557d24c114..4e466b2d76f 100644 --- a/includes/api/class-wc-rest-settings-options-controller.php +++ b/includes/api/class-wc-rest-settings-options-controller.php @@ -139,7 +139,7 @@ class WC_REST_Settings_Options_Controller extends WC_REST_Controller { // Get the option value if ( is_array( $option_key ) ) { $option = get_option( $option_key[0] ); - $setting['value'] = $option[ $option_key[1] ]; + $setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : ''; } else { $setting['value'] = WC_Admin_Settings::get_option( $option_key ); } diff --git a/tests/unit-tests/api/settings.php b/tests/unit-tests/api/settings.php index 03a56ec4c03..31a7ae7b9e5 100644 --- a/tests/unit-tests/api/settings.php +++ b/tests/unit-tests/api/settings.php @@ -603,6 +603,29 @@ class Settings extends WC_REST_Unit_Test_Case { 'tip' => 'This controls the email subject line. Leave blank to use the default subject: [{site_title}] New customer order ({order_number}) - {order_date}.', 'value' => 'This is my subject', ), $setting ); + + // test updating another subject and making sure it works with a "similar" id + $request = new WP_REST_Request( 'GET', sprintf( '/wc/v1/settings/%s/%s', 'email_customer_new_account', 'subject' ) ); + $response = $this->server->dispatch( $request ); + $setting = $response->get_data(); + + $this->assertEmpty( $setting['value'] ); + + // test update + $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v1/settings/%s/%s', 'email_customer_new_account', 'subject' ) ); + $request->set_body_params( array( + 'value' => 'This is my new subject', + ) ); + $response = $this->server->dispatch( $request ); + $setting = $response->get_data(); + + $this->assertEquals( 'This is my new subject', $setting['value'] ); + + // make sure the other is what we left it + $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v1/settings/email_new_order/subject' ) ); + $setting = $response->get_data(); + + $this->assertEquals( 'This is my subject', $setting['value'] ); } }