I have a function like this:
add_settings_field( 'contact_phone', 'Contact Phone', 'settings_callback', 'general');
That works. It calls settings_callback. Cool. The problem I have with this is: I don’t want to have to define a callback function for every setting I add, if all I’m doing is echoing out a little bit of stuff.
function settings_callback()
{
echo '<input id="contact_phone" type="text" class="regular-text" name="contact_phone" />';
}
Why on earth should I have to do that? The id, class, and name should all be params.
Is there no way to pass params to the settings_callback function? I started looking at the core, got here: http://core.trac.wordpress.org/browser/tags/3.1.3/wp-admin/includes/template.php
..and ran into this $wp_settings_fields global. Where is this defined?
Look at the declaration for the function:
The last parameter takes your arguments and passes them to the callback function.
Example from my plugin Public Contact Data
The function
print_input_field()
gets these arguments as first parameter:No need to touch a global variable.