本文整理汇总了PHP中BP_Groups_Member::refresh_total_group_count_for_user方法的典型用法代码示例。如果您正苦于以下问题:PHP BP_Groups_Member::refresh_total_group_count_for_user方法的具体用法?PHP BP_Groups_Member::refresh_total_group_count_for_user怎么用?PHP BP_Groups_Member::refresh_total_group_count_for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BP_Groups_Member
的用法示例。
在下文中一共展示了BP_Groups_Member::refresh_total_group_count_for_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bp_admin_repair_group_count
/**
* Recalculate group counts for each user.
*
* @since BuddyPress (2.0.0)
*
* @return array
*/
function bp_admin_repair_group_count()
{
global $wpdb;
if (!bp_is_active('groups')) {
return;
}
$statement = __('Counting the number of groups for each user… %s', 'buddypress');
$result = __('Failed!', 'buddypress');
$sql_delete = "DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ( 'total_group_count' );";
if (is_wp_error($wpdb->query($sql_delete))) {
return array(1, sprintf($statement, $result));
}
$bp = buddypress();
// Walk through all users on the site
$total_users = $wpdb->get_row("SELECT count(ID) as c FROM {$wpdb->users}")->c;
if ($total_users > 0) {
$per_query = 500;
$offset = 0;
while ($offset < $total_users) {
// But only bother to update counts for users that have groups
$users = $wpdb->get_col($wpdb->prepare("SELECT user_id FROM {$bp->groups->table_name_members} WHERE is_confirmed = 1 AND is_banned = 0 AND user_id > %d AND user_id <= %d", $offset, $offset + $per_query));
foreach ($users as $user) {
BP_Groups_Member::refresh_total_group_count_for_user($user);
}
$offset += $per_query;
}
} else {
return array(2, sprintf($statement, $result));
}
return array(0, sprintf($statement, __('Complete!', 'buddypress')));
}