• Resolved perties

    (@perties)


    Is there a shortocode which would help me to display number of users currently online on the top admin bar? Or could you add this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Rogier Lankhorst

    (@rogierlankhorst)

    @perties this is currently not possible in the plugin, but we will add it to our feature requests. Thanks for your suggestion.

    I was curious about this too, so I created this code. You can add this to the theme functions.php (if you or your developer knows what to do) or in your own plugin, but that requires a developer to make ??

    Note: This is experimental code that won’t be updated, so use at your own risk.

    It looks like this (not perfect but it works on every page):

    add_action('admin_bar_menu', function ($wp_admin_bar) {
        global $wpdb;
    
        if (!class_exists("burst_statistics")) {
            return;
        }
    
        $icon = '<img src="https://burst-statistics.com/wp-content/uploads/2021/02/cropped-burst-favicon-32x32.png" style="width: 16px; height: 16px; vertical-align: middle; margin: -2px 4px 0 0;" />';
        $stats = array();
    
        // Live stats
        $table_name = $wpdb->prefix . 'burst_statistics';
        $time_start = strtotime('10 minutes ago');
        $time_now = time();
        $on_page_offset = apply_filters("burst_on_page_offset", 60);
        $live_value = $wpdb->get_var("SELECT count(*) FROM (SELECT DISTINCT(uid) AS uid FROM $table_name WHERE time > $time_start AND ( (time + time_on_page / 1000  + $on_page_offset) > $time_now)) AS active_visitors");
        $stats[] = sprintf('Live: %d', (int) $live_value ?: 0);
    
        // Page stats
        if ($post = get_post()) {
            $burst_total_pageviews_count = get_post_meta($post->ID, 'burst_total_pageviews_count', true);
            $stats[] = sprintf('Pageviews: %d', (int) $burst_total_pageviews_count ?: 0);
        }
    
        $wp_admin_bar->add_node(array(
            'id'    => 'admin-bar-burst',
            'title' => sprintf('%s %s', $icon, implode(' | ', $stats)),
            'href'  => (function_exists('burst_admin_url') ? burst_admin_url() : admin_url()) . '?page=burst#dashboard',
        ));
    }, 999);
    Thread Starter perties

    (@perties)

    Nice. It works fine. I wish you could add tis to your plugin. Additionally it would be nice if it refreshes by itself. Thank you.

    BTW: I do not see Page views.

    • This reply was modified 1 year, 10 months ago by perties.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Shortcode for users online’ is closed to new replies.