public static function __actionWPEnqueueScripts() { $google_fonts = array(); foreach (self::getUsedFonts() as $font) { if (isset(self::$web_safe[$font])) { continue; } else { if (($google_webfont = self::getGoogleWebfont($font)) !== false) { $variants = array(); foreach ($google_webfont['variants'] as $variant) { $variant = preg_replace('/^(regular|(italic))$/', '400\\2', $variant); if (strpos($variant, '400') === 0 || strpos($variant, '700') === 0) { $variants[] = $variant; } } $google_fonts[] = sprintf('%s:%s:%s', urlencode($google_webfont['family']), implode(',', $variants), implode(',', $google_webfont['subsets'])); } else { Theme::getInstance()->addDocumentStyle(Func::cssFontFace(Theme::getInstance()->stylesheet_dir . '/' . self::$fonts_path, Theme::getInstance()->stylesheet_uri . '/' . self::$fonts_path, $font)); } } } if (count($google_fonts) > 0) { wp_enqueue_script(Theme::getInstance()->theme->id . '-webfont', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js', array(), '1.4.7'); Theme::getInstance()->addDocumentScript(sprintf(<<<'EOS' if (typeof WebFont != 'undefined') { WebFont.load({ google: {families: %s}, active: function() { if (document.createEvent) { var e = document.createEvent('HTMLEvents'); e.initEvent('webfontactive', true, false); document.dispatchEvent(e); } else { document.documentElement['webfontactive']++; } } }); } EOS , json_encode($google_fonts))); } }