How to Protect WordPress Audios & Videos

Videos have become one of the most effective types of content to share your expertise and knowledge with others. Oftentimes you want your users to view but not download your private videos. So how to prevent users from downloading your private videos?

Don’t worry, we will guide you on how to achieve that with just a few single clicks.

Requirements:

Once you’ve installed our plugins, please follow these simple steps below to start protecting your WordPress audios and videos now.

At the moment, our plugins only protect mp3 and mp4 files. If you use the other formats, the video player won’t be shown.

Editor Toolbar

Classic Editor

Step 1: Go your where you want to insert your video then click on our plugin’s icon on your post editor.

Step 2: A popup will appear allowing you to choose a video that you want to protect. You can also adjust the width or height of your video (1) or enable autoplay (2).

It’s important to protect your video with PDA Gold so users can’t download it.

Step 3: Once you’ve chosen your video, click on the “Insert video” button

A shortcode will be automatically generated for you, which embeds your video into your content and protect them against downloading.

Gutenberg Editor

Step 1: Search and add our “Protected Video” block into your content

Step 2: Click “Add Media” then choose your desired video.
Please make sure that the video is protected. If it’s not, you can protect it directly on the right sidebar.

Step 3 (optional): Under our Protected video block settings, you can set the video’s height & width, add a custom poster as well as make the video autoplay if you’d like to.

Shortcodes

Instead of using our plugin UI in the visual editor, you can simply copy these shortcodes to your content to protect the private videos. This method supports both the default player, Plyr player and FV player plugin.

Default player

[protected_video width="512" height="308" id="897798" class="your-custom-class" autoplay="true" poster="your poster's image URL" video_id="Put your video id here"]

Please note that the video_id is required for the shortcode to run properly. You can get the ID number by hovering over the video’s title.

Plyr player

[protected_video width="512" height="308" id="897798" class="your-custom-class" autoplay="true" poster="your poster's image URL" video_id="Put your video id here" player="plyr"]

Since version 1.3.2, PDA Protect Videos extension provides another player with more built-in features:

  • Show video length before users click on the play button.
  • Picture in picture mode
  • Disable/Enable caption (WIP)
  • Change video quality (WIP)

FV player

FV player 6.x

Our plugins work seamlessly with FV Player version 6.x without any extra configuration.

Follow the steps below to protect and play videos via FV Player 6.x.

  1. Go to edit a post and click on the FV Player button
  2. Select and protect a video with PDA Gold plugin
  3. Click “Insert” to add the video shortcode to your content
[fvplayer src="protected video file URL" width="1900" height="854"]

It’s important to note that:

  • You have to disable Admin Video Checker for the videos to play properly with admin users.

  • The video won’t be protected from download if the file URL contains a query string such as ?t=xxx.
  • Our plugin supports mp4 and webm format only.
  • FV playlist hasn’t been supported yet.

FV player 7.x

Since version 7.0, FV Player change the logic to handle video files which is using the shortcode ID instead of file URL as in previous versions.

So you need to add some custom code to your (child) theme’s functions.php file for our plugins to works properly.

add_filter(
    'fv_flowplayer_args_pre',
    function ($arguments) {
        $src = $arguments['src'];
        $id = attachment_url_to_postid($src);
        if (!$id) {
            return $arguments;
        }
        if (
            !class_exists('PDA_v3_Gold_Repository')
            || !class_exists('Pda_v3_Gold_Helper')
        ) {

            return $arguments;
        }
        $repo_v3 = new PDA_v3_Gold_Repository();
        $is_protected_file = $repo_v3->is_protected_file($id);
        if (!$is_protected_file) {
            return $arguments;
        }
        $uid = Pda_v3_Gold_Helper::generate_unique_string();
        $repo_v3->create_private_link(array(
            'post_id' => $id,
            'is_prevented' => true,
            'limit_downloads' => null,
            'url' => $uid . '.mp4',
            'type' => 'p_expired',
        ));
        $private_link = Pda_v3_Gold_Helper::get_private_url($uid . '.mp4');
        $arguments['src'] = $private_link;

        return $arguments;
    },
    20
);

Troubleshooting

If the videos can’t run, it might be due to one of the following reasons.

  • You’re using a caching plugin or enabling server cache.
    • Solution: Exclude the video page from your cache.
  • Our htaccess rules are not inserted correctly.
Lasted updated on June 17, 2021