WC_CLI_REST_Command::decode_json()protectedWC 1.0

JSON can be passed in some more complicated objects, like the payment gateway settings array. This function decodes the json (if present) and tries to get it's value.

Method of the class: WC_CLI_REST_Command{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->decode_json( $arr );
$arr(array) (required)
Array that will be scanned for JSON encoded values.

WC_CLI_REST_Command::decode_json() code WC 8.7.0

protected function decode_json( $arr ) {
	foreach ( $arr as $key => $value ) {
		if ( '[' === substr( $value, 0, 1 ) || '{' === substr( $value, 0, 1 ) ) {
			$arr[ $key ] = json_decode( $value, true );
		} else {
			continue;
		}
	}
	return $arr;
}