如何更新复杂的期权?

时间:2022-02-16 作者:bugmagnet

I\'m using Tom McFarlin\'s WordPress-Plugin-Boilerplate along with JoeSz\'s Tutorial.

I\'m loading in a complex options item using

$options = get_option($this->plugin_name);

This works fine for the load and for accessing the items. What I don\'t understand as yet is how to update the modified options back into the db.

For example, if I update the $options blob with

$options[\'stamp1\'] = (isset($input[\'stamp1\']) && !empty($input[\'stamp1\'])) ? esc_attr($input[\'stamp1\']) : (new DateTime(\'NOW\'))->format(\'c\');
$options[\'stamp2\'] = (isset($input[\'stamp2\']) && !empty($input[\'stamp2\'])) ? esc_attr($input[\'stamp2\']) : (new DateTime(\'NOW\'))->format(\'c\');
$options[\'stamp3\'] = (isset($input[\'stamp3\']) && !empty($input[\'stamp3\'])) ? esc_attr($input[\'stamp3\']) : (new DateTime(\'NOW\'))->format(\'c\');
$options[\'stamp4\'] = (isset($input[\'stamp4\']) && !empty($input[\'stamp4\'])) ? esc_attr($input[\'stamp4\']) : (new DateTime(\'NOW\'))->format(\'c\');

the documentation for update_option makes it\'s obvious that

update_option($this->plugin_name );

isn\'t going to work.

There is a register_setting in my class-...-public.php but it\'s not particularly obvious (to me anyway) how this gets called and whether it\'s actually updating the options in the db.

Clues?

1 个回复
SO网友:bugmagnet

弄明白了,我有点尴尬。然而

        update_option($this->plugin_name, $options);

相关推荐

Huge wp_options table

我有一个WP网站的问题。由于没有更多可用磁盘空间,网站崩溃。搜索时,我检测到wp\\U选项表大小为12GB,但大约只有1100行:有什么想法吗?提前感谢[UPDATE 1]如果我导出wp\\U选项表,拖放并导入,大小将减少到9,7mb:我没有机会用优化表OPTIMIZE TABLE wp_options 但如果再发生的话我会试试的[UPDATE 2]问题仍然存在。我试着OPTIMIZE TABLE wp_options;无结果: