Give Your Clients Personalised Screencasts in the WordPress Admin Panel

Give Your Clients Personalised Screencasts in the WordPress Admin Panel

Tutorial Details
  • Program: WordPress
  • Version: 3.0+
  • Difficulty: Easy
  • Estimated Completion Time: 30 min

In this tutorial, I’ll show you an easy way to provide your clients with some personalised video screencasts directly in the WordPress Admin Panel. We’ll be doing this using a open-source media player and a little bit of PHP trickery to automate the process of making new videos available to the client.


Upon completing an awesome project and handing it over to a client, what’s your current method for providing appropriate training? Sure, WordPress has one of the best administration panels available and the majority of the features are fairly easy to understand / learn – but what happens when you come across a client that encounters some difficulty? How do you show a less-than-savvy client how to use that amazing new plugin you’ve just written?

Your clients will thank you for this!

From experience, the most effective way to do this is to record mini-screencasts showing exactly how to do it. These do not have to be professional quality (though Jeffrey Way has produced a course to help with that) as no-one other than the client will ever see them. Also, if you’d rather not speak over the video – then don’t! Just record your screen only.

This method of providing screencasts is designed to reduce the amount of phone calls and emails you receive asking ‘why doesn’t it look right?’ or ‘can you explain that to me again?’. Your clients will thank you for this too, as they can return to the videos whenever they need to brush up on their skills


We don’t want:

  1. To have to use an external 3rd-party video service
  2. To have any of our videos showing up in the media library inside the WordPress Admin Panel

We do want:

  1. An easy, fast way of providing our videos
  2. The ability to upload a video and have it show up instantly in the WordPress Admin Panel

Tutorial Overview

Here’s a quick run-through of what we’ll be covering:

  1. First we’ll set up the directory structure and bring in our dependencies (we’ll be using Flowplayer)
  2. Then we’ll create a simple page in the WordPress Admin Panel
  3. Next we’ll dive into our video directory and generate a list of the available videos
  4. Finally we’ll write a tiny bit of JavaScript that will load each video when the links are clicked

Super simple and super effective! Let’s get coding!


Step 1 Create the Plugin Directory and Files

  1. Create a new folder inside your plugins directory called videos
  2. Create a file called videos.php
  3. Inside the Videos folder, create 3 more folders – js, mp4, swf

Step 2 Download Flowplayer

“Flowplayer is an Open Source video player for your website. For site owners, developers, hobbyists, businesses and programmers” – Sounds perfect for our project! Download it here: Download (get the free version)

When you download the ZIP file, it will contain an example directory, a README file and a licence. We just want the JavaScript file and the two swf files. As seen below.


Step 3 Copy the Files Into the Plugin Directory

Take the 3 files shown above and put them into the corresponding directories that we created prior. Your file structure inside the videos directory should now look like this.


Step 4 The Plugin Comments

Ok, so now it’s time to open up videos.php and begin authoring our plugin! As with all WordPress plugins, we need to add this information at the top of our plugin file.

/*
Plugin Name: Tutorial Videos
Plugin URI: http://wp.tutsplus.com
Description: This plugin displays the Tutorial Training Videos.
Author: Shane Osbourne
Version: 0.1
Author URI: http://wp.tutsplus.com/author/shaneosbourne/
*/

Step 5 Create the Output Function

Because we’ll be dropping in and out of PHP in this tutorial, I’ll do my best to explain each section – but fear not, it will become a lot clearer when you review the entire file at the end.

wp_videos_page()

function wp_videos_page() {
	/** Following snippets go here **/
}

Step 6 A Quick Helper Function

We don’t want to repeat ourselves, so I like to create a little helper function like this to return the current working directory of the plugin we’re working on (it will be helpful later when we need access to assets in the plugin directory).

video_plugin_path()

/** returns "http://example.org/wp-content/plugins/Videos" **/
function video_plugin_path() {
	return path_join(WP_PLUGIN_URL, basename(dirname( __FILE__ )));
}

Step 7 Set Up Some Variables

  1. First we specify where we’re going to keep our video files
  2. Then we retrieve the ‘real path’ to our video directory. This is because later we’ll be searching our mp4 directory for video files using glob() and it requires a real path on the filesystem, not a URL.
  3. Then we create another variable that will store the entire URL into our mp4 directory
/* within wp_videos_page() */
$wp_video_dir       = '/mp4';
$wp_video_real_path = dirname(__FILE__) . $wp_video_dir;
$wp_video_url       = video_plugin_path() . $wp_video_dir;

Step 8 The Opening HTML

We’re going to drop out of PHP now so that we can enter some plain HTML. First of all we open up a div tag with a class of wrap – this is a generic wrapper class that WordPress uses in the admin panel. Next we set a heading for the page and use one of WordPress’ icons (the media uploader)

//exiting php
?>
	<div class="wrap">
		<div id="icon-upload" class="icon32"><br></div>
		<h2>Content Management Tutorial videos.</h2>

Step 9 Get the Video Files in the mp4 Directory

  1. Here we will use glob() to list all of the available video files in the mp4 directory.
  2. We pass our filesystem path along with a regular expression that will match any version of mp4 (MP4 and mp4, for example)
  3. $videos will now be an array containing all of the video files.
<?php
// Array returned
$videos = glob($wp_video_real_path . "/*.[mM][pP]4");

Step 10 The Loop

Now that we have an array containing paths to our video files, we loop through each one and generate some HTML markup that will display a link to each clip.

  1. First we check that $videos is not an empty array (if it is, we skip through to a simple message)
  2. Then we enqueue the Flowplayer JavaScript file
  3. Next we output a simple ‘please choose a video to watch’ message and open up a <ul>
  4. Then it’s the actual loop. We go through each file path and extract the filename only. Then we use str_replace and ucwords() to create a title for each video. This is so that files named in this format create-a-page.mp4 will become Create a Page.

    			'create-a-page.mp4' //<--from this
    			'Create a Page'     //<--to this
    		
  5. Next we generate some HTML markup for each video file with a data-video-url attribute and a class of video-link.
    • data-video-url – this will be the URL path to each video file. We’ll retrieve it later when we write the JavaScript.
    • video-link – we’ll use this CSS selector to listen for clicks on the links.
  6. Finally, we close off the unordered list and set our default message for when there are currently no videos.
if (!empty($videos)) {

	wp_register_script('flowplayer_js', video_plugin_path() . '/js/flowplayer-3.2.6.min.js' );
	wp_enqueue_script('flowplayer_js');

	$o  = '<p>Please choose a Video to watch</p>';
	$o .= '<ul>';

	foreach ($videos as $video) {

		$video_file   = basename($video);
		$needles      = array('-', '.mp4');
		$replacements = array(' ', '');
		$video_title  = ucwords(str_replace($needles, $replacements, $video_file));

		$o .= sprintf(
			('<li><a href="" data-video-url="%s" class="video-link">%s</a></li>'),
			$wp_video_url . '/' . $video_file,
			$video_title
		);
	}
	$o .= '</ul>';
	echo $o;
}
else {
	echo 'Sorry there are no videos to view yet, I\'ll let you know when there is.';
}
?> //<-- Exiting php again

Step 11 The Video Container

Now it’s time to create a div with an ID of player – this is what the video player will be loaded into. Also we close off the wrapper div that we opened earlier.

Note: By default, Flowplayer will load your videos into the specified div at the exact resolution you recorded them at. You could add some inline styles to the div to force the size of the video player to be whatever you want – but be careful if you do this, as your videos may not look great if you are trying to squeeze them into a different aspect ratio.

<div id="player"></div>
</div><!-- #Wrap -->

Step 12 The JavaScript

Now we just need to listen for clicks on our links, grab the video URL and load the player into the div we created above.

  1. We’ll listen for when our links are clicked and extract the data-video-url attribute from each one
  2. Then we’ll call a function that will load our video into the div
  3. The function is play_video – it’s responsible for calling the flowplayer() method. It takes 3 arguments:
    1. The ID of the div that the player will be loaded into
    2. The path to the swf file that Flowplayer uses to play the videos
    3. The video URL
  4. Finally we’ll ensure the video is in view by automatically scrolling to it each time a new video is loaded
<script>
	// catch clicks on the video links
	jQuery('.video-link').on('click', function(e) {

		var link       = jQuery(this);
		var video_url  = link.data('video-url');
		play_video(video_url);

		e.preventDefault();
	});

	var play_video = function(video_url) {

		var plugin_url = '<?= video_plugin_path() ?>';
		var swf_url    = plugin_url + '/swf/flowplayer-3.2.7.swf';
		flowplayer("player", swf_url, video_url);

		// auto scroll to top of player
		jQuery('html, body').animate({
				scrollTop: jQuery('#player').offset().top-50
		}, 1000);
	}
</script>

Step 13 Register the Page

We’re almost finished now, we just need to register our page so that it shows up in the WordPress Admin menu on the left hand side.

function wp_video_option_page() {

	add_menu_page('Tutorial Videos', 'Tutorial Videos', 'manage_options', 'wp_tutorial_videos', 'wp_videos_page');
}
add_action('admin_menu', 'wp_video_option_page');

Step 14 Activate the Plugin

Everything is ready now. All that’s left is for you to upload your videos and activate the plugin.


Conclusion

That’s it! If you’ve made it this far you now have a page where you can share personalised screencasts to your clients in the easiest way possible. All you have to do is upload your videos into the mp4 directory when needed and your clients will immediately have access to them!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • David Kartuzinski

    This is great. I record using Jing and generally hide the videos out in Youtube, but this is a much more elegant solution.

    Thanks.

    -DK

  • http://www.localBusinessPageOne.com Randy

    I love this. It’s way better than creating videos and putting them up on YouTube. But I do have a few questions… (of course)

    1) Steps 1 through 10. These all go into the videos.php file. Correct?
    2) Step 11 – where does this go?
    3) Step 12 – edit the js we uploaded from Step 3? Or create a new one?
    4) Step 13 – where does that code go?

    Thanks again Shane. Nice work!

    • Shane Osbourne

      Hi Randy, thank you for the kind words :)

      Sometimes when explaining how to author a WordPress plugin, it can become a bit difficult to understand where we are currently in a file – we try our best!

      If you download the source files and take a look at Videos.php (the only file that we edit) – it should become a lot clearer when you can see the code all in one place.

      • http://www.localbusinesspageone.com Randy

        Hi Shane:

        I feel like an idiot. lol Got it all sussed out.
        Now to do some vids and amaze my clients!

        Randy

  • eyal

    great idea.

    now just a tutorial on how to create the mp4 videos…

  • Pingback: Give Your Clients Personalised Screencasts in the WordPress Admin Panel | Qoozon

  • http://ak.gd/ André

    Thank, I think I’ll add that in future and will save some client calls!

    • Shane Osbourne
      Author

      That’s the idea André!

      I can tell you from experience that some Clients really do appreciate this.

      :)

  • http://www.designpalatset.se Designpalatset

    This is really clever! Already got plain html/text documentation in my themes dashboard, never thought of putting videos there though. Thanks!

    • Shane Osbourne

      Thanks! Glad you like it :)

  • http://www.reverbstudios.ie Leon

    Is there any way to edit this to grab videos off a remote server, ie, I’d like to be able to include this plugin in client’s sites but only have to upload the videos in 1 place, my own server??

    • Shane Osbourne

      Hi Leon.

      You could, but then you wouldn’t be able use glob() to list the files in the directory automatically.

      Flowplayer will happily play a video file from another domain though – so instead of looping over the result of glob(), you could provide an array of urls (that point to your videos on another server) and do it that way.

      • http://www.reverbstudios.ie Leon

        Hmm, not sure I know enough about php to change that but I’ll try thanks.

        It’s a cool tutorial and idea but you’d have to upload any new videos to possibly hundreds of client sites. Bit of hassle!?

        • Wade

          or you could take shane’s suggestion one step further and populate the array from an external xml or json source, that way you only need to update one file to feed to all your clients, and still host your own video files. so updating and creating new video files would be a breeze.

          great tut by the way Shane!

          • Shane Osbourne
            Author

            Good idea Wade. :)

  • Pingback: Give Your Clients Personalised Screencasts in the WordPress Admin Panel | Wptuts+ : Brutally Succinct: curating web designer resources

  • juju

    Hey Shane,

    Thanks for this tut, great idea.

    I was just wondering, if I wanted to add this to my theme instead of a making the plugin, could I create the folders in my theme folder and then include the videos.php file in my theme functions.php file?

  • Pepa

    Hi!! Thanks so much for this. It’s exactly what I needed. I have upload everything and is showing fine but when I click in the video link noyhing happens. Do you know what can be causing this?? Thanks again!!

  • Pepa

    I have changed the flowplayer version in videos.php. But now I get this error:

    An Actionscript error ocurred:
    Error:200, Stream not found,………….. and so on. But my video is there and listed. Why??

    Thanks!!!

  • Pepa

    Sorry for all the comments. The video name was too long. I now have it listed and when the link is pressed I hear it but nothing shows in the screen. Only sound!!

  • http://www.albruna.nl Martin

    I am used to creating some videos with DemoBuilder and placing the html and swf files on their server and send them the links to it, but I think this solution is way more elegent so I am definately going to give it a a try.

    Thanks for the tutorial.

  • http://www.wpbeginner.com Syed Balkhi

    Great article. What would be even more interesting is if we can host the videos elsewhere rather than bundling it with the plugin (this will speed things up). Because chances are that most of these plugins won’t make it in the repository. So automatic upgrades will be an issue. You may want to give your clients most recent videos ….

    Updating the videos on off-site location would be an easier solution.

    Not to mention, you don’t want to use the precious server resources of your client….

  • http://www.techiesquare.com/ Bharat Chowdare

    It would be great if all the videos are hosted at one place and can be accessed through dashboard after installing a “plugin”. Yes, adding many videos on clients server is not good and expecting a clean plugin based on this idea very soon. Thanks for the files, just downloaded them.

  • http://en.bainternet.info bainternet

    Nice idea, but i prefer to upload videos to youtube as unlisted (to allow “private” embedding).
    and i add them to the dashboard as help tabs using `add_help_tab()`.

  • Pingback: Give Your Clients Personalised Screencasts in the WordPress Admin Panel | Wptuts+

  • http://www.reverbstudios.ie Leon

    My free “WordPress Help Menu” plugin avoids all that uploading and uses php “file get-contents” to grab a web page off my server that shows a list of WordPress help resources and some embedded videos in client’s admins. If I want to change or add something, I just do it in 1 file and all clients sites get updated automatically!

    http://www.reverbstudios.ie/1818/wordpress-help-menu-plugin/

  • Andy

    Hi,
    Thank’s for you tutorial. It’s very interesting, but your code doesn’t works: audio works fine, but video doesn’t shows. Can you give me some advice – what can be a reason?

    • Shane Osbourne
      Author

      Hi Andy – I’m not entirely sure what is causing that, (someone else also mentioned it). All the MP4 files I’ve tested with all worked fine.

      Perhaps it could be an issue with the file you’re trying to play, or a problem specific to your browser.

      Sorry I can’t be of any more help.

  • Shannon

    Thanks for this tutorial!

    When I upload my mp4s, the list is printed on the admin page, but all the links just link back to the same admin page, not to the video files.

    At first I thought it was my mistake, because I hand-coded the tutorial file. But then when I copy and paste the source files I get the same result.

    Is it something about my video? the title is long and uses – to separate words…

    Thanks for any help.

    • Shane Osbourne
      Author

      Hi Shannon.

      It sounds very much like a JavaScript error (in the tutorial, we are using JavaScript to intercept clicks on the links – if it fails to do so, the page will just reload)

      Reload the plugin page and then open up the console (F12) & see if there are any errors.

  • Pingback: 5 Ways to Boost Your Wordpress Administration Interface | Visceral

  • merwintest

    Hi shane.. I downloaded your plugin and install to my plugin, I can see the list of my videos but I its ony sound no video appearing.

    can you help me pls.. thanks..

  • http://nclegalmarketing.com bmehder

    This is a great plugin, and will save me and my clients lots of time and money. Thank you for the tutorial.

    One question: How would I go about changing the position of the “Tutorial Videos” label in the admin sidebar?

    I would like it to be before or after the “Site Notes” label, which was installed using the “Dashboard Site Notes” plugin.

    I found this article helpful: http://wp.tutsplus.com/tutorials/creative-coding/customizing-your-wordpress-admin/

    But, I do not know how to incorporate the technique from the article with this tutorial.

    Any advice would be appreciated.

  • Pingback: Marcacci Communications

  • http://thinkdigitalwp.com Russell

    What if I am using this on multisite. I want to make this for each client. so videos will be network enabled, but i want to create on for a client.

    so folder will be videoforsteve.

    When I go to activate the plugin, I get

    Fatal error: Cannot redeclare wp_videos_page() (previously declared in /home/mediaone/public_html/csc/wp-content/plugins/Videos/Videos.php:20) in /home/mediaone/public_html/csc/wp-content/plugins/Videos1/Videos.php on line 83

    any help? how can I rename the folder per client name or business name?

  • http://www.thesisvideotutorials.com Amelia Smith

    I figured out the issue with the videos not showing yet the audio plays.
    You need to add height and width parameters to the player div:

    Works like a dream for me now :)

    Amelia

  • http://twitter.com/ignitionlab Chris Young

    Interesting tutorial, sadly I get the same result as Shannon – Once video is uploaded, clicking the link does
    nothing. Quick check via console shows the following error:

    Uncaught TypeError: Object [object Object] has no method ‘on’ admin.php:205

    Is there a solution for this ? Thanks,

  • Pepa Cobos

    I have the same issue. Trying to click on video link and nothing happens. Anybody has an answer???

  • gillespieza

    When I tried this, it didn’t look like the flowplayer script was being called at all. I can’t find it anywhere when viewing the source of the admin page?

    Also, FYI, the flowplayer filenames and directory structure have changed a bit since your tutorial using version 3.2

  • wpsuperplugins

    Nice tutorial! Question though!
    Can you not just have them pop up in light box playing from youtube? What would be the best way do this??