Search code examples
phpwordpressif-statementeco

How can I say that in php language if (isset($video_url)&not just only https sting can be found)?


I have a field inside the WordPress admin area, in the post-new.php section. I use the latest version of WordPress, as well as the Advanced Custom Fields plugin so that I can write out this field in header.php.
I use this field for the og:video tag, so that I can easily output a secure video url.
The problem is, the default field value is https, and so that I can recall it, the video url must always start with https.
When I click the publish button, the database saves this value, such that the og secure url in a blank state will only be https.
For example:

<meta property="og:video" content="https://www.neocsatblog.info/jwplayer/player.swf?file=https%3A%2F%2F&autostart=true&skinName=newtube&skinURL=https%3A%2F%2Fneocsatblog.info%2Fskinning-sdk%2Ffive%2Fnewtube%2Fnewtube.xml" />

This is a problem, because I don't want a blank video in the post for Facebook.
As such, I need to check two things in the header:

  1. Firstly: is the field empty?
  2. Secondly: Are there any characters in the string after https://?

If both the conditions are met, the code should output the url.
Current php code:

    $video_url = get_field('video_url');
    if (isset($video_url)) {
      $meta1='<meta property="og:video:type" content="application/x-shockwave-flash" />';
      $skinURL="https://neocsatblog.info/skinning-sdk/five/newtube/newtube.xml";
      $meta2=' <meta property="og:video" content="https://www.neocsatblog.info/jwplayer/player.swf?file='.urlencode($video_url).'&autostart=true&skinName=newtube&skinURL='.urlencode($skinURL).'" />';
      echo $meta1;
      echo $meta2;
     }

Solution

  • if (isset($video_url) && $video_url !== "https://") {