Display around the user's avatar of the green border when it's online?

Good day ! The question is this: I'm developing a small social network using Wordpress and BuddyPress and there is a problem I would like to display the user status is green online/offline is red in the form of a border around avatars user I approximately don't even predstava how to implement it! How to pass, who has worked with these two components of the prompt!

Here the validation function
/**
 * Output the "active [x days ago]" string for a user.
*
 * @see bp_get_last_activity() for a description of parameters.
*
 * @param int $user_id See {@link bp_get_last_activity()}.
*/
function bp_last_activity( $user_id = 0 ) {

/**
 * Filters the 'active [x days ago]' string for a user.
*
 * @since 1.0.0
*
 * @param string $value Formatted 'active [x days ago]' string.
*/
 echo apply_filters( 'bp_last_activity', bp_get_last_activity( $user_id ) );
}
/**
 * Get the "active [x days ago]" string for a user.
*
 * @param int $user_id ID of the user. Default: displayed user ID.
 * @return string
*/
 function bp_get_last_activity( $user_id = 0 ) {
 if ( empty( $user_id ) )
 $user_id = bp_displayed_user_id();

 $last_activity = bp_core_get_last_activity( bp_get_user_last_activity( $user_id ), __('active %s', 'online') );
/**
 * Filters the 'active [x days ago]' string for a user.
*
 * @since 1.5.0
*
 * @param string $value Formatted 'active [x days ago]' string.
*/
 return apply_filters( 'bp_get_last_activity', $last_activity);
 }


Here is the output

<span class="activity"><?php bp_last_activity( bp_displayed_user_id() ); ?></span>


I would be very grateful!

13862076394946cd8244abc517d04d7f.png
July 9th 19 at 10:14
2 answers
July 9th 19 at 10:16
Solution
Already decided this issue by writing a simple function and style to the page! Everything works fine!

Here someone can be useful solution:
For example avatar has id = "item-header-avatar", then it is possible for example so:

<?php
/**
* We define an online user or not
*/
check_is_user_online function($user_id) {
 if (bp_has_members("type=online&include=" . $user_id))
 return true;
else
 return false;
}
/**
*Add a style if the viewing user is online
*/
onwp_header_avatar function() {
 $is_online = check_is_user_online(bp_displayed_user_id());
 if (!empty($is_online)) {
 echo '<style-->
 #item-header-avatar {
 border: 2px solid green;
}
';
}
}
add_action('wp_footer', 'onwp_header_avatar');

?>

code to add in functions.php
Very useful! - Neal12 commented on July 9th 19 at 10:19
July 9th 19 at 10:18
in css:
.activity {
border: 2px solid green; // set the desired width (2px), type (solid, dotted, dashed etc) and colour (green)
}
It's a simple CSS! I mean the output if the user is online it is green - if the user is offline is burning red! - Neal12 commented on July 9th 19 at 10:21
: well, change class and just CSS.
Or call a programmer. - johnpaul.Hamm commented on July 9th 19 at 10:24
well insert in the item class activity and inactivity and all and style them - Jeff28 commented on July 9th 19 at 10:27
: There appear strings all values that is "online Now" or "was online stellato seconds ago" and how to replace this code in style! - Angelica.Bradtke commented on July 9th 19 at 10:30
sorry for the dumb question, but how are you going to develop some sort of social network if you cannot enter class to the element by condition? well, stick a Php variable which will write the class if the user is active and nothing will write if the user is not active. - johnpaul.Hamm commented on July 9th 19 at 10:33

Find more questions by tags WordPress