bp_admin_repair_friend_count ()

重新计算每个用户的好友数。

描述

返回

(数组)

文件:bp-core / admin / bp-core-admin-tools.php

函数bp_admin_repair_friend_count(){全局$wpdb;如果(!Bp_is_active ('friends')) {return;} $statement = __('计算每个用户的连接数…% s”、“buddyboss”);$result = __('失败!”、“buddyboss”);$sql_delete = "DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ('total_friend_count');";If (is_wp_error($wpdb->query($sql_delete)) {return array(1, sprintf($statement, $result));} $bp = buddypress();//浏览网站上的所有用户。 $total_users = $wpdb->get_row( "SELECT count(ID) as c FROM {$wpdb->users}" )->c; $updated = array(); if ( $total_users > 0 ) { $per_query = 500; $offset = 0; while ( $offset < $total_users ) { // Only bother updating counts for users who actually have friendships. $friendships = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id FROM {$bp->friends->table_name} WHERE is_confirmed = 1 AND ( ( initiator_user_id > %d AND initiator_user_id <= %d ) OR ( friend_user_id > %d AND friend_user_id <= %d ) )", $offset, $offset + $per_query, $offset, $offset + $per_query ) ); // The previous query will turn up duplicates, so we // filter them here. foreach ( $friendships as $friendship ) { if ( ! isset( $updated[ $friendship->initiator_user_id ] ) ) { BP_Friends_Friendship::total_friend_count( $friendship->initiator_user_id ); $updated[ $friendship->initiator_user_id ] = 1; } if ( ! isset( $updated[ $friendship->friend_user_id ] ) ) { BP_Friends_Friendship::total_friend_count( $friendship->friend_user_id ); $updated[ $friendship->friend_user_id ] = 1; } } $offset += $per_query; } } else { return array( 2, sprintf( $statement, $result ) ); } return array( 0, sprintf( $statement, __( 'Complete!', 'buddyboss' ) ) ); }

更新日志

更新日志
版本 描述
BuddyPress 2.0.0 介绍了。

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队