Jetpack: Search: Customizer not correctly saving options on first change

Created on 5 Aug 2020  路  2Comments  路  Source: Automattic/jetpack

We've had periodic reports of this, and I think I was able to reproduce it. It only happens when the option being changed is not yet in the DB. So for instance if the 'jetpack_search_show_powered_by' option is not yet in the DB, then we are unable to set the option to false because update_option() in Core checks to see what the current setting is with get_option(). get_option() returns false because it doesn't exist, and then update_option() doesn't think it has anything to do: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/option.php#L405

I guess we should be setting the value to '0' rather than false https://github.com/Automattic/jetpack/blob/aa1eedce7d7b90b5a943969e0b49ebdd9708f2f1/modules/search/class-jetpack-search-customize.php#L264

There have been a bunch of HE reports around this.

Instant Search Search [Pri] High [Type] Bug [Type] Happiness Request

Most helpful comment

Do you know where we're setting the value to false? I dug quite a bit into the Customizer code but was never able to find out where we serialize input values to be stored in the codebase.

I spent hours hunting around for this last week also. I think that by default it returns false. I can think of two solutions:

  1. Invert the selections. "Hide Powered by" rather than "Show". Backwards compatibility may be an issue and I guess requires a new option.
  2. Add a custom sanitization function that converts the values to be '0' or '1'.

All 2 comments

I'm able to reproduce this. Your explanation seems to be spot on.

I guess we should be setting the value to '0' rather than false (@gibrown)

Do you know where we're setting the value to false? I dug quite a bit into the Customizer code but was never able to find out where we serialize input values to be stored in the codebase.

Do you know where we're setting the value to false? I dug quite a bit into the Customizer code but was never able to find out where we serialize input values to be stored in the codebase.

I spent hours hunting around for this last week also. I think that by default it returns false. I can think of two solutions:

  1. Invert the selections. "Hide Powered by" rather than "Show". Backwards compatibility may be an issue and I guess requires a new option.
  2. Add a custom sanitization function that converts the values to be '0' or '1'.
Was this page helpful?
0 / 5 - 0 ratings