If you look closely at the function definition of theme_get_settings(), you’ll see a not-so-obvious bug.

theme_get_settings() should be returning the values for these settings as they are stored in the database (or as the defaults define them). However, you’ll notice that the returned value for toggle_search setting is altered depending on the user that is currently viewing the site. That's just wrong!

The check for !module_exists('search') || !user_access('search content') should be placed where the setting is being used in the business logic; in this case that check should be inside template_preprocess_page because that's where the theme's search box is being added to the page.tpl.php.

If a theme is trying to do something based on the actual value of toggle_search, the theme will often (but not always) get the wrong value returned by theme_get_settings().

For example, because of this bug, the Zen theme and any theme following the “Initializing the default values” section of the Advanced Theme Settings documentation, will encounter a bizarre error where the search box will get disabled at random times. See #311458: Search box gets disabled after arbitrary amount of time

FYI, the search box feature of themes has been removed from D7, so this is not an issue for D7.

CommentFileSizeAuthor
#2 theme-get-settings-605768-2.patch1.47 KBJohnAlbin
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JohnAlbin’s picture

Title: theme_get_setting() incorrectly tweaks db setting based on current user » theme_get_settings() incorrectly changes returned value based on current user
JohnAlbin’s picture

Status: Active » Needs review
FileSize
1.47 KB

And here's the fix.

q0rban’s picture

Good catch!

greg.harvey’s picture

Has anyone checked to see if this is still an issue in D7?

JohnAlbin’s picture

Greg, the theme's search box feature has been removed in D7. If you want search, you have to enable the search block.

So, that line of code is missing from where it would be in D7's code base. theme_get_settings() has been removed and its code merged with theme_get_setting(). See http://api.drupal.org/api/function/theme_get_setting/7

greg.harvey’s picture

I see - I didn't read the patch and thought the issue was more generic. Been having similar "forgotten settings" issues with other themes. I bet the cause is the same, though the cure will be subtly different.

JohnAlbin’s picture

Assigned: JohnAlbin » Unassigned

Cleaning up my "assigned" queue.

Status: Needs review » Needs work

The last submitted patch, theme-get-settings-605768-2.patch, failed testing.

cooldeeponline’s picture

Thanks for the patch.. worked for me!

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.