我想在用户注销/登录时这样做(&N);查看其他用户配置文件“仅查看联系人卖家”按钮(&A);当用户登录查看自己的个人资料时,会显示“查看收件箱”&;编辑我的个人资料按钮。这是一个屏幕,显示以管理员身份登录的用户查看属于flamez的配置文件,并看到错误的按钮https://www.dropbox.com/s/lifcq06y54jol7z/Screenshot%20of%20error.png?dl=0
以下是我目前掌握的代码:
<style>
a.view_inbox_btn:link, a.view_inbox_btn:visited{
background: Green;
display: inline-block;
padding: 9px 0px 9px 0px;
color: #fff;
text-align: center;
text-decoration: none;
border: 1px solid #457D2B;
width: 25%;
font-size: 23px;
font-weight: bold;
font-family: \'Alegreya Sans\',Arial, Helvetica, sans-serif;
border-radius: 3px;
margin-left: 5px;
margin-top: 52px;}
a.view_inbox_btn:hover, a.view_inbox_btn:active {
background-color: #4da64d;
}
a.edit_profile_btn:link, a.edit_profile_btn:visited{
background: #ff7f00;
display: inline-block;
padding: 9px 0px 9px 0px;
color: #fff;
text-align: center;
text-decoration: none;
border: 1px solid #ff7f00;
width: 25%;
font-size: 23px;
font-weight: bold;
font-family: \'Alegreya Sans\',Arial, Helvetica, sans-serif;
border-radius: 3px;
margin-left: 11px;
margin-top: 17px;}
a.edit_profile_btn:hover, a.edit_profile_btn:active {
background-color: orange;
}
a.contact_seller_btn:link, a.contact_seller_btn:visited{
background: Green;
display: inline-block;
padding: 9px 0px 9px 0px;
color: #fff;
text-align: center;
text-decoration: none;
border: 1px solid #457D2B;
width: 25%;
font-size: 23px;
font-weight: bold;
font-family: \'Alegreya Sans\',Arial, Helvetica, sans-serif;
border-radius: 3px;
margin-left: 5px;
margin-top: 52px;}
a.contact_seller_btn:hover, a.contact_seller_btn:active {
background-color: #4da64d;
}
</style>
<?php if (is_user_logged_in() ): ?>
<a href="http://enormu.com/marketplace/my-account/private-messages/"class="view_inbox_btn">View Inbox</a>
<a href="http://enormu.com/marketplace/my-account/personal-information/"class="edit_profile_btn">Edit Profile</a>
<?php else: ?>
<a href="http://enormu.com/marketplace/my-account/private-messages/"class="contact_seller_btn">Contact Seller</a>
<?php endif ?>
</ul>
</div>
SO网友:appartisan
如果页面作者是需要比较的用户,则可以使用get\\u the\\u author\\u meta(\'id\')。如果没有,也许可以从url获取尼克,并从其id在数据库中搜索。
$currentUserId = get_current_user_id();
$lastPartOfUrl = \'flamez\'; // Get from the url, as in your screenshot
$table = $wpdb->prefix.\'users\';
$page_owner_id = $wpdb->get_var("select ID from $table where user_login=\'$lastPartOfUrl\'");
//Then compare
if($currentUserId === $page_owner_id){
//We show the edit profile button
}else{
//We show the other button
}
希望这有助于更好地理解。注意清理$lastPartOfUrl变量,因为它会破坏您的代码或将您暴露于
SQL injection.
[编辑]如果您不知道url的最后一部分,可以按如下方式提取:
$currentPage = $_SERVER[\'REQUEST_URI\'];
$parts = explode(\'?\',$currentPage);
$lastPartOfUrl = basename(trim($parts[0],\'/\'));