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 | |
/** | |
* 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_ip_address( $field, $escaped_value, $object_id, $object_type, $field_type_object ) { | |
echo $field_type_object->input( array( 'type' => 'text' ) ); | |
} | |
add_action( 'cmb2_render_ip_address', 'cmb2_render_callback_for_ip_address', 10, 5 ); | |
/** | |
* Sanitize the input for the IP address field type | |
* | |
* @param null $override_value Sanitization override value to return. | |
* @param string $value The actual field value. | |
* @return string The sanitized IP address. | |
*/ | |
function cmb2_sanitize_ip_address_callback( $override_value, $value ) { | |
if ( ! filter_var( $value, FILTER_VALIDATE_IP ) ) { | |
$value = ''; | |
} | |
return $value; | |
} | |
add_filter( 'cmb2_sanitize_ip_address', 'cmb2_sanitize_ip_address_callback', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment