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.
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)
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:And ⦠welcome to WordPress Stack Exchange!