Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/15/2020 06:33:17 PM (4 years ago)
Author:
imath
Message:

Members: stop mirroring user last_activity data to user metadata

The primary storage location for user last_activity is the activity table. For backward compatibility reasons, we used to mirror that data into user metadata.

Backward compatibility user last_activity metadata mirroring is now only done if the legacy user query is enabled. This can be achieved by forcing the bp_use_legacy_user_query filter to return true.

Props boonebgorges, r-a-y

Fixes #7882

File:
1 edited

Legend:

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

    r12729 r12754  
    127127    ), 'core_get_users' );
    128128
    129     // For legacy users. Use of BP_Core_User::get_users() is deprecated.
    130     if ( apply_filters( 'bp_use_legacy_user_query', false, __FUNCTION__, $r ) ) {
     129    /**
     130     * For legacy users. Use of BP_Core_User::get_users() is deprecated.
     131     *
     132     * Forcing this filter to true will use the legacy user query. As of
     133     * BuddyPress 7.0.0, mirroring of the 'last_activity' value to usermeta
     134     * is also disabled if true. See bp_update_user_last_activity().
     135     *
     136     * @since 2.0.0
     137     *
     138     * @param bool   $retval   Defaults to false.
     139     * @param string $function Current function name.
     140     * @param array  $r        User query arguments.
     141     */
     142    $use_legacy_query = apply_filters( 'bp_use_legacy_user_query', false, __FUNCTION__, $r );
     143
     144    if ( $use_legacy_query ) {
    131145        $retval = BP_Core_User::get_users(
    132146            $r['type'],
     
    10491063 *
    10501064 * @since 1.9.0
     1065 * @since 7.0.0 Backward compatibility usermeta mirroring is only allowed if the
     1066 *              legacy user query is enabled.
    10511067 *
    10521068 * @param int    $user_id ID of the user being updated.
     
    10711087    }
    10721088
    1073     // As of BuddyPress 2.0, last_activity is no longer stored in usermeta.
    1074     // However, we mirror it there for backward compatibility. Do not use!
    1075     // Remove our warning and re-add.
    1076     remove_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10 );
    1077     remove_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10 );
    1078     bp_update_user_meta( $user_id, 'last_activity', $time );
    1079     add_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10, 4 );
    1080     add_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10, 4 );
     1089    /** This filter is documented in bp_core_get_users() */
     1090    $use_legacy_query = apply_filters( 'bp_use_legacy_user_query', false, __FUNCTION__, [ 'user_id' => $user_id ] );
     1091
     1092    /*
     1093     * As of BuddyPress 2.0, last_activity is no longer stored in usermeta.
     1094     * However, we mirror it there for backward compatibility. Do not use!
     1095     *
     1096     * As of BuddyPress 7.0, mirroring is only allowed if the legacy user
     1097     * query is enabled.
     1098     */
     1099    if ( $use_legacy_query ) {
     1100        remove_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10 );
     1101        remove_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10 );
     1102        bp_update_user_meta( $user_id, 'last_activity', $time );
     1103        add_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10, 4 );
     1104        add_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10, 4 );
     1105    }
    10811106
    10821107    return BP_Core_User::update_last_activity( $user_id, $time );
Note: See TracChangeset for help on using the changeset viewer.