2013-11-03 138 views
0

我試圖只允許特定成員的用戶和管理員訪問某些內容。 用下面的代碼時,我記錄爲管理員,我不能查看內容:只允許訪問成員的組和管理員

<?php 
    if (is_category(4)) { 
     if (!current_user_can('my-group') || !current_user_can('add_users')) { 
      echo '<h1 class="entry-title">You can not access</h1><p>This content is only for Administrator and group\'s members.</p>'; 
     } 
    } else { 
?> 

而且我個人tryed每一個條件,但作爲管理員,我不能查看內容。


我tryed這個例子代碼:

<?php if (is_category(8)) { 
    if (!current_user_can('mio-gruppo') || !user_can('administrator')) { 
     echo 'you can not pass'; 
     } 
    } else { 
     echo 'you pass'; 
    } 
?> 

但是,這兩個條件語句進去衝突。如果我嘗試兩個單獨作品的權利

+0

如果這是你的整個代碼,你需要關閉你的'else'語句。 – Shane

+0

我閉上了else語句內容 \t \t Gabriele

+0

後我tryed這個例子代碼: 但是這兩個條件聲明有衝突。如果我嘗試兩個分開的作品。 – Gabriele

回答

0

我想這應該是&&而不是||

<?php 
    if (is_category(4)) { 
     if (!current_user_can('my-group') && !current_user_can('add_users')) { 
      echo '<h1 class="entry-title">You can not access</h1><p>This content is only for Administrator and group\'s members.</p>'; 
     } 
    } else { 
?> 

或者讓它倒過來:

<?php 
    if (is_category(4)) { 
     if (current_user_can('my-group') || current_user_can('add_users')) { 
      echo 'access granted'; 
     } else { 
      echo 'no access'; 
     } 
    } 
?> 
0

這正是我需要的:

<?php 
if (is_category(8) && (current_user_can(array(1,2,3,4,5,6,7)) || !is_user_logged_in())) { 
if (!current_user_can('mio-gruppo')) { 
echo 'you can not pass'; 
} 
} else { 
echo ' you can pass'; 
} 
?> 
相關問題