$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugin development - How do you store options with a:n:{{}} syntax in wp_options?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin development - How do you store options with a:n:{{}} syntax in wp_options?

matteradmin9PV0评论

I'm checking out how a particular plugin works and noticed that it stores its data for option_value in wp_options in this array format...

a:2:{i:20;a:2:{s:8:"original";s:15:"20.original.jpg";s:9:"thumbnail";s:12:"20.thumb.jpg";}i:8;a:2:{s:8:"original";s:14:"8.original.png";s:9:"thumbnail";s:11:"8.thumb.png";}}

I like this method, since it only uses a single row to hold my custom data, uninstall cleanup is easy. Is there a standard way to do a get/set operation on a custom field that results in this syntax?

Update: Thanks to Denis and the others who've added responses.

Here's an excellent tutorial on this method in case anyone else has this question > /

I'm checking out how a particular plugin works and noticed that it stores its data for option_value in wp_options in this array format...

a:2:{i:20;a:2:{s:8:"original";s:15:"20.original.jpg";s:9:"thumbnail";s:12:"20.thumb.jpg";}i:8;a:2:{s:8:"original";s:14:"8.original.png";s:9:"thumbnail";s:11:"8.thumb.png";}}

I like this method, since it only uses a single row to hold my custom data, uninstall cleanup is easy. Is there a standard way to do a get/set operation on a custom field that results in this syntax?

Update: Thanks to Denis and the others who've added responses.

Here's an excellent tutorial on this method in case anyone else has this question > http://striderweb/nerdaphernalia/2008/07/consolidate-options-with-arrays/

Share Improve this question edited Jan 6, 2011 at 16:37 Scott B asked Jan 6, 2011 at 16:03 Scott BScott B 5,69614 gold badges94 silver badges148 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 8

Just pass an array when updating your option. It will be serialized automatically.

The serialization is done automatically, but if you want to know how to do this manually the function to look at is called serialize()

As per other answers (un)serialization is performed automatically on more complex data formats (arrays, objects) when options are stored or retrieved. This also applies to transients and other functionality.

Technically this is performed by internal usage maybe_serialize() and maybe_unserialize() functions that try to determine if data needs to be processed or passed as is.

Post a comment

comment list (0)

  1. No comments so far