0

我在一个 wordpress 网站上工作,我需要将函数的值分配给数组内的值,但它一直给我错误。在 customFields 数组中,我需要将 get_option('contact_email', 'no one') 的值插入到一些帮助文本中。在下面的代码片段中,我需要将 {CONTACT_EMAIL} 替换为 get_option 值,但无法弄清楚。

...

    var $customFields = array(
        array(
            "name"          => "ContactPerson-name",
            "title"         => "Contact Name",
            "description"   => "Enter the first and last name of the page contact. If left blank, the site default of {CONTACT_PERSON} will be used.",
            "type"          => "textinput",
            "scope"         =>  array( "page" ),
            "capability"    => "edit_pages"
        ),
        array(
            "name"          => "ContactPerson-email",
            "title"         => "Contact Email",
            "description"   => "Enter the email address of the page contact. If left blank, the site default of {CONTACT_EMAIL} will be used.",
            "type"          => "textinput",
            "scope"         =>  array( "page" ),
            "capability"    => "edit_pages"
        ),

        array(
            "name"          => "ContactPerson-phone",
            "title"         => "Contact Phone (XXX) XXX-XXXX",
            "description"   => "Enter the phone number of the page contact. If left blank, the site default of {CONTACT_PHONE} will be used.",
            "type"          => "textinput",
            "scope"         =>  array( "page" ),
            "capability"    => "edit_pages"
        ),

        array(
            "name"          => "ContactPerson-address",
            "title"         => "Contact Room Number & Building",
            "description"   => "Enter the room number and building of the page contact. Click <a href=\"http://www.engin.umich.edu/buildingabbreviations\">here</a> for building abbreviations. If left blank, the site default of {CONTACT_ADDRESS} will be used.",
            "type"          => "textinput",
            "scope"         =>  array( "page" ),
            "capability"    => "edit_pages"
        ),

...

...

我试图关闭文本并连接函数,我试图进行字符串替换,但似乎没有任何效果。感谢任何人都可以提供的任何帮助。

4

1 回答 1

2

蛮力方法将起作用...

$customFields = array(
    array(
        "name"          => "ContactPerson-name",
        "title"         => "Contact Name",
        "description"   => "... of {CONTACT_PERSON} will be used...",
        "type"          => "textinput",
        "scope"         =>  array( "page" ),
        "capability"    => "edit_pages"
    )
);

$contact_person = get_option('contact_person');

foreach($customFields as &$field)
{
    $field['description'] = str_replace("{CONTACT_PERSON}", $contact_person, $field['description']);
}

unset($field);
于 2013-06-27T12:43:05.727 回答