In WordPress, how do you filter a textarea that saves a vimeo embed code in theme admin? Using sanitize_text_field will make the code unusable when saving into db via update_post_meta.
$postmeta = sanitize_text_field( $_POST['embed_video']);
update_post_meta($post_id, 'embed_video',$postmeta );
I often approach wordpress video embeds from the other angle, creating the embed code in the template, for example rather than have someone embed a video like this:
I’d have them just insert the id, in this case 69277800. Then I’d put in my template
I would suggest that you save the video’s URL in a text input (continue using
sanitize_text_field()
) and then output the embed code using WordPress’swp_get_oembed()
function. This will work on a variety of allowed providers, such as Youtube and Vimeo. This method is safer as long as you are using allowed providers and I believe it is possible to add providers to the whitelist in the off-chance you are using someone pretty obscure.Additionally, you can whitelist the
iframe
and sanitize the textarea usingwp_kses()
as shown in my answer here.