AJAX call in backend results in empty update_option

In the admin backend pages I get some settings saved in a multidimensional array, update them and then save them again in an AJAX callback function. The problem is that the saved settings are empty, but if I save the array to a different option it works. I boil it down to the code below.

public function my_ajax_callback() {      $options = get_option('user_manager_options');      // Saves the multidimensional array returned above. Excellent.     update_option('test_option', $options);      // Has a completely blank value in the database. Terrible and illogical.     update_option('user_manager_options', $options);      die(); } 

This makes no sense and I've spent hours on it now. I have serialised the array with maybe_serialize which did not work.


I figured it out, when registering with register_setting the second parameter is the name of the settings you will be saving and updating, the parameter is pass in here to whitelist it against being updated outside of the plugin. The AJAX callback is deemed outside of the plugin.

My register settings is below and the second option is the same as the one in get_option in my question. For the settings that I will be changing I will simply use a different name.

     array($this, 'sanitize')

Category: ajax Time: 2016-07-29 Views: 0
Tags: ajax options wpdb

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.272 (s). 12 q(s)