Have video content populate page from upload sub-directory?

Maybe it’s not necessary to add the files to the library. We can simply scan a given folder and print <video> tags with all the video files that we find.

If password is required, I’d give Subscriber accounts to the users and present the content in the backend. In each User profile, an administrator can select the folders that they’ll have access to.

Here’s a proof of concept supposing that:

  • We upload manually to sub-folders inside wp-content/videos/.

  • A user has access to wp-content/videos/chapter1/ and wp-content/videos/chapter2/.

  • Some solution is found to prevent external access to this folder/files.

<?php 
/* Plugin Name: Video Page for Subscribers */

add_action( 'admin_menu', 'admin_menu_wpse_114998' );

# Custom admin page
function admin_menu_wpse_114998()
{
    add_dashboard_page(
        'Video Library',
        'Video Library',
        'read', // visible to Subscribers
        'video-library',
        'menu_callback_wpse_114998'
    );
}

# Print the admin page
function menu_callback_wpse_114998()
{
    $paths = user_folders_wpse_114998( get_current_user_id() );
    foreach( $paths as $path )
        print_video_folder_wpse_114998( $path );
}

# Get the user's allowed folders
function user_folders_wpse_114998( $user_id )
{
    // $user_folders = do_your_thing_to_get_it();
    $user_folders = array( 'chapter1', 'chapter2' );
    return $user_folders;
}

# Iterate through a directory and print all MP4 videos
function print_video_folder_wpse_114998( $folder )
{
    $path = WP_CONTENT_DIR . '/videos/' . $folder;
    $files = array();
    $directory = new RecursiveDirectoryIterator( $path );
    $objects = new RecursiveIteratorIterator( $directory, RecursiveIteratorIterator::SELF_FIRST );
    foreach( $objects as $name => $fileinfo )
    {
        if ( !$fileinfo->isFile() ) 
            continue;

        if( false === strpos( $name,'.mp4' ) )
            continue;

        $files[] = array(
            'url' => WP_CONTENT_URL . "/videos/$folder/" . $fileinfo->getFilename(),
            'name' => $fileinfo->getFilename()
        );
    }
    foreach( $files as $file )
    {
        ?>  <div style="margin:25px 25%;background-color:#cecece;text-align:center">
            <h2><?php echo $file['name']; ?></h2>
            <video src="https://wordpress.stackexchange.com/questions/114998/<?php echo $file["url']; ?>" controls>
              Your browser does not support the <code>video</code> element.
            </video>
            </div>
        <?php
    }

}

enter image description here