Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/11/2014 03:19:01 PM (11 years ago)
Author:
boonebgorges
Message:

Add 'active_format' parameter to bp_get_member_last_active()

This new param allows theme authors to specify whether they'd like the current
user's last activity string in the format "Active 5 minutes ago" vs the simpler
"5 minutes ago".

Fixes #5387

Props lenasterg

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-members/bp-members-template.php

    r7756 r7846  
    587587    add_filter( 'bp_get_member_name', 'esc_html'       );
    588588
    589 function bp_member_last_active() {
    590     echo bp_get_member_last_active();
    591 }
    592     function bp_get_member_last_active() {
    593         global $members_template;
    594 
    595         if ( isset( $members_template->member->last_activity ) )
    596             $last_activity = bp_core_get_last_activity( $members_template->member->last_activity, __( 'active %s', 'buddypress' ) );
    597         else
     589/**
     590 * Output the current member's last active time.
     591 *
     592 * @param array $args See {@link bp_get_member_last_active()}.
     593 */
     594function bp_member_last_active( $args = array() ) {
     595    echo bp_get_member_last_active( $args );
     596}
     597    /**
     598     * Return the current member's last active time.
     599     *
     600     * @param array $args {
     601     *     Array of optional arguments.
     602     *     @type bool $active_format If true, formatted "Active 5 minutes
     603     *           ago". If false, formatted "5 minutes ago". Default: true.
     604     * }
     605     * @return string
     606     */
     607    function bp_get_member_last_active( $args = array() ) {
     608        global $members_template;
     609
     610        $r = wp_parse_args( $args, array(
     611            'active_format' => true,
     612        ) );
     613
     614        if ( isset( $members_template->member->last_activity ) ) {
     615            if ( ! empty( $r['active_format'] ) ) {
     616                $last_activity = bp_core_get_last_activity( $members_template->member->last_activity, __( 'active %s', 'buddypress' ) );
     617            } else {
     618                $last_activity = bp_core_time_since( $members_template->member->last_activity );
     619            }
     620        } else {
    598621            $last_activity = __( 'Never active', 'buddypress' );
     622        }
    599623
    600624        return apply_filters( 'bp_member_last_active', $last_activity );
Note: See TracChangeset for help on using the changeset viewer.