我自己解决了这个问题,这很容易,我很惊讶没有其他人提供答案。话虽如此,解决方案是添加几行代码,检查您正在查看的配置文件的作者ID,并将其与当前登录用户的ID进行比较。
此代码位于members/single/profile的顶部。php
<?php
// Global $bp variable holds all of our info
global $bp;
// The user ID of the currently logged in user
$current_user_id = (int) trim($bp->loggedin_user->id);
// The author that we are currently viewing
$author_id = (int) trim($bp->displayed_user->id);
if ($current_user_id !== $author_id)
{
// redirect to home page url
wp_redirect(home_url());
exit();
}
?>