Echoing a variable inside a function

In the interest of automation, instead of making a long list of code like this

<td valign="top"width="50%"><p><label for="Facebook"><strong>Facebook URL</strong></label><input  type="text" name="Facebook" id="Facebook" size="52" value="<?php echo get_option('Facebook_url'); ?>"/></p></td></tr><tr>

I’d like to echo all of that out from PHP to generate the page. I have build an array containing all the social networks, twitter/facebook etc.
As of now, this can read the saved settings but does not allow it to save new inputs.

Read More
function display_settings_fields($value,$key){
$keyurl = $key.'_url';
echo "The key $key has the value $value<br />";
echo '<td valign="top"width="50%"><p><label for="'.$key.'"><strong>'.$key .'URL</strong></label><input  type="text" name="'.$key.'" id="'.$key.'" size="52" value="';
echo get_option(''.$keyurl.'');
echo '"/></p></td></tr><tr>';

    }
    $social_icon_set = array(
    "Twitter" =>"$twitter_url",
    "Facebook" =>"$facebook_url",
    "GooglePlus" =>"$googleplus_url",
    "Yelp" =>"$yelp_url",
    "Youtube" =>"$youtube_url",
    "Vimeo" =>"$vimeo_url",
    "Flickr" =>"$flickr_url",
    "Tumblr" =>"$tumblr_url",
    "Picplz" =>"$picplz_url",
    "Foursquare" =>"$foursquare_url",
    "RSS" =>"$rss_url",
    "Behance" =>"$behance_url",
    "Goodreads" =>"$goodreads_url",
    "Github" =>"$github_url",
    "Formspring" =>"$formspring_url",
    "Myspace" =>"$mypsace_url",
    "Klout" =>"$klout_url",
    "Diaspora" =>"$diaspora_url",
    "LinkedIn" =>"$linkedin_url"
    );
    array_walk($social_icon_set,"display_settings_fields");
    ?>

The problem comes about with the “echo get_option(”.$keyurl.”);.
Right now, its echoing the correct value, the saved value for it, but it does not allowing saving of anything edited in the text field. Is this even possible to echo/print this out, where its savable.

(This is mostly PHP but if there’s another way around this, because it is using wordpress’s get_options, im open to ideas)

Related posts

Leave a Reply

1 comment

  1. Use the Settings API. A look at my latest plugin may help you to understand how to register a save function for your fields. Most relevant excerpt:

    /**
     * Register custom settings for the fields.
     *
     * @see    save_settings()
     * @see    print_input_field()
     * @return void
     */
    public function add_contact_fields()
    {
        register_setting(
            'general',
            $this->option_name,
            array ( $this, 'save_settings' )
        );
    
        foreach ( $this->fields as $type => $desc )
        {
            $handle   = $this->option_name . "_$type";
            $args     = array (
                'label_for' => $handle,
                'type'      => $type
            );
            $callback = array ( $this, 'print_input_field' );
    
            add_settings_field(
                $handle,
                $desc,
                $callback,
                'general',
                'default',
                $args
            );
        }
    }
    
    /**
     * Callback for 'register_setting()'.
     *
     * @see    add_contact_fields()
     * @param  array $settings
     * @return array $settings
     */
    public function save_settings( array $settings = array () )
    {
        $default  = get_option( $this->option_name );
        $settings = array_map( 'trim', $settings );
        $settings = $this->prepare_mail_save( $settings, $default );
        $settings = $this->prepare_phone_save( $settings );
    
        return $settings;
    }
    

    And … welcome to WordPress Stack Exchange!