• sheershoff

    (@sheershoff)


    Чтобы разработчикам было веселее и они могли использовать забранный вашим плагином курс в других местах в WP – предлагаю добавить следующее:

    /**
     * Последний курс из кеша, либо false, если курса для $code не найдено.
     * @param string $code Одно из 'USD','EUR','GBP','BYR','CNY','JPY'
     * @return boolean|float Курс, либо false
     */
    function cbrrate_current_rate($code){
        $limit=12;
        $i=0;
        $codes = array('USD','EUR','GBP','BYR','CNY','JPY');
        if(!in_array($code, $codes)){
            return false;
        }
    
        do {
            $curtime = mktime(0,0,0,date("m"),date("d")-$i+1,date("Y"));
            $date = date("d.m.Y",$curtime);
            $test = cbr_cache_get($code.'_'.$curtime);
            if ($test && $test>0){
                $current = cbr_cache_get($code.'_'.$curtime);
            }
            if (++$i > $limit) break;
        } while(empty($current));
    
        if (empty($current)){
            return false; //"data empty ";
        } else {
            return $current;
        }
    }

    https://wordpress.org/plugins/cbrrate/

  • The topic ‘Предложение добавить функцию (код внутри)’ is closed to new replies.