我对此感到困惑,如果我们的一位用户删除了他们的帐户,如何更新此功能? 它应该自我更新,我不知道该怎么做才能自动更新。 请帮忙。
/**
* Retrieve following count
*
* Gets the total number of users that the specified user is following
*
* @access private
* @since 1.0
* @param int $user_id - the ID of the user to retrieve a count for
* @return int
*/
function pwuf_get_following_count( $user_id = 0 ) {
if ( empty( $user_id ) ) {
$user_id = get_current_user_id();
}
$following = pwuf_get_following( $user_id );
$count = 0;
if ( $following ) {
$count = count( $following );
}
return (int) apply_filters( 'pwuf_get_following_count', $count, $user_id );
}
这是获取以下用户的功能
/**
* Retrieves all users that the specified user follows
*
* Gets all users that $user_id followers
*
* @access private
* @since 1.0
* @param int $user_id - the ID of the user to retrieve following for
* @return array
*/
function pwuf_get_following( $user_id = 0 ) {
if ( empty( $user_id ) ) {
$user_id = get_current_user_id();
}
$following = get_user_meta( $user_id, '_pwuf_following', true );
if ( empty( $following ) ) {
return;
}
return (array) apply_filters( 'pwuf_get_following', $following, $user_id );
}
这是用于增加或减少用户数的
/**
* Increase follower count
*
* Increments the total count for how many users a specified user is followed by
*
* @access private
* @since 1.0
* @param int $user_id - the ID of the user to increease the count for
* @return int
*/
function pwuf_increase_followed_by_count( $user_id = 0 ) {
do_action( 'pwuf_pre_increase_followed_count', $user_id );
$followed_count = pwuf_get_follower_count( $user_id );
if ( $followed_count !== false ) {
$new_followed_count = update_user_meta( $user_id, '_pwuf_followed_by_count', $followed_count + 1 );
} else {
$new_followed_count = update_user_meta( $user_id, '_pwuf_followed_by_count', 1 );
}
do_action( 'pwuf_post_increase_followed_count', $user_id );
return $new_followed_count;
}
/**
* Decrease follower count
*
* Decrements the total count for how many users a specified user is followed by
*
* @access private
* @since 1.0
* @param int $user_id - the ID of the user to decrease the count for
* @return int
*/
function pwuf_decrease_followed_by_count( $user_id ) {
do_action( 'pwuf_pre_decrease_followed_count', $user_id );
$followed_count = pwuf_get_follower_count( $user_id );
if ( $followed_count ) {
$count = update_user_meta( $user_id, '_pwuf_followed_by_count', ( $followed_count - 1 ) );
do_action( 'pwuf_post_increase_followed_count', $user_id );
}
return $count;
}
现在我不知道为什么当某些用户删除其帐户时,计数没有改变。
答案 0 :(得分:0)
在尝试进行此操作之前,请先备份数据库,或者先在临时站点中使用它,然后再进行实时实施。将此添加到主题的“ functions.php”中。
function follow_delete_user( $user_id ) {
$userslist = get_users();
foreach ( $userslist as $user ) {
pwuf_unfollow_user( $user->ID, $user_id );
pwuf_unfollow_user( $user_id, $user->ID );
}
}
add_action( 'delete_user', 'follow_delete_user' );