0

I am working on a wordpress site and I need to assign the value of a function to a value inside an array but it keeps giving me errors. In the customFields array I need to insert the value of the get_option('contact_email', 'no one') into some helper text. In the code snippet below I need to replace {CONTACT_EMAIL} with the get_option value but can't figure it out.

...

    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"
        ),

...

...

I've tried to close the text and concat the function, I've tried to do a string replace and nothing seems to work. Thanks for any help anyone can provide.

11
  • did you try to use something like: $contactEmail = get_option('contact_email', 'no one'); array(...."title" => $contactEmail), Commented Jun 27, 2013 at 12:02
  • Have you included the files needed to to use that function? Commented Jun 27, 2013 at 12:03
  • @deceze, the famous white screen of death, but my UI was telling me there was a code error Commented Jun 27, 2013 at 12:04
  • If get_Option will return array, you can use implode and store it on CONTACT_EMAIL variable Commented Jun 27, 2013 at 12:05
  • @cptnk, guess I should mention that its an array inside an array Commented Jun 27, 2013 at 12:08

1 Answer 1

2

Brute force method will work...

$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);
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I did something just like that and it worked. But lead me to a new issue...getting the right value from the get_option() function..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.