Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

[v1.8 Github latest] How to enable by default plugin

+3 votes
239 views
asked Apr 15, 2017 in Plugins by ProThoughts

@Scott, I would like to enable by default sitemap plugin....similar to WYSIWYG Editor plugin(which can not be disabled), how to enable that? Thanks!

Q2A version: 1.8 Github latest

3 Answers

+3 votes
answered Apr 18, 2017 by JackSiro

Okay I have taken considerable amount of time to examine the issue because for me it was not a bother at all till I saw your question. When I look at the metadata of Xml Site Plugin verses that of WYSIWYG Editor plugin I see the reason why you see this situation. I installed one of my plugin and saw it getting enabled which I cant disable which I found intresting. Okay the plugin manager checks if a plugin has a "load_order" in its metadata. If it doesn't have like the case of the WYSIWYG Editor plugin it enabled status is true and permanent (can't be changed).

In summary:

  1. Disabling a plugin is not optional when
    • load_order is set to before_db_init in the plugin's metadata
    • or load_order is not set at all in the plugin's metadata
    • or plugin is missing metadata which is the case with most plugins.
  2. Enabling/Disabling a plugin is optional only when
    • load_order is set to after_db_init in the plugin's metadata.

To prove this: add the following line in xml-site-plugin's metadata

,"load_order": "before_db_init"

then reload Plugin's page. 

Conclusion:
sitemap plugin can not be enabled by default.

commented Feb 7 by q2apro
Also check before_db_init etc. at http://docs.question2answer.org/plugins/
commented Feb 8 by ProThoughts
Thanks q2apro. I will read that again.
+1 vote
answered Apr 18, 2017 by sama55
It may be backward compatibility issue.
commented Apr 19, 2017 by ProThoughts
Not sure, I'm checking on fresh installation of v1.8.
commented Apr 19, 2017 by JackSiro
am not sure on that too. Please Check the PluginManager class under "qa-include/Q2A/Plugin/PluginManager.php for more details
commented Apr 19, 2017 by sama55
Plugin switch feature must also work properly with old (There is no "load_order") plugins. It is correct to enable plugins which "load_order" is not defined just after upgrading operation. However, it is incorrect to disable at the same time. Currently, we can not disable and re-enable old plugins. This is the backward compatibility issue I point out. Anyway, it will be necessary to change program specifications (basic archtecture).
+1 vote
answered Feb 7 by pupi1985

I've just seen this and it seems you still haven't solved the issue. I bet you have updated the metadata.json file and then replaced the file with a new Q2A release so the changes got lost. In order not to rely on having to modify core files you can just do what Q2A does in order to remember the enabled plugins.

1. Enable all the plugins you want to have enabled

2. Run this query against the database:

SELECT content FROM ^options WHERE title = 'enabled_plugins';

The output should look like this (note the xml-sitemap plugin will be there):

basic-adsense;event-logger;example-page;facebook-login;mouseover-layer;opensearch-support;recaptcha-captcha;tag-cloud-widget;wysiwyg-editor;xml-sitemap

3. Configure that string to be applied to the enabled_plugins key of the options table after initialization. For example, you could do something like this:

qa_opt('enabled_plugins', 'basic-adsense;event-logger;example-page;facebook-login;mouseover-layer;opensearch-support;recaptcha-captcha;tag-cloud-widget;wysiwyg-editor;xml-sitemap');

If this works after the first refresh or after the second will depend on how you reset your site.

commented Feb 8 by ProThoughts
@pupi1985, thanks for the detail explanation, will try this.
...