Presto Player – Source video admin column

Tech Articles | August 14, 2025 | Uncategorized

I’ve been a presto player user for sometime in fact the wordpress version of this site is actually using presto-player and thanks to some additional CSS / JS uploading they work flawlessly on the static version too.

I like others have a lot of videos on this site and my other sites using presto and sometimes from a wide mix of sources and I may need to know the location of one of these because I want to use it again or because I want to post a link on a site, forum or Facebook group. The easiest way to do this with the native plugin is to inspect the source or check the database SCR reference.

So I began working on snippets I run on a few different sites to make this task easier and following a post on the Sure Crafted Facebook group I decided to publish them in this article.

The first one deals with adding a new column to the media hub and is the one i use the most and have on this site;

Prestoplayer media source media column

The following code snippet adds the column above to your presto media hub.

<?php
/**
 * Presto Player: "Source URL" admin column
 */

// Add the column (before Date if present)
add_filter('manage_pp_video_block_posts_columns', function ($cols) {
    $new = [];
    foreach ($cols as $key => $label) {
        if ($key === 'date') {
            $new['presto_source'] = __('Source URL', 'pp-admin');
        }
        $new[$key] = $label;
    }
    if (!isset($new['presto_source'])) {
        $new['presto_source'] = __('Source URL', 'pp-admin');
    }
    return $new;
});

/**
 * Resolve the source URL for a pp_video_block post.
 */

function ta_presto_source_url_col($post_id) {
    static $cache = [];
    if (isset($cache[$post_id])) return $cache[$post_id];

    global $wpdb;
    $url = '';
    $table = $wpdb->prefix . 'presto_player_videos';

    // Check table exists
    $table_exists = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table));

    if ($table_exists) {
        // Get the newest NON-EMPTY src for this post
        $url = $wpdb->get_var($wpdb->prepare("
            SELECT src
            FROM {$table}
            WHERE post_id = %d
              AND (deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00')
              AND src IS NOT NULL AND src <> ''
            ORDER BY IFNULL(updated_at, created_at) DESC, id DESC
            LIMIT 1
        ", $post_id));
    }

    // Fallback 1: look in postmeta for a plausible video URL
    if (!$url) {
        $meta = get_post_meta($post_id);
        foreach ($meta as $vals) {
            foreach ((array) $vals as $v) {
                if (!is_string($v)) continue;
                if (preg_match('#https?://[^\s"\'<>]+#i', $v, $m)) {
                    $cand = $m[0];
                    if (preg_match('#(youtube\.com|youtu\.be|vimeo\.com|wistia\.com|bunnycdn|cloudfront\.net|s3\.amazonaws\.com|\.m3u8(\?.*)?$|\.mp4(\?.*)?$)#i', $cand)) {
                        $url = $cand;
                        break 2;
                    }
                }
            }
        }
    }

    // Fallback 2: scan post content
    if (!$url) {
        $content = get_post_field('post_content', $post_id);
        if ($content && preg_match_all('#https?://[^\s"\'<>]+#i', $content, $matches)) {
            foreach ($matches[0] as $cand) {
                if (preg_match('#(youtube\.com|youtu\.be|vimeo\.com|wistia\.com|bunnycdn|cloudfront\.net|s3\.amazonaws\.com|\.m3u8(\?.*)?$|\.mp4(\?.*)?$)#i', $cand)) {
                    $url = $cand;
                    break;
                }
            }
        }
    }

    $cache[$post_id] = $url ? esc_url_raw($url) : '';
    return $cache[$post_id];
}

// Render the column
add_action('manage_pp_video_block_posts_custom_column', function ($column, $post_id) {
    if ($column !== 'presto_source') return;

    $src = ta_presto_source_url_col($post_id);

    if ($src) {
        $display = esc_html(preg_replace('#^https?://#', '', $src));
        echo '<a href="' . esc_url($src) . '" target="_blank" rel="noopener noreferrer" title="' . esc_attr($src) . '">' . $display . '</a>';
    } else {
        echo '—';
    }
}, 10, 2);

PHP

The second one adds a small meta box to your media editing and can be useful if your following media rather than visiting the hub, these should both be able to run in the same snippet as long as you only have one opening php tab.

Prestoplayer media source media metabox
<?php
/**
 * Presto Player: Source URL meta box for pp_video_block
 * - Shows detected src (from {$wpdb->prefix}presto_player_videos)
 */

/* === Resolver (cached) === */
if (!function_exists('ta_presto_source_url')) {
    function ta_presto_source_url($post_id) {
        static $cache = [];
        if (isset($cache[$post_id])) return $cache[$post_id];

        global $wpdb;
        $url   = '';
        $table = $wpdb->prefix . 'presto_player_videos';

        // 1) From Presto table (newest non-empty)
        $table_exists = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table));
        if ($table_exists) {
            $url = $wpdb->get_var($wpdb->prepare("
                SELECT src
                FROM {$table}
                WHERE post_id = %d
                  AND (deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00')
                  AND src IS NOT NULL AND src <> ''
                ORDER BY IFNULL(updated_at, created_at) DESC, id DESC
                LIMIT 1
            ", $post_id));
        }

        // 2) Fallbacks: postmeta then content
        if (!$url) {
            $meta = get_post_meta($post_id);
            foreach ($meta as $vals) {
                foreach ((array) $vals as $v) {
                    if (!is_string($v)) continue;
                    if (preg_match('#https?://[^\s"\'<>]+#i', $v, $m)) {
                        $cand = $m[0];
                        if (preg_match('#(youtube\.com|youtu\.be|vimeo\.com|wistia\.com|bunnycdn|cloudfront\.net|s3\.amazonaws\.com|\.m3u8(\?.*)?$|\.mp4(\?.*)?$)#i', $cand)) {
                            $url = $cand; break 2;
                        }
                    }
                }
            }
        }
        if (!$url) {
            $content = get_post_field('post_content', $post_id);
            if ($content && preg_match_all('#https?://[^\s"\'<>]+#i', $content, $m)) {
                foreach ($m[0] as $cand) {
                    if (preg_match('#(youtube\.com|youtu\.be|vimeo\.com|wistia\.com|bunnycdn|cloudfront\.net|s3\.amazonaws\.com|\.m3u8(\?.*)?$|\.mp4(\?.*)?$)#i', $cand)) {
                        $url = $cand; break;
                    }
                }
            }
        }

        return $cache[$post_id] = $url ? esc_url_raw($url) : '';
    }
}

/* === Meta box (always read-only) === */
add_action('add_meta_boxes', function () {
    add_meta_box(
        'ta-presto-src',
        __('Source URL (Presto)', 'pp-admin'),
        function ($post) {
            $detected = ta_presto_source_url($post->ID);

            // No saving needed (read-only display), but keep a nonce in case you add actions later.
            wp_nonce_field('ta_presto_src_box', 'ta_presto_src_nonce');
            ?>
            <p>
                <input
                    type="url"
                    id="ta-presto-source"
                    value="<?php echo esc_attr($detected); ?>"
                    style="width:100%"
                    readonly
                    placeholder="<?php esc_attr_e('No URL detected', 'pp-admin'); ?>"
                >
            </p>
            <p>
                <a
                    class="button button-small"
                    id="ta-presto-open"
                    target="_blank"
                    rel="noopener"
                    href="<?php echo esc_url($detected ?: '#'); ?>"
                    <?php echo $detected ? '' : 'aria-disabled="true" style="pointer-events:none;opacity:.5"'; ?>
                ><?php _e('Open', 'pp-admin'); ?></a>

                <button
                    type="button"
                    class="button button-small"
                    id="ta-presto-copy"
                    <?php echo $detected ? '' : 'disabled'; ?>
                ><?php _e('Copy', 'pp-admin'); ?></button>
            </p>

            <script>
            (function () {
                const input = document.getElementById('ta-presto-source');
                const copy  = document.getElementById('ta-presto-copy');

                if (!input || !copy) return;

                copy.addEventListener('click', async function () {
                    const val = input.value || '';
                    try {
                        if (navigator.clipboard && window.isSecureContext) {
                            await navigator.clipboard.writeText(val);
                        } else {
                            // Fallback for older contexts
                            input.focus();
                            input.select();
                            document.execCommand('copy');
                        }
                        const original = copy.textContent;
                        copy.textContent = <?php echo json_encode(__('Copied!', 'pp-admin')); ?>;
                        copy.disabled = true;
                        setTimeout(() => { copy.textContent = original; copy.disabled = false; }, 1000);
                    } catch (e) {
                        alert(<?php echo json_encode(__('Could not copy to clipboard.', 'pp-admin')); ?>);
                    }
                });
            })();
            </script>
            <?php
        },
        'pp_video_block',
        'side',
        'default'
    );
});
PHP

Now both of these snippets are minor quality of life improvements and my hope is by sharing them they can help a few others like they have helped me

Support the Author

buy me a coffee
Really Useful Plugin Logo
Wpvideobank temp
Appoligies for any spelling and grammer issue. As a dyslexic i need to rely on tools for this they like me are not perfect but I do try my best