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

According to the docs the option_default() function is called whenever an option is not set. But it's not working for me (1.4.1).

I tested this on the tag cloud plugin. I deleted the 3 options from the database and it comes up with this error:

Warning: Cannot modify header information - headers already sent by (output started at /path/qa-include/qa-theme-base.php:79) in /path/qa-include/qa-install.php on line 60
Question2Answer query failed:
 
SELECT BINARY word AS word, tagcount FROM qa_words JOIN (SELECT wordid FROM qa_words WHERE tagcount>0 ORDER BY tagcount DESC LIMIT 0,_utf8 '') y ON qa_words.wordid=y.wordid
 
Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '_utf8 '') y ON qa_words.wordid=y.wordid' at line 1

If I go to the tag options they are all zero or blank, but if I put in some values and hit Save, the options are then stored in the database and it works fine. The same thing happens with a new plugin so Q2A is not calling option_default and not creating defaults when you first use a plugin.

by
Not sure if related, but i had to manually set in db the default avatar size as I couldn't get the admin options to change it?

1 Answer

0 votes
by

I think this is probably happening because one of the installed plugins is not responding correctly to the option_default(...) method. If one of the plugin modules returns false by default, instead of null, that could be the issue.

by
I had two plugins that returned false in certain cases but I changed those to null (and also tried other values) and the same error occurs. Any ideas?
by
Now that these options are set to the empty string, the error will persist. So please try removing them - then the correct default should kick in?
by
The problem seems to be with one of my plugins. Do you see anything wrong with this:

    function option_default($option)
    {
        if ($option == 'tag_list_count_tags')
            return 100;

        return null;
    }

If the option value is not in the database it gets set to the empty string, and that is passed into this code:

    $populartags = qa_db_single_select( qa_db_popular_tags_selectspec(0, qa_opt('tag_list_count_tags')) );

This is essentially a dupe of the tag cloud plugin but showing the tags as a simple list. Can't see why it would be breaking :(
by
Yeah, the false thing caught me for a while... remember, if ANY plugin that is queried by the script before your plugin is returning a default of false, your option will get set to false BEFORE it comes to your plugin.  If you're using older versions of any of my plugins, that may be the problem.
by
Hmm I did change all those to use null instead of false but it didn't work. But I try today and it's all working fine. Maybe returning false from the function messed up only for the session or something.
...