0

If I run the following code in the debug console on my WP install, I get the expected behavior:

<?php
$option = get_option('fun_options');
var_dump($option);

$new = array();
update_option('fun_options', $new);

$option = get_option('fun_options');
var_dump($option);

Output:

C:\Program Files (x86)\Ampps\www\... : eval()'d code:3:
array (size=2)
  'option1' => string 'lovely' (length=6)
  'option2' => string 'horrid' (length=6)
C:\Program Files (x86)\Ampps\www\... : eval()'d code:9:
array (size=0)
  empty

The option is overwritten. (It is set in a plugin I created to isolate this problem).

For the options set in another plugin, I get different behavior from what seems like the same procedure. I've tried emptying the cache and I've tried updating with a string and an array. For some reason the option values get updated to the first letter of the string in some cases and remain unchanged in others.

Please could someone explain what is happening here and how to successfully update my options in this situation?

<?php
$option = get_option('ga_events_options');
var_dump($option);

//wp_cache_delete ( 'ga_events_options' );

//$new = array();
$new = 'test';

update_option('ga_events_options', $new);

$option = get_option('ga_events_options');
var_dump($option);

Output:

C:\Program Files (x86)\Ampps\www\ga-plugin\wp-content\plugins\debug-bar-console\class-debug-bar-console.php(84) : eval()'d code:3:
array (size=19)
  'id' => string 'my_id' (length=0)
  'license' => string '' (length=0)
  'status' => string '' (length=0)
...

C:\Program Files (x86)\Ampps\www\ga-plugin\wp-content\plugins\debug-bar-console\class-debug-bar-console.php(84) : eval()'d code:13:
array (size=19)
  'id' => string 't' (length=1)
  'license' => string 't' (length=1)
  'status' => string '' (length=0)
...
  • 1
    Somewhere is filter option_ga_events_options or pre_option_ga_events_options, or update_option_ga_events_options or pre_update_option_ga_events_options, which filters option value – KAGG Design Jan 24 '18 at 13:46
  • 2
    in weird cases like this I have sometimes given up and ended up just using delete_option followed by add_option... – majick Jan 24 '18 at 13:50

Your Answer

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

Browse other questions tagged or ask your own question.