开发者

How to assign wordpress options to multidimensional array

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, jus开发者_如何学Pythont 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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜