Plugin activation/deactivation depending on selected theme Plugin activation/deactivation depending on selected theme
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Plugin activation/deactivation depending on selected theme

Started by paquets, November 28, 2008, 06:27:01 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

paquets

Hi,

I'm a coppermine newbie so please bare with me. I was wondering if there is any way to deactivate all plugins on a CPG installation when a specific theme is selected. This while the plugins remain active with other themes.

Is that possible at all?

Thanks!

Paver

If you're willing to add a hack, then it's possible.  It's not possible otherwise (not possible by modifying the themes or adding another plugin).  You can modify a plugin to look for a particular theme before implementing certain functions.  I have done that in a plugin I use on my family site.  But changing all the plugins you use is not feasible and makes it very difficult for upgrades.

The hack would actually be fairly simple I think (unless I'm ignoring some side effects).   Look for the following lines in include/init.inc.php:
// Include plugin API
require('include/plugin_api.inc.php');
if ($CONFIG['enable_plugins'] == 1) {
        CPGPluginAPI::load();
}

This loads all the activated plugins.  So to disable this for certain themes, add in checks on $CONFIG['theme'] for the admin-set theme or $USER['theme'] for the user-set theme.  So to disable the plugins for theme 'snowy_day', do something like this:
if (($CONFIG['enable_plugins'] == 1) && ($USER['theme'] != 'snowy_day')) {
        CPGPluginAPI::load();
}


But there's one major problem you have to address.  $CONFIG['theme'] and $USER['theme'] are not set until later on in init.inc.php.  So you would have to move or replicate this code.  I haven't looked into this yet and don't have time right now, so decide if you want a hack first and then you'll have to see if you can move the plugin loading code down below where $USER['theme'] is set.

I would add a comment in or make a list somewhere of hacks so that when you upgrade Coppermine, you can apply the hack to the new version.  (You have to do this unless you use the SVN repository for upgrades.)

Joachim Müller

I suggest you explain why you want this to be done - your initial request appears to be strange. Explain what you're actually trying to accomplish or what you have issues with - maybe we could suggest an altogether different solution that you haven't been thinking of yet.

paquets

Thanks Paver and Joachim,

The reason I'm asking for this is for implementing CuMin (an iPhone-friendly theme) on a Coppermine installation. In trying it, I noticed that plugins came in the way of letting that theme work properly. For instance, I had "Add thumbnails to Lightbox v1.2.3" installed and it conflicted with the theme. I disabled it and the theme worked fine thereafter. Since plugins are great, but bring extra weight and complexity to a Coppermine installation, my thinking is that for the iPhone, it would be better to have a lighter version of the same site, just for viewing, not adding comments, notes, etc... Now, I don't know if this is feasible at all. ???

That said, and if it's possible to do, to be able to remove plugins in specific sites could be useful not just for mobile platforms, thus having this request as a separate forum thread...

I've tried what Paver suggested but it did not work. Unfortunately I'm not enough of a coder to figure it out by myself. I tried moving and also adding the code further down in the include/init.inc.php file and it didn't work either.

Any ideas?

Thanks!

Paver

That's a good example of a reason to disable plugins for a particular theme: the "Add thumbnails to Lightbox" plugin implements a theme function that if the theme uses, you get an error.  This plugin tries to avoid filtering the page which has its own issues (assuming a certain output from the theme engine and being very CPU-intensive in some cases).

So the non-hack way of getting what you want is to remove this plugin completely and then modify your CuMin theme to remove links to the comments, etc. that you don't want to show up.

To hack what you want, start from the original include/init.inc.php.  If you're not sure what the original is, download a new copy of the CPG package, unzip it to a temporary directory, then copy the include/init.inc.php to your webserver overwriting the one there.

Then replace these lines:
// Include plugin API
require('include/plugin_api.inc.php');
if ($CONFIG['enable_plugins'] == 1) {
        CPGPluginAPI::load();
}

with these lines:
// Include plugin API
require('include/plugin_api.inc.php');
// HACK BEGIN - need to copy and apply to upgraded installations
// original lines
/*
if ($CONFIG['enable_plugins'] == 1) {
        CPGPluginAPI::load();
}
*/
// new lines
user_get_profile();
if (!empty($_GET['theme'])) {
    $USER['theme'] = $_GET['theme'];
}
$hack_theme_noplugins = 'fruity';
$hack_load_plugins = (($USER['theme'] != $hack_theme_noplugins) && ($CONFIG['theme'] != $hack_theme_noplugins)) ;
if (($CONFIG['enable_plugins'] == 1) && $hack_load_plugins) {
        CPGPluginAPI::load();
}
// to remove this hack, uncomment the original lines and comment/remove the new lines
// HACK END

In the replaced lines, replace 'fruity' in the variable $hack_theme_noplugins with your theme to disable plugins.

You can see I added some comments in the hacked lines so you can remove the hack or apply it to future upgrades.

paquets