Plugin Settings not Saving on Ajax re-ordered table

So the option profile_element_order forms is an array term – and WordPress considers that entire array to be on option.
When you click ‘save’ the form data is posted to WordPress. WordPress recieves this as an array and it updates your option-row in the database by over-riding the old options array with a the one its just recieved.

The problem is that your option profile_element_order is not forming part of that recieved array, because its not posted (it’s just printed to the page, but there are no inputs).

It seems though you are trying to update with both AJAX and a standard form – but you need to sync them. So when your profile_element_order option is updated via AJAX it updates some hidden forms, so when the user clicks ‘save’ the form is sending the updated options.

But then why bother with AJAX? If the user is going to click save and have the form data posted, then AJAX here is redundant and only causing syncing problems.

I would use hidden inputs to store the order, and this updated when the user re-orders them. That order is only saved when the user clicks save (along with all the other options).

Also, you may want to read up on the settings API. You seem to be using only part of it… see this answer (and linked tutorials).

Leave a Comment