2013-06-27 4 views
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" 
     ), 

...

...

Я попытался закрыть текст и CONCAT функции, я попытался сделать строку замены и ничего не работает. Спасибо за любую помощь, которую любой может предоставить.

+0

Что ошибка ?! – deceze

+0

Вы пытались использовать что-то вроде: $ contactEmail = get_option ('contact_email', 'no one'); array (.... "title" => $ contactEmail), – cptnk

+0

Включили ли вы файлы, необходимые для использования этой функции? – Aleeeeee

ответ

2

Brute метод сила будет работать ...

$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); 
+0

Да, я сделал что-то подобное, и это сработало. Но привести меня к новой проблеме ... получить правильное значение из функции get_option(). –