Skip to:
Content

BuddyPress.org

Ticket #7882: 7882.02.patch

File 7882.02.patch, 4.1 KB (added by r-a-y, 4 years ago)
  • src/bp-core/classes/class-bp-core-user.php

     
    760760
    761761                // Fetch the user's last_activity.
    762762                if ( 'active' != $type ) {
    763                         $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) );
     763                        $user_activity = self::get_last_activity( $user_ids );
    764764                        for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    765765                                foreach ( (array) $user_activity as $activity ) {
    766                                         if ( $activity->id == $paged_users[$i]->id )
    767                                                 $paged_users[$i]->last_activity = $activity->last_activity;
     766                                        if ( ! empty( $activity['user_id'] ) && (int) $activity['user_id'] === (int) $paged_users[$i]->id ) {
     767                                                $paged_users[$i]->last_activity = $activity['date_recorded'];
     768                                        }
    768769                                }
    769770                        }
    770771                }
  • src/bp-members/bp-members-functions.php

     
    126126                'count_total'         => 'count_query' // What kind of total user count to do, if any. 'count_query', 'sql_calc_found_rows', or false.
    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'],
    133147                        $r['per_page'],
     
    10481062 * Update a user's last activity.
    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.
    10531069 * @param string $time    Time of last activity, in 'Y-m-d H:i:s' format.
     
    10701086                $time = bp_core_current_time();
    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 );
    10831108}