bp_get_member_last_active

Return the current member's last active time.

Description

(string) bp_get_member_last_active( (array) $args = array() ); 

Returns (string)

Parameters (1)

0. $args — Optional. (array) => array()
Array of optional arguments.

Options

  • active_format (mixed) => null

    If true, formatted active 5 minutes ago.. If false, formatted 5 minutes ago. If string, should be sprintf'able like last seen %s ago.

array(

    /**
     * If true, formatted "active 5 minutes ago". If false, formatted "5 minutes ago". If string,
     * should be sprintf'able like 'last seen %s ago'.
     *
     * @type mixed
     * @default null
     */
    'active_format' => null
);        


Usage

  1. if ( !function_exists( 'bp_get_member_last_active' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-template.php'; 
  3.  
  4. // Array of optional arguments. 
  5. $args = array( 
  6. 'active_format' => null 
  7. ); 
  8.  
  9. // NOTICE! Understand what this does before running. 
  10. $result = bp_get_member_last_active($args); 
  11.  

Defined (1)

The function is defined in the following location(s).

/bp-members/bp-members-template.php  
  1. function bp_get_member_last_active( $args = array() ) { 
  2. global $members_template; 
  3.  
  4. // Parse the activity format. 
  5. $r = bp_parse_args( $args, array( 
  6. 'active_format' => true,  
  7. 'relative' => true,  
  8. ) ); 
  9.  
  10. // Backwards compatibility for anyone forcing a 'true' active_format. 
  11. if ( true === $r['active_format'] ) { 
  12. $r['active_format'] = __( 'active %s', buddypress ); 
  13.  
  14. // Member has logged in at least one time. 
  15. if ( isset( $members_template->member->last_activity ) ) { 
  16. // We do not want relative time, so return now. 
  17. // @todo Should the 'bp_member_last_active' filter be applied here? 
  18. if ( ! $r['relative'] ) { 
  19. return esc_attr( $members_template->member->last_activity ); 
  20.  
  21. // Backwards compatibility for pre 1.5 'ago' strings. 
  22. $last_activity = ! empty( $r['active_format'] ) 
  23. ? bp_core_get_last_activity( $members_template->member->last_activity, $r['active_format'] ) 
  24. : bp_core_time_since( $members_template->member->last_activity ); 
  25.  
  26. // Member has never logged in or been active. 
  27. } else { 
  28. $last_activity = __( 'Never active', buddypress ); 
  29.  
  30. /** 
  31. * Filters the current members last active time. 
  32. * @since 1.2.0 
  33. * @param string $last_activity Formatted time since last activity. 
  34. * @param array $r Array of parsed arguments for query. 
  35. */ 
  36. return apply_filters( 'bp_member_last_active', $last_activity, $r );