Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
–1 vote
344 views
in Q2A Core by
edited by

I'm using qa_opt() to check if a plugin *is enabled* or not. For instance:

if( qa_opt('q2apro_pluginXX_enabled') ) { // do something }

However, I realized that every time I call qa_opt() with a value that has not been set, q2a core sets it immediately in the database.

For the example that means, value 'q2apro_pluginXX_enabled' would be written to the database, table qa_options.

 

Questions:

1. Is this intended behaviour?

2. If yes, what is the reason for this?

 

Thanks,
Kai

Q2A version: 1.6.3

2 Answers

–2 votes
by

qa-page-admin-plugins.php (L45 -) may help you ?

Key variable: global $qa_modules

Key function: qa_list_module_types(), qa_list_modules()

global $qa_modules;
echo '<pre>';
echo 'qa_modules = '.print_r($qa_modules,true).PHP_EOL;
echo '<pre>';
by
Hi sama55, my question is about the qa_opt() that automatically sets the option with an empty value in the database. It should rather check if the option is present without setting it...
by
Two issues are included in your question. Therefore the way of your question is wrong. The default value problem of the qa_opt() function is different from confirming existence of the plugin.
by
Okay, you are right. I should have been more detailed: I am checking if the plugin is *enabled* or not by using an qa_opt value so I can check if it has been enabled or it is disabled. Doing so I realized that each time I do this, the qa_opt value is created in the database.

PS: The (-1) vote on your answer is not from me.
+5 votes
by

This is intended behavior, though I can see it's not ideal in some cases.

Try calling qa_opt('site_title') or something like that, to make sure that the options are loaded from the database. Then you can call qa_opt_if_loaded(...) and it will return null if the option you really want is not present.

by
Mhh, two lines to check for a value, or one line if I do: if( qa_opt_if_loaded(qa_opt('site_title')) ) { ... }

Had been great if qa_opt worked as shortcut to check for existing value as well - without setting it.

Nevertheless, using if( qa_opt('does_not_exist') ) works but I guess it returns an empty string then because value in database is empty.
...