背景信息:
我有一个Wordpress插件来显示每个用户配置文件(前端)。登录用户访问其配置文件时。url为/profile/。当用户访问另一个配置文件时,路径是相同的,后面跟着他们的用户名/profile/bob1/(例如)。
使用一些div类,我创建了一个模糊的背景,上面有另一个图像,以阻止某些Wordpress用户查看配置文件信息。
问题:
我想知道如何隐藏这些div类而不是在它们自己的配置文件页面上:/profile/,而是它的所有其他路径/profile/bob1/(例如)以及其他"if"条件,您可以在下面看到:
(正如你所看到的,我只向具有Wordpress"阅读"能力的特定用户显示了一个div类…)
<div class="back"<?php if (current_user_can('read')){ echo 'style="display:none;"'; } ?>></div>
非常感谢你看了这个!非常感谢。
来自作者模板的WordPress文档。
<?php
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
?>
所以应用同样的逻辑。
<?php
$viewother = (isset($_GET['author_name'])) ? true : false;
?>
或者您可以检查用户ID。
<?php
$style = '';
$curauth = get_userdata(intval($author));
$otherauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : false;
if($otherauth && $otherauth->ID != $curauth->ID) {
// user is viewing another profile
$style = ' style="display:none;"';
}
?>
<div class="back"<?php echo $style; } ?>></div>