WP-Less,Less和PhpStorm编译

时间:2016-10-12 14:06:13

标签: php wordpress less redux

我使用Redux框架创建wp主题,WP-Less用于编译LESS中的样式。在PhpStorm工作。

现在,我想从Redux动态更改一些颜色并将它们传递给我的main style.less文件,该文件将在style.css中编译。

问题是,当我想加载我的CSS时,我需要使用

来做
wp_enqueue_style('my-style', get_stylesheet_uri());

但它只加载css,而不是我的文件。在我的functions.php文件中,我定义了我的变量。

add_filter('less_vars', 'my_less_vars', 10, 2);

function my_less_vars($ vars,$ handle) {

Redux::init('redux_qmakeup');

global $redux_qmakeup;
if (isset($redux_qmakeup['opt-typography']['font-family'])) {
    $font_name = $redux_qmakeup['opt-typography']['font-family'];
} else {
    $font_name = 'Montserrat';
}
if (isset($redux_qmakeup['opt-typography']['color'])) {
    $font_color = $redux_qmakeup['opt-typography']['color'];
} else {
    $font_color = '#d6451e';
}
if (isset($redux_qmakeup['opt-color-footer'])) {
    $footer_color = $redux_qmakeup['opt-color-footer'];
} else {
    $footer_color = '#414243';
}

// $handle is a reference to the handle used with wp_enqueue_style()
$vars["font-family"] = "'$font_name'";
$vars["font-color"] = "$font_color";

$vars["footer-color"] = "$footer_color";

return $vars; }

在WP-LESS文档中,它说我现在可以在我的.less文件中使用@ footer-color,而PhpStorm会自动编译它。但它不会,因为我的@ footer-color没有定义,所以编译被破坏了。如果我将它定义为一个空的var,它将不会采用我的redux颜色,但将保留该空变量。

1 个答案:

答案 0 :(得分:0)

您正在使用WordPress过滤器add_filter(' less_vars',' my_less_vars',10,2);添加较少的变量。

我使用Netbeans,我确定它在PhpStorm中是一样的。 Netbeans编译器不能使用WP过滤器,就这么简单。您不能使用PhpStorm编译器进行编译,除非所有变量都是用较少的文件编写的。

一种解决方案是仅在较少的文件或变量(在更改与之相关的主题选项后更改)中使用WP-LESS编译文件。

希望这会有所帮助:)