Settings'; array_unshift($links, $settings_link); } return $links; } function register_vid_settings() { // whitelist options register_setting( 'vid_options', 'vid_options_field' ); } //------------------------------------------------------------------------------------------------------------------------------- /** * Admin page plugin options ** //---------------------------------------------------------------------------------------------------------------------------- */ function vid_plugin_options() { ?>

Responsive Video Settings

true, '_builtin' => false ); $output = 'names'; // names or objects, note names is the default $operator = 'and'; // 'and' or 'or' $p_types = get_post_types($args,$output,$operator); // loop through all costom post types and create an array $enable = array(); foreach ($p_types as $p ) { $enable[$p] = $options["enable_$p"]; } //print_r($enable); ?>

 

You can select which post, page or custom post type you want to allow the add video settings to display on.
Custom posts are added to this list automatically once they have been registered in functions.php in your theme.

Select post types to allow videos to be displayed
  • checked="checked" />
  • checked="checked" />
  • true, '_builtin' => false ); $output = 'names'; // names or objects, note names is the default $operator = 'and'; // 'and' or 'or' $post_types=get_post_types($args,$output,$operator); // loop through and display a check box for each custom post type foreach ($post_types as $post_type ) { ?>
  • $value ) { // if any of the items in the array have a value of 1 mark them as checked //echo "Key: $key; Value: $value
    \n"; if ( $key == $post_type && $value == "1" ) { ?> checked="checked" />

Notes for theme developers

Each video is added as custom meta fields which means you can call auto-generated thumbnails from both YouTube and Vimeo to be used instead of a post thumbnail.

To do this:

Open archive.php and find where your post thumbnail sits within the loop. Replace it with the code below.
This code finds the meta information for each post, checks to see if a YouTube video is present. If it isn't, checks for a Vimeo video. If neither have been used, and assuming you are using the "Featured Image" for your thumbnail, it will fall back to the Featured Image. If that hasn't been set either, no image will display.

global $post;
$meta = get_post_meta($post->ID,'_video_meta',TRUE);
/* Setup $post and get the meta data from the custom fields */

if ( $meta['type'] == "youtube" ) {

/* Break the video URL apart to find the ID */
$loc = strpos($meta['url'],"v=");
$videoid = substr($meta['url'], $loc + 2);

/* YouTube give you a choice of 3 thumbnails: 0.jpg, 1.jpg, 2.jpg */
echo '‹img src="http://img.youtube.com/vi/'.$videoid.'/0.jpg" alt="the_title();>" /›';

} else if ( $meta['type'] == "vimeo" ) {

/* Vimeo's URL structure is slightly different and needs breaking apart differently */
$loc = explode( "/", $meta['url'] );
$videoid = end($loc);

/* Vimeo stores all info about each video in JSON, PHP and XML Formats. This is the PHP version */
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$videoid.php"));

/* Depending on the size of the image needed you could use ['thumbnail_large'], ['thumbnail_medium'] or ['thumbnail_small'] */
echo '‹img src="'.$hash[0]['thumbnail_large'].'" alt="the_title();" /›';

} else {

the_post_thumbnail( 'thumbnail' );

}

The autogenerated images will need some styling to make them display the same way your post thumbnails do. This can be done with standard CSS though, exactly as you would do with any other images.

Happy coding! ~ grin!

Need help with the Responsive Videos plugin?"; $text .= "

Check out the documentation.

"; $text .= "Documentation
Support forums"; } return $text; } add_action('contextual_help', 'vid_contextual_help', 10, 1); //------------------------------------------------------------------------------------------------------------------------------- /** * Add the videos directly into pages and posts * * **/ //---------------------------------------------------------------------------------------------------------------------------- */ // Creates custom meta box for video settings define('MY_WORDPRESS_FOLDER',$_SERVER['DOCUMENT_ROOT']); define('VIDEO_PLUGIN_FOLDER',get_settings('siteurl')."/wp-content/plugins/responsive-video/"); add_action('admin_init','video_meta_init'); function video_meta_init() { // registers the style for the meta boxes in the admin panel wp_enqueue_style('video_meta_css', VIDEO_PLUGIN_FOLDER . 'css/admin-responsive-videos.css'); // Set up to use the selections from the main admin screen above to determine which add / edit screens allow videos to be inserted using the shortcode $options = get_option('vid_options_field'); // get the standard page and post types $enable_post = $options["enable_post"]; $enable_page = $options["enable_page"]; // if these have been selected show on the appropriate add / edit screens if ( $enable_post == "1" ) { add_meta_box('video_all_meta', 'Video Settings', 'video_meta_setup', 'post', 'normal', 'high'); } if ( $enable_page == "1" ) { add_meta_box('video_all_meta', 'Video Settings', 'video_meta_setup', 'page', 'normal', 'high'); } // Find all custom post types $args=array( 'public' => true, '_builtin' => false ); $output = 'names'; // names or objects, note names is the default $operator = 'and'; // 'and' or 'or' $p_types = get_post_types($args,$output,$operator); // loop through all costum post types and create an array $enable = array(); foreach ($p_types as $p ) { $enable[$p] = $options["enable_$p"]; // loop through the $enable array to find post type and value foreach ( $enable as $key => $value ) { // if post type has a value of 1 display the custom meat box on this add / edit screen if ( $key == $p && $value == "1" ) { add_meta_box('video_all_meta', 'Video Settings', 'video_meta_setup', $p, 'normal', 'high'); } } } // original add a meta box for each of the wordpress page types: posts and pages /* foreach (array('post','page') as $type) { add_meta_box('video_all_meta', 'Video Settings', 'video_meta_setup', $type, 'normal', 'high'); } */ // add a callback function to save any data a user enters in add_action('save_post','video_meta_save'); } function video_meta_setup() { global $post; // using an underscore, prevents the meta variable // from showing up in the custom fields section $meta = get_post_meta($post->ID,'_video_meta',TRUE); // HTML for meta boxes ?>

Inserts a video directly into your page / post content using the shortcode [responsive_vid].

Enter in a name

Choose the video type

Paste the URL of the video from the main address bar here

(optional) Enter in a description

Copy and paste the shortcode [responsive_vid] anywhere within the main content of the page

'; } function video_meta_save($post_id) { // authentication checks // make sure data came from our meta box if (!wp_verify_nonce($_POST['video_meta_noncename'],__FILE__)) return $post_id; // check user permissions if ($_POST['post_type'] == 'page') { if (!current_user_can('edit_page', $post_id)) return $post_id; } else { if (!current_user_can('edit_post', $post_id)) return $post_id; } // authentication passed, save data // var types // single: _my_meta[var] // array: _my_meta[var][] // grouped array: _my_meta[var_group][0][var_1], _my_meta[var_group][0][var_2] $current_data = get_post_meta($post_id, '_video_meta', TRUE); $new_data = $_POST['_video_meta']; video_meta_clean($new_data); if ($current_data) { if (is_null($new_data)) delete_post_meta($post_id,'_video_meta'); else update_post_meta($post_id,'_video_meta',$new_data); } elseif (!is_null($new_data)) { add_post_meta($post_id,'_video_meta',$new_data,TRUE); } return $post_id; } function video_meta_clean(&$arr) { if (is_array($arr)) { foreach ($arr as $i => $v) { if (is_array($arr[$i])) { video_meta_clean($arr[$i]); if (!count($arr[$i])) { unset($arr[$i]); } } else { if (trim($arr[$i]) == '') { unset($arr[$i]); } } } if (!count($arr)) { $arr = NULL; } } } //------------------------------------------------------------------------------------------------------------------------------- /** * Create the video Shortcode for use in content **/ //---------------------------------------------------------------------------------------------------------------------------- */ function videoCode($atts, $content = null) { global $post; $meta = get_post_meta($post->ID,'_video_meta',TRUE); // if the YouTube option is selected if ( $meta['type'] == "youtube" ) { // Find the YouTube ID $loc = strpos($meta['url'],"v="); $videoid = substr($meta['url'], $loc + 2); extract(shortcode_atts(array( "vid_url" => $videoid, "vid_name" => $meta['name'], "vid_desc" => $meta['description'], ), $atts)); return '

'.$vid_name.'

'.$vid_desc.'

'; // Else this is a Vimeo video as there are only two options } else { // Find the Vimeo ID $loc = explode( "/", $meta['url'] ); $videoid = end($loc); extract(shortcode_atts(array( "vid_url" => $videoid, "vid_name" => $meta['name'], "vid_desc" => $meta['description'], ), $atts)); return '

'.$vid_name.'

'.$vid_desc.'

'; } } add_shortcode('responsive_vid', 'videoCode'); ?>