/** * Register Stylesheets templates files * * @param string $handle handle name * @param string $src path to stylesheets template file * @param array $dep An array of registered style handles this stylesheet depends on. Default empty array. * @param string|bool $ver String specifying the stylesheet version number. Used to ensure that the correct version * is sent to the client regardless of caching. Default 'false'. Accepts 'false', 'null', or 'string'. * @param string $media Optional. The media for which this stylesheet has been defined. * Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print', * 'screen', 'tty', or 'tv'. * @param bool|false $compress compress the target file * * @return WPScssStylesheet * @throws Exception */ protected function registerStylesheetsTemplates($handle, $src, array $dep = array(), $ver = false, $media = 'all', $compress = false) { if (class_exists('\\WPScssPlugin')) { $WPScssPlugin = \WPScssPlugin::getInstance(); $WPScssPlugin->dispatch(); $this->configDirs($WPScssPlugin); $variable = $this->variables; $WPScssPlugin->setVariables($variable); $WPScssPlugin->getCompiler()->setFormatter('scss_formatter_compressed'); if (!wp_style_is($handle, 'registered')) { wp_register_style($handle, $src, $dep, $ver, $media); wp_enqueue_style($handle); } return $WPScssPlugin->processStylesheet($handle, true); } else { throw new Exception(Translate::translate('Plugin WPScssPlugin not found!')); } }
/** * SCSSify a stylesheet on the fly * * <pre> * <head> * <title><?php wp_title() ?></title> * <link rel="stylesheet" media="all" type="text/css" href="<?php echo wp_scssify(get_bloginfo('template_dir').'/myfile.scss') ?>" /> * </head> * </pre> * * @todo hook on WordPress cache system * @author oncletom * @since 1.2 * @version 1.0 * @param string $stylesheet_uri * @param string $cache_key * @param string $version_prefix * @return string processed URI */ function wp_scssify($stylesheet_uri, $cache_key = null, $version_prefix = '?ver=') { static $wp_scss_uri_cache; $cache_key = 'wp-scss-' . ($cache_key === '' ? md5($stylesheet_uri) : $cache_key); if (is_null($wp_scss_uri_cache)) { $wp_scss_uri_cache = array(); } if (isset($wp_scss_uri_cache[$cache_key])) { return $wp_scss_uri_cache[$cache_key]; } /* * Register a fake stylesheet to make the process possible * It relies on a _WP_Dependency object */ wp_register_style($cache_key, $stylesheet_uri); $stylesheet = WPScssPlugin::getInstance()->processStylesheet($cache_key); wp_deregister_style($cache_key); $wp_scss_uri_cache[$cache_key] = $stylesheet->getTargetUri(); unset($stylesheet); return $wp_scss_uri_cache[$cache_key]; }