1

I have created a custom post type which will store posts that contain videos, i have made use of the ACF wysiwyg field to display the video content and i have a further true/false field which will enable/disable the video. Basically if it is enabled, it will display the video on the page and if it is disabled then it won't display on the page.

Now for the tricky part, when a video is disabled i need to either rename the file on the server or move it to a temporary location. If there are other options, i am open to ideas. The requirement for this is so that they can have control of when the video is viewed.

If the video is shared on Facebook, you would normally be able to still view that video regardless because it would still exist on the server, however we need to be able to control that. If i share a video today and disable it tomorrow, no one else clicking on the link for that video should be able to view it until it is enabled again.

I tried using a rename function but i don't think that is the best way of doing this, as if i enable the video again it would need to have the same name as before it was disabled. Perhaps there is another way of achieving what i need to do?

Video path comes from my ACF field. (The wysiwyg editor)

function jd_video_path($video_path) {
    global $wpdb;

    $video_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE guid='%s';", $video_path ) );

    $post = get_post($video_id);
    $file = get_attached_file($video_id);
    $path = pathinfo($file);

    $new_file_name = "offline";
    $new_file = $path['dirname']."/".$new_file_name.".".$path['extension'];

    rename($file, $newfile);    
    update_attached_file( $video_id, $new_file );

    var_dump($path);
}
2
  • I would look into some kind of rewriting. The video would have a rewritten URL with a unique id that never changes, you just enable/disable the connection to the actual file as needed. You never expose the real file location so it doesn't have to be moved or renamed.
    – Milo
    Commented Jul 28, 2018 at 18:03
  • That is an interesting idea @Milo, how would you suggest enabling or disabling that connection?
    – zen_1991
    Commented Jul 30, 2018 at 12:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.