Php 限制用户访问特定页面-Wordpress

Php 限制用户访问特定页面-Wordpress,php,wordpress,Php,Wordpress,我有一段精彩的代码,限制对wp admin登录页面的访问,除非登录的用户是该站点的管理员: add_action( 'init', 'blockusers_init' ); function blockusers_init() { if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJA

我有一段精彩的代码,限制对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操作创建并加载函数