WordPress - 如果用户删除了他们的帐户,则更新功能



我被困住了,如果我们的某个用户删除了他们的帐户,我该如何更新此功能? 它应该自己更新,我不知道我能做些什么来自动更新。 请帮忙。

/**
* 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;
}

现在我不知道为什么当某些用户删除其帐户时计数没有更改。

在尝试此操作之前备份数据库,或者在实时实施之前尝试在暂存站点中使用。将其添加到主题的"功能.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' );

最新更新