LESS compiler conflict with plug-in


Hi all,

With the updated Beans, I get a conflict with a plug-in that is using the same compiler for LESS (lessphp v0.4.0). I get the error message,

Fatal error: Cannot declare class lessc_parser, because the name is already in use in... [plug-in]

I'm a designer, not a real developer (which is why Beans has been so great for me, and taught me so much!) and I don't understand how to resolve this problem. I can't just stop using either Beans or the plug-in. For the moment I put the site back on the old version of Beans, but of course we want to be able to update the parent theme.

Am I missing something very basic, e.g. enabling compiling or flushing the cache in Beans settings? Or is there a way for the child theme to enqueue a slightly different version of the compiler?

Please take pity and help this lost newbie out!

Thank you!

Abigail


Hi Abigail Miller,

Beans has prefixed the main class, but in that file there are more than 3-4 other classes which will conflict with other plugins that uses the lessphp.

You can fix it in four ways:

  1. Every class should wrapped in a statement that checks if class exists. Needs a bit of coding knowledge. You will have to do this every time you update Beans (if the problem is not fixed on the next update).

  2. Download the file here lessc.php and replace with the same file in Beans theme. This is the path you can find the file /tm-beans/lib/api/compiler/vendors/lessc.php. You will have to do this every time you update Beans (if the problem is not fixed on the next update).

  3. Wait until Beans developers will fix it.

  4. Don't mess Beans with third-party plugins that makes the same job as Beans 🙂

Just making sure I understand correctly: the file you link to in 2, lessc.php, is what you describe doing in 1, wrapping each class in a if statement, yes?

The problem is, I'm still getting that same error message.

I totally hear you on waiting for Beans developers and not using annoying third-party plug-in, but it's a quite complicated website for a client who has a very different approach than I would take—nothing clean or simple about it, unfortunately.

Anyhow, thank you so much, Joseph, this is really helpful and I certainly would not have gotten this far on my own!


The problem is that lessc classes are declared more than once. In PHP you can't do that, nor for Classes nor for Functions. That's why WordPress first rule is to prefix everything.

PHP has a functions called class_exists() to prevent this 'fatal error' from happening:

// run the code only if class does not exist.
if ( ! class_exists( 'lessc_parser' ) ) :
    class lessc_parser {
        // some code here...
    }
endif;

In the file that I have sent to you, this is already done. So you just have to replace with the file in your theme, or copy all the content of this file and paste it to your file using WordPress editor, and save it. This is the path you can find your file on editor: /lib/api/compiler/vendors/lessc.php.

If you have done these steps, the error should be fixed. If the error is still showing, please make a screenshot or paste the error here.


Yes, I have followed those steps and still get the same error:

Fatal error: Cannot declare class lessc_parser, because the name is already in use in [my-url]/public_html/wp-content/plugins/bb-theme-builder/classes/class-lessc.php on line 2239


Just following up in case anyone else is curious, I asked the plug-in developer for help, and he managed to fix it by adding a prefix (i.e. beans_lessc_parser )

What I still don't understand is why this wasn't a problem previously, since Beans 1.4 was also using that less compiler.


Hi Joseph, Hi (again) Abigail,

thank you for this report and the solutions. Looks like we will have a solution in the next release.

Write a reply

Login or register to write a reply, it's free!