Code Duplication    Length = 19-33 lines in 2 locations

includes/abstracts/abstract-wc-rest-settings-api-controller.php 1 location

@@ 119-137 (lines=19) @@
116
	 * @param  string $default
117
	 * @return mixed
118
	 */
119
	public function get_value( $setting, $default = '' ) {
120
		if ( strstr( $setting, '[' ) ) { // Array value.
121
			parse_str( $setting, $setting_array );
122
			$setting = current( array_keys( $setting ) );
123
			$values  = get_option( $setting, '' );
124
			$key     = key( $setting_array[ $setting ] );
125
			$value   = isset( $values[ $key ] ) ? $values[ $key ] : null;
126
		} else { // Single value.
127
			$value = get_option( $setting, null );
128
		}
129
130
		if ( is_array( $value ) ) {
131
			$value = array_map( 'stripslashes', $value );
132
		} elseif ( ! is_null( $value ) ) {
133
			$value = stripslashes( $value );
134
		}
135
136
		return $value === null ? $default : $value;
137
	}
138
139
	/**
140
	 * Filters out bad values from the settings array/filter so we

includes/admin/class-wc-admin-settings.php 1 location

@@ 178-210 (lines=33) @@
175
	 * @param mixed $option_name
176
	 * @return string
177
	 */
178
	public static function get_option( $option_name, $default = '' ) {
179
		// Array value
180
		if ( strstr( $option_name, '[' ) ) {
181
182
			parse_str( $option_name, $option_array );
183
184
			// Option name is first key
185
			$option_name = current( array_keys( $option_array ) );
186
187
			// Get value
188
			$option_values = get_option( $option_name, '' );
189
190
			$key = key( $option_array[ $option_name ] );
191
192
			if ( isset( $option_values[ $key ] ) ) {
193
				$option_value = $option_values[ $key ];
194
			} else {
195
				$option_value = null;
196
			}
197
198
		// Single value
199
		} else {
200
			$option_value = get_option( $option_name, null );
201
		}
202
203
		if ( is_array( $option_value ) ) {
204
			$option_value = array_map( 'stripslashes', $option_value );
205
		} elseif ( ! is_null( $option_value ) ) {
206
			$option_value = stripslashes( $option_value );
207
		}
208
209
		return $option_value === null ? $default : $option_value;
210
	}
211
212
	/**
213
	 * Output admin fields.