Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
439 views
in Plugins by
Is there an order by which plugins are loaded in Q2A? If not then can it be loaded in alphabetical order in future - will make it easier to write plugins which depends on others - for example multiple plugins modifying q_list() function.
Q2A version: 1.8.0

1 Answer

+4 votes
by
selected by
 
Best answer

Strictly answering your question, plugins are loaded from the filesystem in this line. This applies to Q2A 1.8+. It uses the PHP glob function, which seems to rely on the operating system implementation to return sorted results. In my Debian Stretch they are returned in a case-sensitive alphabetical order and I guess that will be the same for most *nix-based operating systems.

It really took a lot of effort to move the logic from the old procedural way that was spread in global functions into a somewhat decently readable class that was also backwards compatible. So the way it is now is already quite good compared to v1.7.5. In fact, if you want a different sorting, you can tweak it right there, after that line.

Having said so, I agree on the plugin order issue. Although it is unlikely that two or more plugins require swapping the execution order... it can happen. Developers can take actions to make the code more compatible and decrease the chance for this to happen but still, this situation is possible.

The thing is that forcing alphabetical order on the plugin directories is a no-go. That is not user friendly, cannot be done without accessing the filesystem and, sometimes, it is impossible, as some plugins have a hardcoded directory path. As no plugin can know if it should be executed before or after the rest, I think the only way is for the user to configure the execution order based on the plugins they use: sorting them in the admin/plugins page manually.

And I've been trying to avoid plugin dependencies which might be quite related to this but let's leave that for another time :)

by
Thank you pupi. I was expecting something similar. My problem is with q_list function. In Mouseover Layer plugin this function is overridden to add "title" tag to the question lists. And I have my own plugin which addends a portion of the question description to the "Question TITLE" field. So, I want the action of my plugin to happen first and then the Mouse Over Layer plugin. Is there any way to do this?
by
I think changing the plugin folder name should do it. However, you can also override a different theme method in your own plugin that gets executed before q_list (you can even use the initialize method)
by
Thank you :) Renaming didnt work for some reason but alternate theme function worked perfectly. q_list_and_form() is the one.
by
I think plugins should load with the order the developer define. Same like add_action( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 ) in WordPress. So they can overcome with the conflict of priority. Probably can be done by defining number while registering plugin or autoload might works too. I know it is not as easy as we write here but this is one of the important point to improve.
by
Here I've explained why that is not the best approach: https://www.question2answer.org/qa/71487/question-direct-question-instead-correspondant-question?show=71851#c71851

Each Q2A installation is different so the plugin order execution will have to be determined in a per-installation basis. Even doing so, plugins may still conflict
...