Join our new community forum for support & discussion
Join NowShow Vendor Online Status
-
AuthorPosts
-
Seegon 1 year, 1 month ago
I trying to work out a way to show the online status of the vendors on my site, however i’m strugling to put it all together. Hopefully there are some bright minds here that can help sort things out. So far I’ve been able to gather this content:
// ON VENDOR PAGE add_filter( 'hivepress/v1/templates/vendor_view_page/blocks', function( $blocks, $template ) { $vendor = $template->get_context('vendor'); $user_id = $vendor->get_user__id(); if($vendor){ $blocks = hivepress()->helper->merge_trees( [ 'blocks' => $blocks ], [ 'blocks' => [ 'vendor_details_primary' => [ 'blocks' => [ 'custom_vendor_email' => [ 'type' => 'content', 'content' => 'the shortcode here', '_order' => 1, ], ], ], ], ] )['blocks']; } return $blocks; }, 1000, 2 ); // ON VENDOR BLOCK add_filter( 'hivepress/v1/templates/vendor_view_block/blocks', function( $blocks, $template ) { $vendor = $template->get_context('vendor'); $user_id = $vendor->get_user__id(); if($vendor){ $blocks = hivepress()->helper->merge_trees( [ 'blocks' => $blocks ], [ 'blocks' => [ 'vendor_details_primary' => [ 'blocks' => [ 'custom_vendor_connection_time' => [ 'type' => 'content', 'content' => 'the shortcode here', '_order' => 1, ], ], ], ], ] )['blocks']; } return $blocks; }, 1000, 2 );
and I’ve found that this will track everytime a user refreshes a page. If there has been no activity for 15 minutes, the user status will be set to Offline.
This one should be added to “function.php”
add_action('wp', 'update_online_users_status'); function update_online_users_status(){ if(is_user_logged_in()){ // get the online users list if(($logged_in_users = get_transient('users_online')) === false) $logged_in_users = array(); $current_user = wp_get_current_user(); $current_user = $current_user->ID; $current_time = current_time('timestamp'); if(!isset($logged_in_users[$current_user]) || ($logged_in_users[$current_user] < ($current_time - (15 * 60)))){ $logged_in_users[$current_user] = $current_time; set_transient('users_online', $logged_in_users, 30 * 60); } } }
This one to author.php
function is_user_online($user_id) { // get the online users list $logged_in_users = get_transient('users_online'); // online, if (s)he is in the list and last activity was less than 15 minutes ago return isset($logged_in_users[$user_id]) && ($logged_in_users[$user_id] > (current_time('timestamp') - (15 * 60))); } $passthis_id = $curauth->ID; if(is_user_online($passthis_id)){ echo 'User is online.';} else { echo'User is not online.';}
Anyone know how to put this all together with Code_Snippet? If we can make it work, I’m sure more people would like this feature.
Regards
Sorry, I can’t help with checking a third-party Online status implementation, but the code that inserts a custom block to the vendor templates seems to be correct, it should add the “shortcode here” text. If there’s some plugin or shortcode you’re using for indicating the online status please try adding the shortcode instead of text.
Seegon 1 year, 1 month agoJust thought anyone could put em together, somehow. The resource I found them on put the code in the function.php and author.php (whatever that is), and I’m wondering if I could make em work with code snippet plugin.
I’ll mess around some, but my idea was that this might be something others want as well. Seeing if a vendor is currently online is very helpfull. And if someone has more experience with coding, we can make it work together. (and seeing as this “vendor online” feature was on your roadmap 1 year and 4 months ago, I thought you would be interessted aswell.. *wink*)
Anyway, I’ll do some testing on my own.
Sorry, the online functionality itself is not related to HivePress features (yet), but I can advice on customizing templates and inserting custom elements if this helps. The rest depends on your requirements, where it’s an online status badge or another embedded content.
-
AuthorPosts
New Reply
This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.