4

I know that when delete_option() or update_option() fail to perform their respective database interactions, they return false. Does anyone know why they wouldn't be able to perform these actions?

It's only for specific options. Most options will work, however, a few options just seem to "die". They'll work fine for a while, then just stop working. Any ideas?

6

The delete_option() function will return false if the option does not exist.

The update_option() function will return false if the option already has the same value as what you're trying to update it to.

Both will also return false if the SQL query itself fails for whatever reason.

3
  • Yeah, in this case it's the mySQL query failing as if I use get_option and var_dump, the option exists with a non-falsy value and I'm not trying to update with the same value. Do you have any idea why the mySQL query would fail consistently for some options but not others?
    – Sam
    Apr 25 '14 at 6:13
  • Sure, your database is corrupt. Run a REPAIR and OPTIMIZE on the tables.
    – Otto
    Apr 25 '14 at 6:42
  • So I tried running those to no avail. Instead, it seems like it was actually a problem with APC cache. I restarted PHP and that did the trick. What seems to have been happening was that the update and delete were actually working (I went back and found that they returned true once, then would return false), but get_option was getting an old, cached value, making it seem like update and delete weren't working. Do you happen to know why the APC cache wouldn't bust during an update or delete using Jaquith's APC object-cache.php? And thanks for staying on this thread Otto - much appreciated.
    – Sam
    Apr 25 '14 at 16:31
0

I had a similar issue with wp_update_option failing, but I knew that the data I was trying to update was different from what was already in place, so the "obvious" reason for failure was ruled out.

It turned out that it was (is, at the time of writing this) a bug in WordPress itself, in the way caching is handled. Not super-sure this was the explanation, but disabling persistent caching (like memcached) solved the issue for me. The fix for that bug should ship in 5.3.1 anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.