如何将wordpress选项分配给多维数组
好吧,我在开发新插件时遇到了障碍,
插件选项作为序列化数组存储在 WordPress 数据库中。 现在数组如下..
$wp_options = array(
'ptinstalldir' => '',
'ptscriptdir' => '',
'feeds' => array(
'name' => 'Test Feed 1',
'url' => 'http://www.test.com/feed.xml'
),
'db_version' => $wp_plugin_dbversion
);
使用当前选项设置,我需要一种方法来填充选项['feed'];有不止一组值,现在它有一个测试名称和 url 设置,但我正在寻找一种更动态的方式来存储提要列表,我希望能够从管理区域内根据需要添加尽可能多的提要。
类似的事情..
$wp_options = array(
'ptinstalldir' => '',
'ptscriptdir' => '',
'feeds' => array('feed1' => array(
'name' => 'Test Feed 1',
'url' => 'http://www.test.com/feed.xml'
),
'feed2' => array(
'name' => 'Test Feed 1',
'url' => 'http://www.test.com/feed.xml'
),
'db_version' => $wp_plugin_version
);
我正在考虑为数据库中的提要创建一个新表,但我知道 WordPress 可以做到这一点,它只是让我的头脑围绕它,当涉及到保存和添加任何新选项、任何建议时欢迎 干杯
ok, I've hit a road block while working on a new plugin,
the plugin options are stored as a serialized Array in the wordpress database.
just now the array is as below..
$wp_options = array(
'ptinstalldir' => '',
'ptscriptdir' => '',
'feeds' => array(
'name' => 'Test Feed 1',
'url' => 'http://www.test.com/feed.xml'
),
'db_version' => $wp_plugin_dbversion
);
with the current options setup, I needed a way to populate the options['feed']; with more than one set of values, just now its got a test name and url setup, but im looking for a more dynamic way of storing the list of feeds i want to beable to add as many feeds as needed from inside the admin area.
something along these lines..
$wp_options = array(
'ptinstalldir' => '',
'ptscriptdir' => '',
'feeds' => array('feed1' => array(
'name' => 'Test Feed 1',
'url' => 'http://www.test.com/feed.xml'
),
'feed2' => array(
'name' => 'Test Feed 1',
'url' => 'http://www.test.com/feed.xml'
),
'db_version' => $wp_plugin_version
);
I was thinking of creating a new table for the feeds in the database, but i know wordpress can do this, its just getting my head around it, when it comes to saving and adding any new options, any advice is welcome
cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 array_push 向现有数组添加更多选项。
这是您要找的吗?
Use
array_push
to add more options to an existing array.Is this what you are looking for?