Question

I have a set of settings fields:

(...)
add_settings_field( 'Option1', 'Option 1', 'textarea', 'page1', 'plugin_options');  
add_settings_field( 'Option2', 'Option 2', 'textarea', 'page1', 'plugin_options'); 
add_settings_field( 'Option3', 'Option 3', 'text_input', 'page1', 'plugin_options');  
add_settings_field( 'Option4', 'Option 4', 'text_input', 'page1', 'plugin_options');
(...)   

All tutorials and Codex state that I have to create separate rendering functions for each settings field, but wouldn't be it much easier to create just basic functions for all input fields like checkbox, radio button, textarea etc. and reuse them?

I believe it will work smoothly if I'll be able to pass fields id to these functions, but I'm not sure how?

function textarea() {
    $options = get_option('my_settings');
    echo "<textarea id='[how to get ID?]' name='my_settings[[how to get ID?]'>{$options['how to get ID?']}</textarea>";
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top