Please visit Add Text to Videos with Watermark for a detailed introduction to adding a watermark to your videos. This particular blog explains what is going on under the hood of the WP plugin, and is useful only if you are adding your own custom-built variables as part of the watermark. Currently, name, IP, and email can be shown as part of the watermark.
Table Of Contents:
Watermark on videos adds extra security for the video from screen capture by adding variables such as email, IP or date information to the videos. Custom variables are now supported in plugin 1.6
Default WordPress fields that can be added
Our plugin has been configured to replace the following strings in the annotation code by default:
- {name} – Current User display name
- {email} – Current User email
- {username} – Current User Login
- {id} – Current User ID
Till version 1.5 of our WordPress video hosting plugin, watermark on videos could only have a limited number of dynamic variables. With version 1.6, we have now added filter hooks on the annotation code to enable other plugins or themes to change the annotation code.
Custom filter addition to the WordPress hook
You can now add a custom filter to the hook `vdocipher_annotate_preprocess` . Example code for adding custom filter is:
function customfunc($vdo_annotate_code){ $customVariable = "Hello world"; $vdo_annotate_code = str_replace('{var1}', $customVariable, $vdo_annotate_code); return $vdo_annotate_code; } add_filter('vdocipher_annotate_preprocess', 'customfunc');
Display WordPress Default field like User Fullname
An example code to display the full name is as follows:
function customvdofunc($vdo_annotate_code){ $fullname = ""; if (is_user_logged_in()) { $current_user = wp_get_current_user(); $firstname = $current_user->user_firstname; $lastname = $current_user->user_lastname; $fullname = $firstname . " " . $lastname; } $vdo_annotate_code = str_replace('{fullname}', $fullname, $vdo_annotate_code); return $vdo_annotate_code; } add_filter('vdocipher_annotate_preprocess', 'customvdofunc');
This would replace the string ‘{fullname}’ in the watermark code to the fullname of the logged in user.
JSON Code addition to the VdoCipher WordPress Plugin
The above code enables you to replace the token {var1} with the value of $customVariable. You can then use an annotation code like:
[ {'type':'rtext', 'text':'Your IP : {ip}', 'alpha':'0.8', 'color':'0xFF0000','size':'12','interval':'5000'}, {'type':'text', 'text':'{var1}', 'alpha':'0.5' , 'x':'150', 'y':'100', 'color':'0xFF0000', 'size':'12'} ]
This code on going through the above filter will become
[ {'type':'rtext', 'text':'Your IP : {ip}', 'alpha':'0.8', 'color':'0xFF0000','size':'12','interval':'5000'}, {'type':'text', 'text':'Hello world', 'alpha':'0.5' , 'x':'150', 'y':'100', 'color':'0xFF0000', 'size':'12'} ]
This function can be placed in the functions.php file in your theme. It is recommended to create a child theme before making such edits.
Example Steps to configure custom field “Phone number” as a watermark
You can configure user-specific details like “phone numbers” as a watermark using the VdoCipher WordPress video plugin annotation field and add_filter function in the functions file. shortcode embedded in WordPress.
Note: This phone number is a Custom Field created for illustration using a plugin named “Advanced Custom Fields” and the name for this custom field is phone_number. You might not need to configure such custom fields, your membership plugin that you might be using would already have such custom field addition functionality. The phone number addition of a user on their profile needs to be managed and taken care of from your WordPress setup side. Your WordPress developers can check and implement it. For this example, the sample WordPress viewer playing the video has the phone number 887788778877 on his profile.
Below is a code demonstrating the usage of a sample function for displaying the saved phone number as a watermark and plugin setup.
Additions in functions.php WordPress file
- Login to your WordPress account having theme editor access.
- Open functions.php through Appearance>Theme File Editor or Tools>Theme File Editor
- Add given below custom PHP function in the functions.php file and save the file.
function customvdofunc($vdo_annotate_code){
$Phonenumber = "";
if (is_user_logged_in()) {
$current_user = wp_get_current_user();
$PNO = $current_user->phone_number;
}
$vdo_annotate_code = str_replace('{Phonenumber}', $PNO, $vdo_annotate_code);
return $vdo_annotate_code;
}
add_filter('vdocipher_annotate_preprocess', 'customvdofunc');
Adding JSON to the VdoCipher WordPress Plugin field
You need to add the following JSON code in the plugin settings to call the custom function and display the viewer’s phone number as a watermark.
[{"type":"rtext", "text":"{Phonenumber}", "alpha":"0.90","color":"#FFFF00","size":"12","interval":"5000","skip":5000}]
On playback of the videos, the watermark will show the phone number of the viewer playing the video. Similarly, you can call other custom or WordPress data fields via functions.php and display the same by adding more lines of JSON code in the VdoCipher plugin field.
Supercharge Your Business with Videos
At VdoCipher we maintain the strongest content protection for videos. We also deliver the best viewer experience with brand friendly customisations. We'd love to hear from you, and help boost your video streaming business.
Leave a Reply