[英]Restricting user access to a particular page - Wordpress
我有這段精彩的代碼限制訪問wp-admin登錄頁面,除非用戶登錄是該站點的管理員:
add_action( 'init', 'blockusers_init' );
function blockusers_init() {
if ( is_admin() && ! current_user_can( 'administrator' ) &&
! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}
我想添加另一個限制訪問的功能,並執行相同的重定向到我的主頁但是我的網站的特定頁面。 但這不起作用:
add_action( 'init', 'blockusers_init' );
function blockusers_init() {
if ( is_admin() && ! current_user_can( 'administrator' ) &&
! ( defined( 'mysite.co.uk/shop' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}
而且我並不為此感到懊惱,但我希望有人必須糾正代碼才能執行此功能?
謝謝
您可以將其添加到header.php文件中,以檢查它們是否在頁面上,以及它們是否為管理員
if(is_page(PAGE_ID)){
current_user_can( 'manage_options' ){
---do redirect here or whatever else---
}
}
您也可以通過init操作創建加載函數,就像您一樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.