Custom Fields
Re-Envisioned
Support General OEmbed Empty Control

This topic contains 3 replies, has 2 voices, and was last updated by  Anh Tran 1 year ago.

  • Creator
    Topic
  • #8849

    bulutozturk1993
    Participant

    Hi,

    How can I check empty control when I use OEmbed? If it empty, it return “Embed HTML not available”.

    Thanks!
    Kind regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #8852

    Anh Tran
    Keymaster

    You can use the rwmb_meta() function, it will auto checks whether the media player is available. If not, it shows the “Embeded HTML is not available” message.

    If you want to check that your self, you can do similarly like here:

    https://github.com/wpmetabox/meta-box/blob/master/inc/fields/oembed.php#L41

    #8895

    bulutozturk1993
    Participant

    Hi Anh,
    This is not good for me. Because If there isn’t any embed, I don’t want print HTML codes. How can I can check empty control?
    Kind regards.

    #8906

    Anh Tran
    Keymaster

    In the link I pasted above, there’s full code to detect if the URL is a valid oembed, you can try it, like this:

    $url = get_post_meta( get_the_ID(), 'oembed', true );
    $args = ['width' => 640];
    $embed = wp_oembed_get( $url, $args );
    if ( ! $embed ) {
        $embed = $GLOBALS['wp_embed']->shortcode( $args, $url );
    }
    if ( $embed ) {
        echo $embed;
    } else {
        // Do something when there's no controls if you want
    }
Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.