Description

Filter cvm_theme_support allows a video enabled WordPress theme to import videos into its own post type. When importing videos as posts designed for a third party WP theme, all embedding is managed by the theme. The plugin will only query Vimeo and create the posts that will have all details and custom fields needed by the theme filled with the video details.

The plugin supports by default a bunch of WordPress themes. This means that if a WordPress theme is supported by the plugin, all posts created from Vimeo videos can be created by the plugin as posts compatible with the theme. In this case, all embedding will be entirely managed by the theme. This is especially useful if your WordPress theme has video capabilities and you want to manage all videos as theme posts.

The filter has only one parameter which consists of an array of compatible themes. This is where your own theme compatibility details will need to be filled in order to allow the plugin to import videos as posts designed for your theme.

Parameters

$themes
(array)(required) An array of compatible themes.

Default:None

Examples

Let’s assume that the theme we’re trying to make compatible with the plugin does the following:

  1. Saves posts as post type video_post;
  2. It uses post format video for displaying videos;
  3. Category taxonomy for this post type is video_category;
  4. Tag taxonomy is video_tag;
  5. To embed videos in posts it needs the video URL on custom post field video_url;
  6. It can display video views, view count is stored in custom post field video_views;
  7. It can display the video duration that is stores in custom field video_duration.

First, you need to determine your theme name. To do this, look in your active theme folder for file style.css. Inside it, at the top of the file, there’s the theme name:
Theme Name: Fictional Theme Name

Next, we need to use the filter and tell the plugin how it should save the posts that are imported as compatible with the theme:

function my_theme_compatibility( $themes ){
	// theme name should be all lowercase
	$theme_name = strtolower('Fictional Theme Name');
	// add theme to compatible themes array 
	$themes[$theme_name] = array(
		'post_type' => 'video_post', // the post type used by the theme
		'taxonomy' 	=> 'video_category', // the category taxonomy
		'tag_taxonomy'	=> 'video_tag', // the tag taxonomy
		'post_meta' => array(
			'url' => 'video_url' // url of the video is stored in meta key video_url
		),
		'post_format' => 'video', // the post format used by the theme
		'theme_name' => 'Fictional Theme', // the human readable theme name
		'url'		=> 'http://somedomain.com/Fictional_theme', // theme homepage
		'extra_meta' => array(
			'video_duration' => array( // store the video duration
				'type' 	=> 'video_data', // data is pulled from video details
				'value' => 'human_duration' // for seconds duration, use only duration
			)	
		)
	);	
	
	return $themes;
}
add_filter('cvm_theme_support', 'my_theme_compatibility', 10, 1);

As you can see above, all you need to do to make a theme compatible with the plugin is to pass an array containing the details needed by the plugin to save any Vimeo video as a post that your theme can display.

From the above, please note keys post_meta and extra_meta. Key post_meta tells the plugin that the video URL should be stored in post custom field video_url. If the theme were to use the embed code of the video instead of the URL, the code would have been:

'post_meta' => array(
	'embed' => 'video_embed_code_custom_field' 
)

Basically, depending on whether your theme is using the video URL or the embed code, your should use either key url or key embed.

Next, extra_meta can hold various other meta fields that need to be set according to your theme needs. The structure of the array is:

'meta_field_name' => array( 
    'type' => type of data, 
    'value' => value to be stored 
)

In the above example, type can have any of these values:

1. static : for static values, for example, you want videos to have a custom field that when set to true, flags the post as video. In this case, the field would look something like this in the array:

'is_video' => array( '
    'type' => 'static',  
    'value' => true 
)

2. video_url : when used, it will store the video URL into the specified custom field:

'video_url_field_name' => array( 
    'type' => 'video_url', 
    'value' => '' )

3. player_settings : if your theme requires any player settings to be defined (for example video width), you can use this key. The plugin will automatically retrieve the setting you have set in plugin Settings page under Embedding and will set the field with the value specified in your settings:

'video_width_field_name' => array( 
    'type' => 'player_settings', 
    'value' => 'width' )

4. video_data : same as the above but it applies to the video details retrieved from Vimeo for the current video being inserted. For example, if a certain custom field needs to contain the duration of the video, the array will look like this:

'video_duration_field_name' => array( 
    'type' => 'video_data', 
    'value' => 'human_duration' )