Created
April 23, 2012 12:12
-
-
Save kovshenin/2470555 to your computer and use it in GitHub Desktop.
Reusable Settings API fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Text Field | |
* | |
* A simple text field callback to use with the Settings API. Don't forget to pass in | |
* the arguments array. Here's an example call to add_settings_field() : | |
* | |
* add_settings_field( 'my_option', __( 'My Option' ), 'foo_field_text', 'theme_options', 'general', array( | |
* 'name' => 'my_theme_options[my_option]', | |
* 'value' => $options['my_option'], // assuming $options is declared | |
* 'description' => __( 'Write some description for the field here.' ), | |
* ) ); | |
*/ | |
function foo_field_text( $args ) { | |
extract( wp_parse_args( $args, array( | |
'name' => null, | |
'value' => null, | |
'description' => null, | |
) ) ); | |
?> | |
<input type="text" name="<?php esc_attr_e( $name ); ?>" value="<?php esc_attr_e( $value ); ?>" /> | |
<?php if ( $description ) : ?><span class="description"><?php echo $description; ?></span><?php endif; ?> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I currently use this method to define my own form fields in Oenology, but agree that the form-field markup itself could easily be commoditized into core. The advantage of using this method now is that, if/when it does get rolled into core, it will be fairly trivial to switch to supporting the core method.