A friend helped me put it together, so I can’t take credit for it, but here it is. Hasn’t really been tested very adequately, just in my unique instance.
//Generate New Page from Video
function copy_videos_to_pages( $post_id ) {
// Only if we're saving a flowplayer5 video
if ( 'flowplayer5' !== get_post_type( $post_id ) )
return;
// Get $post object for video currently being saved
$video = get_post( $post_id );
$page_title = get_page_by_title( $video->post_title, '', 'page' );
//Prevent Infinite Loop - https://codex.www.ads-software.com/Plugin_API/Action_Reference/save_post#Avoiding_infinite_loops
remove_action( 'save_post', 'copy_videos_to_pages' );
/**
* Check to see if a Page with the same title as this Video exists.
* If not, create a new Page
* Not totally foolproof, but a simple check.
*/
if ( is_null( $page_title ) ) {
//Create new Page that includes content from Video
$my_post = array(
'post_title' => $video->post_title,
'post_date' => $video->post_date,
'post_content' => '[flowplayer id="' . $video->ID . '"]',
'post_type' => 'page',
'post_status' => 'publish',
);
$post_id = wp_insert_post($my_post);
add_post_meta($post_id, 'related_video', $video->ID, true);
} else {
//do nothing
}
add_action( 'save_post', 'copy_videos_to_pages', 10, 1 );
}
add_action( 'save_post', 'copy_videos_to_pages', 10, 1 );