You’re adding a url
field in the control but the underlying setting has an absint
sanitize callback. When you pass a URL string into absint
you get 0
. So what you should do is check to see if the value is numeric, and then call absint
; otherwise if it is a string then it should be passed through esc_url_raw
to sanitize. Here’s an example that also includes validation:
$wp_customize->add_setting( 'feed_video_setting', array(
'default' => '',
'sanitize_callback' => function( $value ) {
if ( is_numeric( $value ) ) {
$value = intval( $value );
if ( $value < 0 ) {
return new WP_Error( 'invalid_attachment_id', __( 'Invalid attachment ID', 'myplugin' ) );
}
} elseif ( ! empty( $value ) ) {
$value = esc_url_raw( $value );
if ( empty( $value ) ) {
return new WP_Error( 'invalid_video_url', __( 'Invalid URL', 'myplugin' ) );
}
}
return $value;
},
) );
Please refer also to the external video header control in core for how it is done there: