I would like to use $id to echo the id entered in other functions. Here is an example function using id:
function nl_register_ga_code() {
// Validation callback
register_setting( 'nl_theme_options', 'nl_theme_options', 'nl_validate_settings' );
// Add setting to section
add_settings_section( 'nl_footer_section', 'Footer', 'nl_display_footer_section', 'nl_theme_options.php' );
// Create textarea field
$field_args = array(
'type' => 'textarea',
'id' => 'nl_ga_code',
'name' => 'nl_ga_code',
'desc' => 'Paste Google Analytics code.',
'std' => '',
'label_for' => 'nl_ga_code'
);
// Label
add_settings_field( 'label_ga_code', 'Google Analytics Code', 'nl_display_setting', 'nl_theme_options.php', 'nl_footer_section', $field_args );
}
// Registers the setting
add_action( 'admin_init', 'nl_register_ga_code' );
The function I will be using the variable is this one:
function nl_display_setting ( $args ) {
extract( $args );
$option_name = 'nl_theme_options';
$options = get_option( $option_name );
switch ( $type ) {
case 'text':
$options[$id] = stripslashes( $options[$id] );
$options[$id] = esc_attr( $options[$id] );
echo "<input class='regular-text$class' type='text' id='$id' name='" . $option_name . "[$id]' value='$options[$id]'>";
echo ( $desc != '' ) ? "<br><span class='description'>$desc</span>" : "";
break;
I need to initialize $id but do not know how.