Skip to:
Content

BuddyPress.org

Changeset 9123


Ignore:
Timestamp:
11/04/2014 08:17:51 PM (6 years ago)
Author:
johnjamesjacoby
Message:

Use bp_update_user_meta() in bp_update_user_last_activity() to ensure bp_get_user_meta_key filter is ran.

Fixes bug causing last_activity meta to not be prefixed, and includes testcase.

Fixes #5988.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r9109 r9123  
    974974    remove_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10, 4 );
    975975    remove_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10, 3 );
    976     update_user_meta( $user_id, 'last_activity', $time );
     976    bp_update_user_meta( $user_id, 'last_activity', $time );
    977977    add_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10, 4 );
    978978    add_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10, 3 );
  • trunk/tests/phpunit/testcases/members/functions.php

    r8958 r9123  
    412412        $this->assertSame( NULL, bp_core_get_userid_from_nicename( 'non_existent_user' ) );
    413413    }
     414
     415    /**
     416     * @group bp_update_user_last_activity
     417     */
     418    public function test_bp_last_activity_multi_network() {
     419
     420        // Filter the usermeta key
     421        add_filter( 'bp_get_user_meta_key', array( $this, 'filter_usermeta_key' ) );
     422
     423        // We explicitly do not want last_activity created, so use the
     424        // WP factory methods
     425        $user = $this->factory->user->create();
     426        $time = date( 'Y-m-d H:i:s', time() - 50 );
     427
     428        // Update last user activity
     429        bp_update_user_last_activity( $user, $time );
     430
     431        // Setup parameters to assert to be the same
     432        $expected = $time;
     433        $found    = bp_get_user_meta( $user, 'last_activity', true );
     434
     435        $this->assertSame( $expected, $found );
     436    }
     437
     438    /**
     439     * @group bp_update_user_last_activity
     440     * @global object $wpdb
     441     * @param  string $key
     442     * @return string
     443     */
     444    public function filter_usermeta_key( $key ) {
     445        global $wpdb;
     446        return $wpdb->prefix . $key;
     447    }
    414448}
Note: See TracChangeset for help on using the changeset viewer.