Skip to:
Content
Pages
Categories
Search
Top
Bottom

Recentally Active

Viewing 11 replies - 1 through 11 (of 11 total)
  • Avatar of Andy Peatling
    Andy Peatling
    Keymaster

    @apeatling

    function get_recently_active_users( $limit = null, $page = 1 ) {
    global $wpdb;

    if ( $limit && $page )
    $pag_sql = $wpdb->prepare( \" LIMIT %d, %d\", intval( ( $page - 1 ) * $limit), intval( $limit ) );

    $paged_users = $wpdb->get_results( $wpdb->prepare(
    \"SELECT DISTINCT um.user_id FROM \" . $wpdb->base_prefix . \"usermeta um
    LEFT JOIN \" . $wpdb->base_prefix . \"users u
    ON u.ID = um.user_id
    WHERE um.meta_key = \'last_activity\'
    AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0
    AND DATE_ADD( FROM_UNIXTIME(um.meta_value), INTERVAL 10 HOUR ) >= NOW()
    ORDER BY FROM_UNIXTIME(um.meta_value) DESC{$pag_sql}\" ) );

    return $paged_users;
    }

    Avatar of Andy Peatling
    Andy Peatling
    Keymaster

    @apeatling

    Put that in /mu-plugins/bp-custom.php and you can make use of it.

    Avatar of Andy Peatling
    Andy Peatling
    Keymaster

    @apeatling

    If you’re using the trunk it’s much easier – take a look at the member theme and the file:

    /directories/members/members-loop.php

    That has the template loop you need to render recently active members.

    Avatar of Bbrian017
    bbrian017
    Participant

    @bbrian017

    Andy I can’t find this file?

    /mu-plugins/bp-custom.php and you can make use of it.

    Avatar of John James Jacoby
    John James Jacoby
    Keymaster

    @johnjamesjacoby

    You need to create that file yourself. bp-custom.php is a file that BuddyPress looks for, kind of as a helper file to allow anyone to modify BP without needing to hack the core files.

    The function that Andy wrote for you will give you the information you need to create a plugin or widget for yourself. He’s teaching you to fish, basically… :)

    Avatar of Bbrian017
    bbrian017
    Participant

    @bbrian017

    ok when I create that file and upload it to /mu-plugins/ I get that exact code displaying in my header

    function get_recently_active_users( $limit = null, $page = 1 ) { global $wpdb; if ( $limit && $page ) $pag_sql = $wpdb->prepare( ” LIMIT %d, %d”, intval( ( $page – 1 ) * $limit), intval( $limit ) ); $paged_users = $wpdb->get_results( $wpdb->prepare( “SELECT DISTINCT um.user_id FROM ” . $wpdb->base_prefix . “usermeta um LEFT JOIN ” . $wpdb->base_prefix . “users u ON u.ID = um.user_id WHERE um.meta_key = ‘last_activity’ AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND DATE_ADD( FROM_UNIXTIME(um.meta_value), INTERVAL 10 HOUR ) >= NOW() ORDER BY FROM_UNIXTIME(um.meta_value) DESC{$pag_sql}” ) ); return $paged_users; }

    The PHP code is differentiated from HTML code by use of the

    <?php .....contents of file here..... ?>

    opening and closing tags. These tell the server that when it finds a PHP file, to scan through for these tags, and execute the code in between them.

    Avatar of Jeff Sayre
    Jeff Sayre
    Participant

    @jeffsayre

    You need to wrap the code Andy provided in php tags. At the very top of the file, type:

    <?php

    Then at the bottom, type:

    ?>

    Make sure there are no spaces after that last angled bracket. Save the file with the php extension and you\’re good to go.

    If this is not clear, open up any BuddyPress file and look at the php tags.

    Avatar of Jeff Sayre
    Jeff Sayre
    Participant

    @jeffsayre

    Dang! DJPaul beat me to it.

    Avatar of Bbrian017
    bbrian017
    Participant

    @bbrian017

    When I upload this,

    <?php

    function get_recently_active_users( $limit = null, $page = 1 ) {

    global $wpdb;

    if ( $limit && $page )

    $pag_sql = $wpdb->prepare( ” LIMIT %d, %d”, intval( ( $page – 1 ) * $limit), intval( $limit ) );

    $paged_users = $wpdb->get_results( $wpdb->prepare(

    “SELECT DISTINCT um.user_id FROM ” . $wpdb->base_prefix . “usermeta um

    LEFT JOIN ” . $wpdb->base_prefix . “users u

    ON u.ID = um.user_id

    WHERE um.meta_key = ‘last_activity’

    AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0

    AND DATE_ADD( FROM_UNIXTIME(um.meta_value), INTERVAL 10 HOUR ) >= NOW()

    ORDER BY FROM_UNIXTIME(um.meta_value) DESC{$pag_sql}” ) );

    return $paged_users;

    }

    ?>

    I’m getting a blank white screen

    Avatar of Jeff Sayre
    Jeff Sayre
    Participant

    @jeffsayre

    Okay, a couple of questions:

    1. Which version of BuddyPress are you using?

    2. What did you name the file?

    3. Where did you place it?

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Recentally Active’ is closed to new replies.