-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vp_option should use defaults specified in template #94
Comments
I think that is actually expected output of vp_option() (including defaults) so I don't see a need for backward compatibility. Can you merge it in the original function? |
@liviucmg Thanks for the addition, but I see it as @vladan-me Calling vp_option directly should return the default value if set. Optionally it could have a second parameter "default", which could be used to override the internal default. So, what vp_option($key, $default = null) could do
|
Okay guys, sounds good. I was just afraid that someone would have previously depended on |
Done. I've also added a proper PHPDoc comment, and fixed the indenting to tabs just like the rest of the file. |
We have the following scenarios:
I believe that the
vp_option
should return the default values for these options, since they are already specified in the template file. Instead, it returnsnull
, unless you manually specify a default value each time you call it.For the sake of backward compatibility, I have created a new function
vp_option_with_default
(suggestions for a better name are welcomed) that fixes this. It will callvp_option
and if that returns null, it will load the default values and extract the option from there.To boost performance, I have also modified
VP_Option_Control_Set
to cache these default values so that they are not computed each and every time.I have made a quick speed test on an unset option, with 1000 runs. Results:
vp_option('some.option', null);
= 6msvp_option_with_default('some.option');
= 17msvp_option_with_default('some.option');
, without caching the defaults = 427msIt is pretty much unnoticeable with the cache fix.
Thoughts?
The text was updated successfully, but these errors were encountered: