如何将wordpress选项分配给多维数组

发布于 2024-09-30 20:16:52 字数 1221 浏览 0 评论 0原文

好吧,我在开发新插件时遇到了障碍,

插件选项作为序列化数组存储在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡笑忘祈一世凡恋 2024-10-07 20:16:52

使用 array_push 向现有数组添加更多选项。

$feed = array('name' => 'Feed 1', 'url' => 'whatever.com');
$wp_options = array_push($wp_options['feeds'], "$feed");
print_r($wp_options);

这是您要找的吗?

Use array_push to add more options to an existing array.

$feed = array('name' => 'Feed 1', 'url' => 'whatever.com');
$wp_options = array_push($wp_options['feeds'], "$feed");
print_r($wp_options);

Is this what you are looking for?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文