PDA

View Full Version : save_settings failing vb 4.2


burtonmiller
06-26-2014, 05:48 PM
Trying to modify a settings option in a plugin - vb 4.2

Trying to call something like the following in a plugin - which is getting called on admin_options_processing_build:

$some_options = array('first_option' => 0);

save_settings($some_options);

Have tried many permutations. Errors result in every case. A memory error when I save the options (in dashboard) is the current problem. In no case have I gotten the options to actually save.

I am not a vb expert - and I am surprised how tricky it is to do something this seemingly simple.

ForceHSS
06-26-2014, 06:14 PM
And the name of the plugin is? Also check server error logs if you not sure where to get them ask your host. If you don't know what you are doing best to leave it alone and ask in here how to change some coding so you don't crash your forums

tbworld
06-26-2014, 06:30 PM
You need to provide us with a better sample of code to digest. What is the memory error?

:)

burtonmiller
06-26-2014, 06:36 PM
I am making a new product (mod). We are doing them for several CMS's and Forum platforms.

There is very little code in it right now. To prove it, i made the smallest possible product, with just an option, and a plugin that tries to modify it - on a vanilla install 4.2.2. I have attached the xml file for this test product.

What I am looking for the shortest plugin code that will save an arbitrary option in an arbitrary product.

And here is the error:

https://vborg.vbsupport.ru/

kh99
06-26-2014, 06:45 PM
I think your problem is that calling save_settings() ends up executing hook admin_options_processing_build, so you have an infinite loop.

tbworld
06-26-2014, 07:22 PM
I think your problem is that calling save_settings() ends up executing hook admin_options_processing_build, so you have an infinite loop.

I was guessing the same after reading and looking at the hook, but I figured I needed a better explanation first.

Now that I see the memory error, I am pretty sure we are right. Lets take a look at the code and find out. :)

--------------- Added 26 Jun 2014 at 13:27 ---------------

I am making a new product (mod). We are doing them for several CMS's and Forum platforms.

There is very little code in it right now. To prove it, i made the smallest possible product, with just an option, and a plugin that tries to modify it - on a vanilla install 4.2.2. I have attached the xml file for this test product.

What I am looking for the shortest plugin code that will save an arbitrary option in an arbitrary product.

And here is the error:

http://suspiciouscode.com/wp-content/uploads/2014/06/memoryError.png

In essence you are calling save_settings() from the save_settings() function. Take a look at "includes/adminfunctions_options.php" #642. You will see your hook is in the same function. The function is looping until it exhausts the memory. There is no need to call save_settings(), because after your hook the settings are written to the database.

burtonmiller
06-26-2014, 07:38 PM
OK - that makes sense.

But I tried calling save_settings() from several other hooks - and could never get it to work.

I have a series of operations that I need to call in global_bootstrap_init_complete, but when I tried to save_settings there it just failed completely.

Is there a general alternative so that I can save an option in my code? I would like it work in all 4.x versions:)

Code anyone?

tbworld
06-26-2014, 07:55 PM
Most likely you did not include the dependencies, in order to call save_settings();

I have not tried to do what you are doing, so I do not have an answer for you off the top of my head. :)

--------------- Added 26 Jun 2014 at 14:10 ---------------

//Noticed this function from class_upgrade - might be what you are looking for.

function set_option($varname, $grouptitle, $value)
{
include_once DIR . '/includes/adminfunctions_options.php';
$values = array($varname => $value);
save_settings($values);
}

burtonmiller
06-27-2014, 06:18 PM
That was close, but here is what actually worked. You pushed me in the right direction:)
------
include_once DIR . '/includes/adminfunctions.php';

include_once DIR . '/includes/adminfunctions_options.php';

function set_test_save_option($varname, $value)
{
$values = array($varname => $value);
save_settings($values);
}

set_test_save_option('test_saving_options_flag', 'Some Value');
------

This plugin is hooked to 'admin_complete', which seems to be a safe place to modify options. So, when you change an option, this code will get fired afterwards, and the option panel will reflect your changes.