Skip to content

Instantly share code, notes, and snippets.

@campusboy87
Created November 20, 2018 19:51
Show Gist options
  • Select an option

  • Save campusboy87/bd93a170ec348f3df560cf70ffb3b478 to your computer and use it in GitHub Desktop.

Select an option

Save campusboy87/bd93a170ec348f3df560cf70ffb3b478 to your computer and use it in GitHub Desktop.
<?php
function cr_get_data_crypto( $type = '', $symbol = '' ) {
$symbol = $symbol ? $symbol : cr_get_crypto_symbol();
$cache_key = $symbol . '-coinsnapshot';
$data = wp_cache_get( $cache_key );
if ( $symbol && false === $data ) {
$file = CRYPT_REVIEWS_PATH . "data-import/coins/$symbol-coinsnapshot.json";
$data = is_file( $file ) ? json_decode( file_get_contents( $file ) ) : [];
// Сохраняем данные в кеш
wp_cache_set( $cache_key, $data );
}
if ( empty( $data->Data ) || ! $data = $data->Data ) {
return '';
}
foreach ( explode( '/', $type ) as $key ) {
$data = isset( $data->{$key} ) ? $data->{$key} : '';
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment