Skip to content

Instantly share code, notes, and snippets.

@rilwis
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rilwis/0491dde925d20f9fff9b to your computer and use it in GitHub Desktop.
Save rilwis/0491dde925d20f9fff9b to your computer and use it in GitHub Desktop.
Create new field type
<?php
/**
* This class defines new "phone" field type for Meta Box class
*
* @author Tran Ngoc Tuan Anh <rilwis@gmail.com>
* @package Meta Box
* @see http://metabox.io/?post_type=docs&p=390
*/
if ( class_exists( 'RWMB_Field' ) )
{
class RWMB_Phone_Field extends RWMB_Field
{
/**
* Get field HTML
*
* @param mixed $meta
* @param array $field
*
* @return string
*/
static public function html( $meta, $field )
{
return sprintf(
'<input type="tel" name="%s" id="%s" value="%s" pattern="\d{3}-\d{4}">',
$field['field_name'],
$field['id'],
$meta
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment