从数组外部向数组中添加键值


Add key values in a array from outside of array

这是一个php问题,恰好涉及到Wordpress。

我的Wordpress父主题添加了一个自定义metabox。我需要添加额外的选项到metabox,但我需要从我的子主题中添加关键值选项…而不是在创建数组的父主题中

在父主题中添加额外的选项(键值)很简单,但是核心主题文件必须更改,因此当父主题被主题开发人员更新时将中断。

所以我做了一个子主题来处理我所有的自定义添加…但是我不知道如何将键值注入到父主题中创建的数组中。

下面是为metabox(父主题)构建选项的数组的摘录:

$page_meta_boxes = array(
    "Page Item" => array(
        'item'=>'page-option-item-type' ,
        'size'=>'page-option-item-size', 
        'xml'=>'page-option-item-xml', 
        'type'=>'page-option-item',
        'name'=>array(
            'home-page-featured'=>array(
                'main-title'=>array(
                    'title'=> 'MAIN TITLE',
                    'name'=> 'page-option-item-featured-text-title',
                    'type'=> 'inputtext'),
                'main-caption'=>array(
                    'title'=> 'MAIN CAPTION',
                    'name'=> 'page-option-item-stunning-text-caption',
                    'type'=> 'textarea'),
            ),
        )
    ),
)

我想在metabox中添加额外的选项,例如:

                'get-started-button-title'=>array(
                    'title'=> 'GETTING STARTED BUTTON TITLE',
                    'name'=> 'page-option-item-featured-text-button-title',
                    'type'=> 'inputtext',
                    'description'=> 'The stunning text button will appear if this field is not a blank.'),
                'get-started-button-link'=>array(
                    'title'=> 'GETTING STARTED BUTTON LINK',
                    'name'=> 'page-option-item-featured-text-button-link',
                    'type'=> 'inputtext',
                    'description'=> 'This is a stunning text button link url. This field will be ignored when button title equals to blank.'),

这可能吗?

更新:到目前为止我所做的一切

我在我的子主题中包含了一个名为options.php的文件,但它没有添加额外的开始按钮选项。

$page_meta_boxes['Page Item']['name']['home-page-featured']['get-started-button-title'] = array(
    'title'=> 'GETTING STARTED BUTTON LINK',
    'name'=> 'page-option-item-featured-text-button-link',
    'type'=> 'inputtext',
    'description'=> 'This is a stunning text button link url. This field will be ignored when button title equals to blank.'
    );

您可以添加这样的附加选项:

$page_meta_boxes['Page Item']['name']['home-page-featured']['get-started-button-title'] = array(....); 

要注意,即使你不改变核心主题。你依赖于它的结构。所以你的代码可能仍然会在主题开发人员更新的情况下中断。