我wp_options
表中的数据当前存储为多维数组(profile_element_order
):
a:12:{s:17:"img_base64_enable";s:1:"1";s:25:"moulding_combination_page";s:0:"";s:24:"moulding_collection_page";s:0:"";s:25:"idea_gallery_thumb_height";s:3:"200";s:24:"idea_gallery_thumb_width";s:3:"200";s:23:"collection_thumb_height";s:3:"200";s:22:"collection_thumb_width";s:3:"200";s:20:"profile_item_columns";s:1:"4";s:17:"idea_item_columns";s:1:"2";s:24:"collections_item_columns";s:1:"2";s:25:"combinations_item_columns";s:1:"4";s:21:"profile_element_order";a:5:{i:0;s:8:"Option 1";i:1;s:8:"Option 2";i:2;s:8:"Option 3";i:3;s:8:"Option 4";i:4;s:8:"Option 5";}}
我想要完成的是更新profile_element_order
选项(在这些选项中)。到目前为止,这是所有内容的样子:
function psort_save_order() {
global $mouldings_options;
$list = $mouldings_options['profile_element_order'];
$new_order = $_POST['list_items'];
$new_list = array();
// update order
foreach($new_order as $v) {
if(isset($list[$v])) {
$new_list[$v] = $list[$v];
}
}
// save the new order
update_option('profile_element_order', $new_list);
die();
}
add_action('wp_ajax_psort_update_order', 'psort_save_order');
数据正确地发布到了DB表中(正如我可以看到的一些失败尝试那样,它们是新的选项条目,例如mouldings_settings->profile_element_order
),我很难确定update_option()
该特定选项的语法。我已经尝试过类似的事情(记住`mouldings_settings是实际的选项名称):
mouldings_settings['profile_element_order']
$mouldings_options['profile_element_order']
profile_element_order
但目前没有骰子。任何指针将不胜感激!谢谢!
更新, 这就是我现在所拥有的-ajax操作可以很好地保存,但是当我保存插件选项时,它将复制数据库中的选项并引发与以前相同的错误:
a:17:{s:17:"img_base64_enable";s:1:"1";s:25:"moulding_combination_page";s:0:"";s:24:"moulding_collection_page";s:0:"";s:25:"idea_gallery_thumb_height";s:3:"200";s:24:"idea_gallery_thumb_width";s:3:"200";s:23:"collection_thumb_height";s:3:"200";s:22:"collection_thumb_width";s:3:"200";s:20:"profile_item_columns";s:1:"4";s:17:"idea_item_columns";s:1:"2";s:24:"collections_item_columns";s:1:"2";s:25:"combinations_item_columns";s:1:"4";s:21:"profile_element_order";a:5:{i:4;s:8:"Option 5";i:0;s:8:"Option 1";i:1;s:8:"Option 2";i:3;s:8:"Option 4";i:2;s:8:"Option 3";}i:0;s:8:"Option 5";i:1;s:8:"Option 1";i:2;s:8:"Option 2";i:3;s:8:"Option 4";i:4;s:8:"Option 3";}
功能:
function psort_save_order() {
global $mouldings_options;
$list = $mouldings_options['profile_element_order'];
$new_order = $_POST['list_items'];
$new_list = array();
// update order
foreach($new_order as $v) {
if(isset($list[$v])) {
$new_list[$v] = $list[$v];
}
}
$mouldings_options['profile_element_order'] = $new_list;
$mouldings_options = array_merge($mouldings_options,$mouldings_options['profile_element_order']);
// save the new order
update_option('mouldings_settings', $mouldings_options);
die();
}
add_action('wp_ajax_psort_update_order', 'psort_save_order');