Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Last active October 20, 2020 02:01
Show Gist options
  • Save KaineLabs/45632670260b395efe02e9f55e12ba46 to your computer and use it in GitHub Desktop.
Save KaineLabs/45632670260b395efe02e9f55e12ba46 to your computer and use it in GitHub Desktop.
Add Member Directory Online Tab
<?php
/**
* Add Member Directory Online Tab .
*/
function yzc_add_md_online_tab() {
$online_count= yzc_get_online_users_total();
?>
<style type="text/css">
.yz-tabs-list-gradient #members-online i {
background: #ff2f20;
background: url(<?php echo YZ_PA; ?>images/dotted-bg.png),linear-gradient(to left, #ff2f20 , #ff1162 );
background: url(<?php echo YZ_PA; ?>images/dotted.png),-webkit-linear-gradient(right, #ff2f20 , #ff1162 );
}
.yz-tabs-list-gradient .loading#members-online i {
background: transparent;
}
</style>
<li id="members-online" class="yzmt-directory-tab">
<a href="#"><i class="fas fa-fire"></i><?php printf( __( 'Online Users %1s', 'youzer' ), '<span>' . $online_count . '</span>' ); ?></a>
</li>
<?php
}
add_action( 'bp_members_directory_member_types', 'yzc_add_md_online_tab' );
/**
* Get Online Users Total.
*/
function yzc_get_online_users_total() {
global $bp, $wpdb;
// Init Data
$interval = apply_filters( 'bp_user_query_online_interval', 15 );
$component = buddypress()->members->id;
// Request.
$online_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$bp->members->table_name_last_activity} WHERE component = '$component' AND type = 'last_activity' AND date_recorded >= DATE_SUB( UTC_TIMESTAMP(), INTERVAL $interval MINUTE )" );
return $online_count;
}
/**
* Members Directory - Get Online Members.
*/
function yzc_get_md_online_members_list( $loop ) {
if ( bp_is_members_directory() && isset( $_POST['scope'] ) && $_POST['scope'] == 'online' ) {
$loop['type'] = 'online';
}
return $loop;
}
add_filter( 'bp_after_has_members_parse_args', 'yzc_get_md_online_members_list', 9999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment