Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Render the new field in the admin area.
*
* @param object $field The current CMB2_Field object.
* @param string $escaped_value The value of this field passed through the escaping filter.
* @param int $object_id The id of the object you are working with.
* @param string $object_type The type of object you are working with.
* @param object $field_type_object This is an instance of the CMB2_Types object.
* @return void
*/
function cmb2_render_callback_for_mac_address( $field, $escaped_value, $object_id, $object_type, $field_type_object ) {
echo $field_type_object->input( array( 'type' => 'text' ) );
}
add_action( 'cmb2_render_mac_address', 'cmb2_render_callback_for_mac_address', 10, 5 );
/**
* Sanitize the input for the MAC address field type
*
* @param null $override_value Sanitization override value to return.
* @param string $value The actual field value.
* @return string The sanitized MAC address.
*/
function cmb2_sanitize_mac_address_callback( $override_value, $value ) {
if ( ! filter_var( $value, FILTER_VALIDATE_MAC ) ) {
$value = '';
}
return $value;
}
add_filter( 'cmb2_sanitize_mac_address', 'cmb2_sanitize_mac_address_callback', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment