Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot register LESS variables using document method in version 1.7+ #63

Closed
thewebists opened this issue Sep 14, 2014 · 4 comments
Closed

Comments

@thewebists
Copy link

In the new version of the plugin @fabrizim has set the compiler to initalize at 'init' priority 1, however the documented method for registering variables uses the functions.php file, which is executed BEFORE the 'init' action in the page life-cycle.

This results in the following error:

Fatal error: Call to a member function setVariables() on a non-object in /bedrock/web/app/plugins/wp-less/lib/Plugin.class.php on line 319

The solution was to call the variable registration with a hook after the init@1:

add_action('init', 'tws_redux_to_less_vars', 2); // The WP-LESS compiler is instantiated in 'init' priority 1.

function tws_redux_to_less_vars() {
    // Pass LESS variables from reduxlessvars option to the LESS plugin class
    if (class_exists('WPLessPlugin')){
        $less = WPLessPlugin::getInstance();
        $less->setVariables(get_option('reduxlessvars'));
    }
}

I think the plugin documentation needs to be updated to reflect this. I have a feeling other plugin components (e.g. function registration) might face a similar issue.

@thom4parisot
Copy link
Owner

Oh blimey :-(

I think we can change the code to instantiate the loader as soon as possible, and keep the same priority for hooks to avoid this "race condition". It would avoid everybody to update their themes.

@fabrizim any input on this?

@thewebists
Copy link
Author

Good point about the existing user-base. +1 for reverting to loading the compiler during the plugin init.

@fabrizim
Copy link
Collaborator

Hey guys-
Reverting back to loading during plugin initialization would revert the ability to change compilers. I just changed the code to initialize the compiler on demand instead of specifically in the "init" hook or during the plugin initialization. That way, it will remain backwards compatible and also allow for themes to change compilers using the new 'wp_less_compiler' filter.

@thom4parisot
Copy link
Owner

Thanks @fabrizim :-) Published as v1.7.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants