Video Blogster support for WordPress Video Gallery


CaptureThe WordPress Video Gallery helps erecting a video site, but it uses custom posts and tables and expects you to enter each video manually through it’s form.

If you wish to have Video Blogster import videos automatically into WordPress Video Gallery, you’ll have to use some code to prevent Video Blogster from creating each WordPress post, letting WordPress Video Gallery create their own custom post and tables instead.

WordPress Video Gallery was also called Contus Video Gallery, so I may use ‘Contus’ for short.

Step 1 – Create your WordPress Video Gallery categories and note the IDs of each. (Note that WordPress Video Gallery categories are not the same as WordPress categories)
Capture

Step 2 – Create your Video Blogster feeds and note the ID of each, and which corresponding WordPress Video Gallery category ID you want it to import videos to.
Capture

In this example, I’ll map Video Blogster feeds 1,2 and 4 to Contus Category ‘Video Game’ (ID 5), Video Blogster feed 3 to Contus Category ‘Animals’ (ID 3) and made featured, and all other feeds will go into Contus Category ‘Movie Trailer’ (ID 1).

Step 3 – Add the following PHP code to your theme’s functions.php file.

/* Support for https://wordpress.org/plugins/contus-video-gallery/
*
* The action 'vb_create_the_post' will be called right before Video Blogster creates the WordPress post.
* The function below will have Contus Video Gallery create it's custom WordPress post instead, and other custom tables.
* Then it will return the custom post ID so that Video Blogster knows the custom post was created.
* Video Blogster will then import and attach any video comments to the post as well as the custom meta fields.
*
* NOTE: You HAVE to map the Video Blogster feeds to the corresponding Contus Video Gallery category ids.
* (Contus Video Gallery categories are NOT the same as WordPress categories)
* Edit the lines after 'CHANGE according to your site!' below.
*
*/

add_action('vb_create_the_post', 'add_to_wordpress_video_gallery', 10, 2);

// Stop Video Blogster from creating a post, have WordPress Video Gallery do it instead with their custom setup
function add_to_wordpress_video_gallery( $vidpost, $videoInfo ) {
global $wpdb;

$file = WP_PLUGIN_DIR . '/contus-video-gallery/admin/models/video.php';

if ( ! file_exists( $file ) ) {
return $vidpost; // Contus WordPress Video Gallery plugin must exist and be activated
}

include_once( $file );

// CHANGE according to your site!
if ( $videoInfo['feedID'] == 1 || $videoInfo['feedID'] == 2 || $videoInfo['feedID'] == 4) {
$featured = 0; // 1 = featured video
$playlist = 5; // the id of a valid Video Gallery category - important!
}
else if ( $videoInfo['feedID'] == 3 ) {
$featured = 1; // 1 = featured video
$playlist = 3; // the id of a valid Video Gallery category - important!
}
else {
$featured = 0; // 1 = featured video
$playlist = 1; // the id of a valid Video Gallery category - important!
}

// translate Video Blogster data to Contus custom WordPress Video Gallery data

$ordering = $wpdb->get_var( 'SELECT count( ordering ) FROM ' . $wpdb->prefix . 'hdflvvideoshare' );

$videoData = array(
'name' => $videoInfo['post_title'],
'description' => $videoInfo['desc'],
'embedcode' => $videoInfo['videoEmbed'],
'file' => addslashes( trim( $videoInfo['url'] ) ),
'file_type' => 1,
'member_id' => wp_get_current_user()->ID,
'duration' => ! empty ( $videoInfo['duration'] ) ? $videoInfo['duration'] : '0:00',
'hdfile' => '',
'streamer_path' => '',
'islive' => 0,
'image' => $videoInfo['img'],
'opimage' => $videoInfo['img'],
'srtfile1' => '',
'srtfile2' => '',
'subtitle_lang1' => '',
'subtitle_lang2' => '',
'link' => $videoInfo['url'],
'featured' => $featured,
'download' => 0,
'postrollads' => 0,
'midrollads' => 0,
'imaad' => 0,
'prerollads' => 0,
'publish' => 1,
'google_adsense' => '',
'google_adsense_value' => '',
'amazon_buckets' => 0,
'post_date' => date( 'Y-m-d H:i:s' ),
'ordering' => $ordering,
'slug' => ''
);

$vm = new VideoModel();
$contusID = $vm->insert_video( $videoData );

// Contus also uses its own custom tags table:
if ( ! empty( $videoInfo['tags'] ) ) {
$tags_name = $videoInfo['tags'];
$strip_tags_name = strtolower( stripslashes( $tags_name ) );
$ambersand_tags_name = preg_replace( '/[&:\s]+/i', '-', $strip_tags_name );
$spl_tags_name = preg_replace( '/[#!@$%^.,:;\/&*( ){}\"\'\[\]<>|?]+/i', '', $ambersand_tags_name );
$seo_tags_name = preg_replace( '/---|--+/i', '-', $spl_tags_name );
$wpdb->query( 'INSERT INTO ' . $wpdb->prefix . 'hdflvvideoshare_tags ( media_id,tags_name,seo_name ) VALUES ( '.$contusID.', "'.$tags_name.'", "'.$seo_tags_name.'" )' );
}

// now we have to map it to Contus custom 'playlist' - whatever custom 'category' that is
$str = ' INSERT INTO ' . $wpdb->prefix . 'hdflvvideoshare_med2play ( media_id,playlist_id,sorder ) VALUES ( '.$contusID.', ' . $playlist . ', 0 )';
$wpdb->query( $str );

# return postID so Video Blogster will add meta fields and comments!
$postID = $wpdb->get_var( 'SELECT slug FROM ' . $wpdb->prefix . 'hdflvvideoshare WHERE vid ='.$contusID );

return $postID;
}

Step 4 – Edit the code above to map your Video Blogster feeds so they will import videos to your site’s Contus WordPress Video Gallery categories. These are the lines below ‘CHANGE according to your site!’ It’s very important they match, otherwise Contus will never show the videos.

Remember, since Contus Video Gallery is creating the posts, the ‘Create the Posts’ section in your Video Blogster feeds will be ignored.

Capture

Possible Issues

  1. Some WordPress themes are hardcoded to not work well with Child Themes. If you have to add the code above the the parent theme’s functions.php file, remember that it will be removed if/when you update the theme.
  2. If you use a plugin like Code Snippets to add the above code, it may not work properly due to load order.

You may also like...