最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - How does one update complex options?

programmeradmin3浏览0评论

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?

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?

Share Improve this question asked Feb 16, 2022 at 2:20 bugmagnetbugmagnet 1012 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Having figured it out I'm a bit embarrassed. Nevertheless,

        update_option($this->plugin_name, $options);
发布评论

评论列表(0)

  1. 暂无评论