Support » Developing with WordPress » Update_option fails with multi-dimensional array

  • rhj4


    I have a complex array that I am passing to update_option as the option_value. Update_option returns false. Here is a var_dump of the array:
    array (size=12)
    ‘enabled’ => boolean true
    ‘verbose’ => boolean true
    ‘do_backtrace’ => int 0
    ‘logfile’ => string ‘MKP Plugins.log’ (length=15)
    ‘handler’ =>
    array (size=3)
    ‘function’ => boolean false
    ‘class’ => string ‘MKP_Base’ (length=8)
    ‘method’ => string ‘file_logger’ (length=11)
    ‘show_all_igroups’ => boolean false
    ‘show_loggedin_igroups’ => boolean false
    ‘source’ => string ‘MKP Plugins: ‘ (length=13)
    ‘autoload’ =>
    array (size=4)
    ‘communities’ => boolean false
    ‘contacts’ => boolean false
    ‘igroups’ => boolean false
    ‘mapper’ => boolean false
    ‘table_name_prefix’ => string ‘mkpusa_’ (length=7)
    ‘google_api_key_name’ => string ‘mkp_google_api_key’ (length=18)
    ‘google_api_key_value’ => string ‘xxxxx’ (length=39)`

    I am assuming that the array is somehow unacceptable to update_option, but I don’t know what the problem is.

Viewing 2 replies - 1 through 2 (of 2 total)
  • rhj4


    Here is the serialized value of the array:

    a:13:{s:7:"enabled";b:1;s:7:"verbose";b:1;s:12:"do_backtrace";i:0;s:7:"logfile";s:15:"MKP Plugins.log";s:7:"handler";a:3:{s:8:"function";b:0;s:5:"class";s:8:"MKP_Base";s:6:"method";s:11:"file_logger";}s:16:"show_all_igroups";b:0;s:21:"show_loggedin_igroups";b:0;s:6:"source";s:13:"MKP Plugins: ";s:8:"autoload";a:4:{s:11:"communities";b:0;s:8:"contacts";b:0;s:7:"igroups";b:0;s:6:"mapper";b:0;}s:17:"table_name_prefix";s:7:"mkpusa_";s:19:"google_api_key_name";s:18:"mkp_google_api_key";s:20:"google_api_key_value";s:39:"AIzaSyCOjHk72lBq6kLBj8p8uUrDnbSsvbkCTr4";s:6:"loaded";a:1:{s:11:"communities";b:1;}}

    • This reply was modified 3 years ago by bcworkz. Reason: code fixed, otherwise syntax errors occur
    Moderator bcworkz


    I unserialized your last posted data and fed the result through update_option() without issue, it returned true and the value in the DB appears to match the serialized data you posted. I didn’t check char for char, but it looks OK. You are passing the actual array variable to update_option(), not a serialized value, correct? update_option() automatically serializes arrays.

    If so, all I can imagine is some sort of plugin/theme conflict or a corrupted update. Please install and activate the health-check plugin. Go to the troubleshooting tab and activate troubleshooting mode (does not impact other site visitors). Through the troubleshooting admin bar pick, re-activate whatever module saves the problem array. If it doesn’t work now, either the module containing the code is the problem, or your installation has been corrupted.

    Assuming it works now, re-activate your modules one by one until the update option fails again. The last activated module is at fault. Take up the issue with the responsible developer. If it looks like your installation is corrupted, perform a manual update of WP and all other modules you use.

    BTW, any time you post code in these forums, please demarcate your code with backticks or use the code button. When you don’t, it’s hard for others to test your code because it gets corrupted by the forum parser. Not everyone can fix your code like I did.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Update_option fails with multi-dimensional array’ is closed to new replies.