Skip to content
Browse files

adding text with sanitize callback

  • Loading branch information...
1 parent 05f4324 commit 072dc7d43f5c57c1312125d4e3cb8d5e61ddbcb6 @kovshenin committed Jul 29, 2011
Showing with 21 additions and 5 deletions.
  1. +21 −5 post-options-api.php
View
26 post-options-api.php
@@ -26,6 +26,17 @@ public static function description( $args = array() ) {
if ( isset( $args['description'] ) && ! empty( $args['description'] ) )
echo "<br /><span class='description'>{$args['description']}</span>";
}
+
+ public static function text( $description = '', $sanitize_callback = '' ) {
+ return array( 'function' => array( 'Post_Options_Fields', '_text' ), 'sanitize_callback' => $sanitize_callback, 'args' => array( 'description' => $description ) );
+ }
+
+ public static function _text ( $args = array() ) {
+ ?>
+ <input type="text" name="<?php echo $args['name_attr']; ?>" value="<?php echo esc_attr( $args['value_attr'] ); ?>" />
+ <?php
+ self::description( $args );
+ }
};
// The post options operations
@@ -113,6 +124,11 @@ function _meta_box_post_options( $post ) {
display: block;
margin-left: 25%;
}
+
+ .post-option-value span.description {
+ display: inline-block;
+ margin-top: 4px;
+ }
</style>
<?php
foreach ( $this->sections as $priority => $sections ) {
@@ -219,13 +235,13 @@ function post_options_test() {
$post_options->register_post_options_section( 'section-id', 'Section Title' );
$post_options->register_post_option( 'option-id', 'Option Title', array( 'function' => 'my_callback', 'args' => array( 1, 2, 3 ), 'sanitize_callback' => 'my_option_sanitize' ), 'section-id' );
$post_options->register_post_option( 'second-option', 'One More Option', 'my_callback', 'section-id' );
- $post_options->register_post_option( 'third-option', 'Third through helper', Post_Options_Fields::checkbox('Full width layout', 'Enable full width layout for this post.'), 'section-id' );
+ $post_options->register_post_option( 'third-option', 'Third through helper', Post_Options_Fields::checkbox( 'Full width layout', 'Enable full width layout for this post.' ), 'section-id' );
+
+ $post_options->register_post_options_section( 'second-section', 'Section #2' );
+ $post_options->register_post_option( 'fourth-option', 'Fourth option', Post_Options_Fields::text( 'This text input is produced by a helper. The sanitize function will make it act like a slug.', 'sanitize_title' ), 'second-section' );
$post_options->add_section_to_post_type( 'section-id', 'post' );
-}
-
-function my_option_sanitize( $option ) {
- return $option . '123';
+ $post_options->add_section_to_post_type( 'second-section', 'post' );
}
function my_callback( $args ) {

0 comments on commit 072dc7d

Please sign in to comment.
Something went wrong with that request. Please try again.