I am looking for an efficient way to detect if user input is a valid embed link (and of what type). I know that one can cause WordPress to run its embed code with arbitrary input.
For example, like this:
$embed_code = wp_oembed_get($some_string);
if($embed_code!=FALSE){
// do something clever
}
Assuming that there is at least some link, it will return a fully marked up link failing all else. The behaviour I am after, however, is to be able to feed it some user input (after appropriate sanitation) and get back either a fully marked-up embed or a FALSE but not a hyperlink if the content is a URL that it does not recognise. The purpose is to detect if the given input text is a valid embeddable URL.
Can (or should) I use wp_oembed_get
to detect a valid embeddable link or is there a better way to do so?