Permalink
Browse files

Merge pull request #243 from funkedgeek/master

New Email field and some text input tweaks
  • Loading branch information...
2 parents aa89b5a + 7b59dfe commit 64c58f0fa7f9dbe9d968a578378c56ec09b700fa @rilwis committed Mar 13, 2013
Showing with 130 additions and 67 deletions.
  1. +48 −0 inc/fields/email.php
  2. +4 −17 inc/fields/password.php
  3. +31 −2 inc/fields/text.php
  4. +47 −48 inc/fields/url.php
View
@@ -0,0 +1,48 @@
+<?php
+// Prevent loading this file directly
+defined( 'ABSPATH' ) || exit;
+
+// Make sure "text" field is loaded
+require_once RWMB_FIELDS_DIR . 'text.php';
+
+if ( ! class_exists( 'RWMB_Email_Field' ) )
+{
+ class RWMB_Email_Field extends RWMB_Text_Field
+ {
+ /**
+ * Get field HTML
+ *
+ * @param string $html
+ * @param mixed $meta
+ * @param array $field
+ *
+ * @return string
+ */
+ static function html( $html, $meta, $field )
+ {
+ return sprintf(
+ '<input type="email" class="rwmb-url" name="%s" id="%s" value="%s" size="%s" />',
+ $field['field_name'],
+ $field['id'],
+ $meta,
+ $field['size']
+ );
+ }
+
+
+ /**
+ * Sanitizes url
+ *
+ * @param $post_id
+ * @param $field
+ * @param $old
+ * @param $new
+ *
+ * @return $new
+ */
+ static function value( $new, $old, $post_id, $field)
+ {
+ return sanitize_email( $new );
+ }
+ }
+}
View
@@ -2,9 +2,12 @@
// Prevent loading this file directly
defined( 'ABSPATH' ) || exit;
+// Make sure "text" field is loaded
+require_once RWMB_FIELDS_DIR . 'text.php';
+
if ( ! class_exists( 'RWMB_Password_Field' ) )
{
- class RWMB_Password_Field
+ class RWMB_Password_Field extends RWMB_Text_Field
{
/**
* Get field HTML
@@ -25,21 +28,5 @@ static function html( $html, $meta, $field )
$field['size']
);
}
-
- /**
- * Normalize parameters for field
- *
- * @param array $field
- *
- * @return array
- */
- static function normalize_field( $field )
- {
- $field = wp_parse_args( $field, array(
- 'size' => 30,
- ) );
-
- return $field;
- }
}
}
View
@@ -18,11 +18,13 @@ class RWMB_Text_Field
static function html( $html, $meta, $field )
{
return sprintf(
- '<input type="text" class="rwmb-text" name="%s" id="%s" value="%s" size="%s" />',
+ '<input type="text" class="rwmb-text" name="%s" id="%s" value="%s" size="%s" %s/>%s',
$field['field_name'],
$field['id'],
$meta,
- $field['size']
+ $field['size'],
+ !$field['datalist'] ? '' : "list='{$field['datalist']['id']}'",
+ self::datalist_html($field)
);
}
@@ -37,8 +39,35 @@ static function normalize_field( $field )
{
$field = wp_parse_args( $field, array(
'size' => 30,
+ 'datalist' => false
) );
return $field;
}
+
+ /**
+ * Create datalist, if any
+ *
+ * @param array $field
+ *
+ * @return array
+ */
+ static function datalist_html( $field )
+ {
+ if( !$field['datalist'] )
+ return '';
+ $datalist = $field['datalist'];
+ $html = sprintf(
+ '<datalist id="%s">',
+ $datalist['id']
+ );
+
+ foreach( $datalist['options'] as $option ) {
+ $html.= sprintf('<option value="%s"></option>', $option);
+ }
+
+ $html .= '</datalist>';
+
+ return $html;
+ }
}
}
View
@@ -1,49 +1,48 @@
-<?php
-// Prevent loading this file directly
-defined( 'ABSPATH' ) || exit;
-
-// Make sure "text" field is loaded
-require_once RWMB_FIELDS_DIR . 'text.php';
-
-if ( ! class_exists( 'RWMB_URL_Field' ) )
-{
- class RWMB_URL_Field extends RWMB_Text_Field
- {
- /**
- * Get field HTML
- *
- * @param string $html
- * @param mixed $meta
- * @param array $field
- *
- * @return string
- */
- static function html( $html, $meta, $field )
- {
- return sprintf(
- '<input type="url" class="rwmb-url" name="%s" id="%s" value="%s" size="%s" />',
- $field['field_name'],
- $field['id'],
- $meta,
- $field['size']
- );
- }
-
-
- /**
- * Sanitizes url
- *
- * @param $post_id
- * @param $field
- * @param $old
- * @param $new
- *
- * @return $new
- */
- static function value( $new, $old, $post_id, $field)
- {
- $new = esc_url($new);
- return $new;
- }
- }
+<?php
+// Prevent loading this file directly
+defined( 'ABSPATH' ) || exit;
+
+// Make sure "text" field is loaded
+require_once RWMB_FIELDS_DIR . 'text.php';
+
+if ( ! class_exists( 'RWMB_URL_Field' ) )
+{
+ class RWMB_URL_Field extends RWMB_Text_Field
+ {
+ /**
+ * Get field HTML
+ *
+ * @param string $html
+ * @param mixed $meta
+ * @param array $field
+ *
+ * @return string
+ */
+ static function html( $html, $meta, $field )
+ {
+ return sprintf(
+ '<input type="url" class="rwmb-url" name="%s" id="%s" value="%s" size="%s" />',
+ $field['field_name'],
+ $field['id'],
+ $meta,
+ $field['size']
+ );
+ }
+
+
+ /**
+ * Sanitizes url
+ *
+ * @param $post_id
+ * @param $field
+ * @param $old
+ * @param $new
+ *
+ * @return $new
+ */
+ static function value( $new, $old, $post_id, $field)
+ {
+ return esc_url( $new );
+ }
+ }
}

0 comments on commit 64c58f0

Please sign in to comment.