Author: oncletom
Inheritance: extends WPPluginToolkitPlugin
 /**
  * Update custom.less stylesheet.
  */
 function presscore_generate_less_css_file($handler = 'dt-custom.less', $src = '')
 {
     /**
      * Include WP-Less.
      *
      */
     require_once PRESSCORE_EXTENSIONS_DIR . '/wp-less/bootstrap-for-theme.php';
     // WP-Less init
     if (class_exists('WPLessPlugin')) {
         $less = WPLessPlugin::getInstance();
         $less->dispatch();
     } else {
         return false;
     }
     /**
      * Less helpers.
      *
      * @since presscore 1.0.6
      */
     require_once PRESSCORE_EXTENSIONS_DIR . '/less-functions.php';
     /**
      * Less variables.
      *
      * @since presscore 0.5
      */
     if ($located_file = locate_template('inc/less-vars.php')) {
         include_once $located_file;
     }
     // $less = WPLessPlugin::getInstance();
     $config = $less->getConfiguration();
     if (!wp_style_is($handler, 'registered')) {
         if (!$src) {
             $src = PRESSCORE_THEME_URI . '/css/custom.less';
         }
         wp_register_style($handler, $src);
     }
     // save options
     $options = presscore_compile_less_vars();
     if ($options) {
         $less->setVariables($options);
     }
     $less->setImportDir(PRESSCORE_THEME_DIR . '/css');
     WPLessStylesheet::$upload_dir = $config->getUploadDir();
     WPLessStylesheet::$upload_uri = $config->getUploadUrl();
     return $less->processStylesheet($handler, true);
 }
/**
 * LESSify a stylesheet on the fly
 * 
 * <pre>
 * <head>
 *  <title><?php wp_title() ?></title>
 *  <link rel="stylesheet" media="all" type="text/css" href="<?php echo wp_lessify(get_bloginfo('template_dir').'/myfile.less') ?>" />
 * </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_lessify($stylesheet_uri, $cache_key = null, $version_prefix = '?ver=')
{
    static $wp_less_uri_cache;
    $cache_key = 'wp-less-' . ($cache_key === '' ? md5($stylesheet_uri) : $cache_key);
    if (is_null($wp_less_uri_cache)) {
        $wp_less_uri_cache = array();
    }
    if (isset($wp_less_uri_cache[$cache_key])) {
        return $wp_less_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 = WPLessPlugin::getInstance()->processStylesheet($cache_key);
    wp_deregister_style($cache_key);
    $wp_less_uri_cache[$cache_key] = $stylesheet->getTargetUri();
    unset($stylesheet);
    return $wp_less_uri_cache[$cache_key];
}
/**
 * Register escape function in lessphp.
 *
 */
function presscore_register_escape_function_for_lessphp()
{
    if (!class_exists('WPLessPlugin') || !function_exists('presscore_lessphp_escape')) {
        return;
    }
    $less = WPLessPlugin::getInstance();
    $less->registerFunction('escape', 'presscore_lessphp_escape');
}
Example #4
0
<?php

if (class_exists('WPLessPlugin')) {
    $less = WPLessPlugin::getInstance();
    $options = get_option(AZEXO_THEME_NAME);
    if (isset($options['brand-color'])) {
        $less->addVariable('brand-color', $options['brand-color']);
    }
    if (isset($options['accent-1-color'])) {
        $less->addVariable('accent-1-color', $options['accent-1-color']);
    }
    if (isset($options['accent-2-color'])) {
        $less->addVariable('accent-2-color', $options['accent-2-color']);
    }
}
Example #5
0
function azexo_styles()
{
    wp_register_style('animate-css', get_template_directory_uri() . '/css/animate.css/animate.min.css');
    wp_enqueue_style('animate-css');
    wp_register_style('font-awesome', get_template_directory_uri() . '/css/font-awesome.min.css');
    wp_enqueue_style('font-awesome');
    wp_register_style('themify-icons', get_template_directory_uri() . '/css/themify-icons.css');
    wp_enqueue_style('themify-icons');
    $less = WPLessPlugin::getInstance();
    $less->dispatch();
    wp_enqueue_style('azexo', get_template_directory_uri() . '/less/' . azexo_get_skin() . '/azexo.less');
    wp_register_style('nwm', get_template_directory_uri() . '/css/nwm.css');
    wp_enqueue_style('nwm');
}
Example #6
0
 /**
  *
  * Parse and register less file and convert it to css
  *
  * @param string $handler
  * @param string $src      css file source
  * @param array  $deps
  * @param bool   $version
  * @param string $media
  * @param bool   $compress the file should by compressed
  *
  * @return mixed
  * @throws Exception
  * @access public
  */
 public function registerStylesheetsTemplates($handler = 'custom.less', $src = '', array $deps = array(), $version = false, $media = 'all', $compress = false)
 {
     if (class_exists('\\WPLessPlugin')) {
         $less = \WPLessPlugin::getInstance();
         $less->dispatch();
         // we’re done, everything works as if the plugin is activated
         $less_config = $less->getConfiguration();
         $less_config->setUploadDir($this->upload_dir);
         $less_config->setUploadUrl($this->upload_url);
         $css_uri = FileSystem::getDirectory('css_uri');
         $less->setImportDir(array($css_uri . 'less'));
         $less_variable = $this->variables;
         $less->setVariables($less_variable);
         \Less_Parser::$default_options['compress'] = $compress;
         //\Less_Parser::$default_options['cache_method'] = 'serialize';
         \WPLessStylesheet::$upload_dir = $less_config->getUploadDir();
         \WPLessStylesheet::$upload_uri = $less_config->getUploadUrl();
         if (!wp_style_is($handler, 'registered')) {
             if (!$src) {
                 $src = $css_uri . 'less/style.less';
             }
             wp_register_style($handler, $src, $deps, $version, $media);
             wp_enqueue_style($handler);
         }
         return $less->processStylesheet($handler, true);
     } else {
         throw new Exception(Translate::translate('WP-Less plugin not found.'));
     }
 }