bp_get_member_last_active( array $args = array() )

Return the current member’s last active time.


Parameters Parameters

$args

(array) (Optional) Array of optional arguments.

  • 'active_format'
    (mixed) If true, formatted "active 5 minutes ago". If false, formatted "5 minutes ago". If string, should be sprintf'able like 'last seen %s ago'.
  • 'relative'
    (bool) If true, will return relative time "5 minutes ago". If false, will return date from database. Default: true.

Default value: array()


Top ↑

Return Return

(string)


Source Source

File: bp-members/bp-members-template.php

	function bp_get_member_last_active( $args = array() ) {
		global $members_template;

		// Parse the activity format.
		$r = bp_parse_args( $args, array(
			'active_format' => true,
			'relative'      => true,
		) );

		// Backwards compatibility for anyone forcing a 'true' active_format.
		if ( true === $r['active_format'] ) {
			/* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */
			$r['active_format'] = __( 'Active %s', 'buddypress' );
		}

		// Member has logged in at least one time.
		if ( isset( $members_template->member->last_activity ) ) {
			// We do not want relative time, so return now.
			// @todo Should the 'bp_member_last_active' filter be applied here?
			if ( ! $r['relative'] ) {
				return esc_attr( $members_template->member->last_activity );
			}

			// Backwards compatibility for pre 1.5 'ago' strings.
			$last_activity = ! empty( $r['active_format'] )
				? bp_core_get_last_activity( $members_template->member->last_activity, $r['active_format'] )
				: bp_core_time_since( $members_template->member->last_activity );

		// Member has never logged in or been active.
		} else {
			$last_activity = __( 'Never active', 'buddypress' );
		}

		/**
		 * Filters the current members last active time.
		 *
		 * @since 1.2.0
		 *
		 * @param string $last_activity Formatted time since last activity.
		 * @param array  $r             Array of parsed arguments for query.
		 */
		return apply_filters( 'bp_member_last_active', $last_activity, $r );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
2.7.0 Added 'relative' as a parameter to $args.
1.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.