Can a theme enable a plugin?

As the title says...

I looked through the docs for Plugin Architecture and saw the options['note']. Also looked at the Theming Tutorial. Didn't see anything that would allow a theme to force a plugin to be enabled.

If there isn't such a thing, I'm guessing there's a good reason for it, right? ;-)

Thanks,
...jim

Comments

  • Themes can force plugins to be loaded by doing the `require_once` code. That could, of course, be dangerous as it might bypass the plugin's disable code. Mostly those plugins will simply disable themselves, but no guarantee.

    You can also use the `setOption('zp_plugin_'.$pluginName,$priority, false)` to temporarily enable a plugin for the duration of a HTML page rendering. $priority should be the value the plugin sets in the variable `$plugin_is_filter` variable.

    BTW, this variant of setOption allows you to set any option temporarily.
  • acrylian Administrator, Developer
    The best probably is to have a theme work generally without any plugins even if that means real basic functionality. "Progressive enhancement" so to speak. That way your site will not break if a plugin gets (suddenly) incompatible on a Zenphoto upgrade.
  • I should mention as well that there is a proscribed loading order for plugins. So a theme can really only enable Theme plugins directly. So for instance it would not likely work to have a theme enable the `zenpage` theme since all the rewrite handling would not be there when the URL was analyzed.

    Of course a custom plugin could be made to enable the other plugins or the theme option initialization could permanently enable the plugin. But with the latter there is no guarantee that the user would not disable it later.

    If what you are building is really specific to your theme perhaps it would be better to make it part of the theme scripts and/or the theme's `functions.php` script.
  • Ok, I think I understand the issues. Thanks for the explanations.

    ...jim
Sign In or Register to comment.