WC_CLI_REST_Command::decode_json │ protected │ WC 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 its value.

Метод класса: WC_CLI_REST_Command{}

Хуков нет.

Возвращает

array.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->decode_json( $arr );
$arr(массив) (обязательный)
Array that will be scanned for JSON encoded values.

Код WC_CLI_REST_Command::decode_json() WC 11.3.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;
}