我认为这里的问题是,在违反这条规则的过程中,你制造了混乱和问题:
每个语句执行一件事,每行执行一条语句
再加上另一个问题:
将数组传递给存储为序列化PHP的API(安全问题)
还有一个:
始终检查您的假设
它忽略存储在“the\\u users”用户元中的用户,只打印当前用户。
最后一个是这里的杀手。从不检查上的错误值get_user_meta, 导致错误。用户不会从the_users meta,必须添加它。
在脑海中反复运行此代码,例如:
$the_following_users = \'\'; //get_user_meta($the_follower, "the_following_users", true);
if(!in_array($user_follow_to, $the_following_users) && is_array($the_following_users)){
    $the_following_users[] = $user_follow_to;
 这里没有检查
$the_following_users, 它可能根本不是数组,而是
false 或空字符串。
因此,让我们修复保存:
$the_following_users = get_user_meta($the_follower, "the_following_users", true);
if ( empty( $the_following_users ) ) {
    $the_following_user = array();
}
 然后让我们简化下一部分:
$the_following_users[] = $user_follow_to;
 并修复保存,使其不存在安全风险:
$following = implode( \',\', $the_following_users );
update_user_meta($the_follower, "the_following_users", $following );
 最后,让我们转到前端:
首先,我们假设get_user_meta 有效,但永远不要检查这是否正确:
$args = array (
    \'order\'      => \'DESC\',
    \'include\'  => get_user_meta($author->ID, \'the_following_users\', true)
);
 如果用户以前从未跟踪过任何人怎么办?如果他们放过所有人怎么办?那会破坏一切!因此,让我们修复它并将其切换到逗号分隔的列表格式:
$include = get_user_meta($author->ID, \'the_following_users\', true);
if ( empty( $include ) ) {
    // the user follows nobody, or has not followed anybody yet!
} else {
    // turn the string into an array
    $include = explode( \',\', $include );
    $args = array (
        \'order\'      => \'DESC\',
        \'include\'  => $include
    );
    // etc...
}
 最后一个注释是这样的:
foreach ( $users as $user ) {
    // Get users
}
 但您从未在循环中共享代码,这可能是您遇到问题的原因。例如
the_author 总是指当前帖子的作者。如果要显示有关
$user, 您需要传递其ID,或使用公共属性,例如。
foreach ( $users as $user ) {
    // Get users
    echo esc_html( $user->first_name . \' \' . $user->last_name );
}