Hi,
I installed the plugin 1.0 version but I saw the modification to prevent overwriting the settings when Wordpress Multisite gets updated isn't in that version. If I would install the plugin on a multisite and afterwords I update the Wordpress version the default settings of pto_default.php get into every subsite of wordpress multisite what you don't want to.
You proposed the following solution during the beta:
Re-upgrading deactivating and re-activating all plugins, one solution I think would be to modify the install (activate) and uninstall (deactive) functions in pto.php so that settings are only deleted on uninstall, and created on install IF pto_default.php exists. So, once you have set-up your master settings and created a master pto_default.php, after activating the plugin for the first time you can then delete pto_default.php which will have the effect of preserving setting across any de-activate re-active cycle.
See also: http://www.pricetapestry.org/node/82
Could you put that in the next version of the plugin so it won't get overwritten when the plugin gets updated.
Hi,
No problem, I discovered it in time. I have a problem with the modified code and V1.
I exported pto_default.php and wanted to import it on another blog. So I placed pto_default.php in there and deactivated the plugin on that specific blog and reactivated it but the settings from pto_default.php aren't loaded?
I used the code modification with 1.0 code.
I tested it with the unmodified v1.0 and then the settings are loaded.
Could you take a look at the modification?
Hi,
I was wondering if there could be a more elegant solution?
I activated the plugin on a new subsite of my multisite and then I get this message:
Plugin could not be activated because it triggered a fatal error.
Warning: require(pto_default.php) [function.require]: failed to open stream: No such file or directory in /.../public_html/wp-content/plugins/pto/pto.php on line 35
Fatal error: require() [function.require]: Failed opening required 'pto_default.php' (include_path='.../public_html/wp-content/plugins/pto/pto.php on line 35
I forgot that I renamed the pto_default.php to prevent overwriting all subsite settings when updating the plugin or updating multisite.
Is it possible to have something like: "use custom settings (subsite specific) it its there and otherwise use default settings combined with a 'reset to defaults button'" ?
Hi Marco,
I thought we had modified your pto.php so as to check if pto_default.php exists - but this looks like that modification is no longer in place. Could you email me your latest pto.php and I'll check / re-introduce that mod for you...
For the next update of PriceTapestry.org for WordPress i'm planning to add Import / Export settings as per the Joomla version which is certainly a more elegant solution!
Cheers,
David
--
PriceTapestry.com
The mod is in there. It works, but if I forget to place it back so I get the error. No problems with that.
I just wanted to say to you that the mod as it is, is a bit risky. For example if I upgrade the plugin by placing a new copy and forget to rename pto_default it overwrites the subsites settings when activating it.
So I was bringing to your attention that a solution where the plugin gives you a choice to use the existing custom settings or go back to the 'default' standard settings. It's a bit more than Import/Export settings (though that is a very nice feature). I think the custom settings should have preference above the 'default'
Thanks.
Hi Marco,
I have been looking into this and I think the solution is 2-part. Firstly, the current distribution incorrectly hooks pto_uninstall into the plugin deactivation process. This should actually be hooked into the uninstall process which can be corrected as follows: Look for the following code at line 84 of pto.php
register_deactivation_hook(__FILE__, 'pto_uninstall');
...and REPLACE with:
register_uninstall_hook(__FILE__, 'pto_uninstall');
That will ensure that settings are not deleted simply be de-activating the plugin - which is logically correct.
Regarding installation / re-activation; the process can now be to check whether each setting already exists (this will allow for new settings in future versions); else use pto_default.php settings.
To do this, REPLACE your existing pto_install() function with the following:
function pto_install()
{
require("pto_default.php");
if (isset($pto_default_config_permalink))
{
global $pto_settings_config;
global $pto_settings_html;
foreach($pto_settings_config as $setting)
{
$default = str_replace("pto_","pto_default_",$setting);
if (get_option($setting)===FALSE) add_option($setting,$$default);
}
foreach($pto_settings_html as $setting)
{
$default = str_replace("pto_","pto_default_",$setting);
if (get_option($setting)===FALSE) add_option($setting,trim($$default));
}
}
}
Above will be included in an update to PriceTapestry.org for Wordpress coming shortly.
Cheers,
David.
--
PriceTapestry.com
Hello Marco,
Thank you for bringing that to my attention; i'll certainly merge that into the next version - apologies if losing settings has caused any inconvenience;
Cheers,
David.
--
PriceTapestry.com