简体   繁体   English

Wordpress:登录用户但无权访问wp-admin

[英]Wordpress: Login for Users Without access to wp-admin

I have a wordpress application and I want the public to be able to view the website only when they are registered and logged-in. 我有一个wordpress应用程序,希望公众只有在注册和登录后才能查看该网站。

Also, I don't want users to have access to wp-admin when they signup. 另外,我不希望用户在注册时可以访问wp-admin。 I used Theme My Login plugin, but all it does is help you get a customized wp-login page, because registered users will get access to wp-admin. 我使用了Theme My Login插件,但是它所做的只是帮助您获得自定义的wp-login页面,因为注册用户将可以访问wp-admin。

PS: I am sorry if this question have been asked before, I could not find it, it is so hard to google "wordpress with custom login" without seeing a page that just customizes the wp-login page. PS:很抱歉,如果以前没有问过这个问题,我找不到它,很难在没有看到仅自定义wp-login页面的页面的情况下使用“具有自定义登录名的wordpress”进行搜索。

I had a WordPress site requirement where only logged in users could see the site and it's contents. 我有一个WordPress网站要求,只有登录的用户才能看到该网站及其内容。 I came across this bit of code a few years ago and found it to be helpful. 几年前,我遇到了这段代码,发现它很有帮助。 Place it into your functions.php and when a visitor comes along who is not logged in, it'll redirect them to the wp-login.php page to login. 将其放入您的functions.php中,当有访客登录并且没有登录时,它将重定向到wp-login.php页面进行登录。 Once logged in, then they can view the site without being blocked. 登录后,他们便可以查看该站点而不会被阻止。

This is an example where it can help keep unwanted visitors away from the content of your site. 这是一个示例,它可以帮助使不需要的访问者远离您的网站内容。

Add the block below to make your website available to logged on authenticated users only. 在下面添加块,使您的网站仅可用于已登录身份验证的用户。 If a user is not authenticated, then they will be redirected to the login page 如果用户未通过身份验证,那么他们将被重定向到登录页面

    <?php

    // Redirect users who arent logged in...
    function members_only() {
        global $pagenow;
        // Check to see if user in not logged in and not on the login page
        if( !is_user_logged_in() && $pagenow != 'wp-login.php' )
              auth_redirect();
    }
    add_action( 'wp', 'members_only' ); 

    ?>

And if you're looking for a custom login page? 如果您正在寻找自定义登录页面? I know there's a plugin that can do that for you such as “Theme My Login”. 我知道有一个插件可以为您完成此任务,例如“主题我的登录名”。 Also, after a user logs in you want them to be redirected back to the site and no dashboard access? 另外,在用户登录后,您希望他们被重定向回站点并且没有仪表板访问权限吗? You could try the plugin “Remove Dashboard Access”. 您可以尝试使用“删除仪表板访问权限”插件。 Hope this helps! 希望这可以帮助!

强制登录 WordPress插件可能是您正在寻找的东西。

In my opinion I would still allow users to access the dashboard so they can use profile section to change their password, email etc. At basic, subscriber level they cannot do much more so you should not be worried. 在我看来,我仍然允许用户访问仪表板,以便他们可以使用配置文件部分来更改其密码,电子邮件等。在基本的订户级别,他们不能做更多的事情,因此您不必担心。

If you still insist on prohibiting them from accessing the dashboard this might come helpful https://premium.wpmudev.org/blog/limit-access-to-your-wordpress-dashboard/ 如果您仍然坚持禁止他们访问仪表板,这可能会有所帮助https://premium.wpmudev.org/blog/limit-access-to-your-wordpress-dashboard/

Here is one scenario which make sense, registered users will have role of subscriber editor or whatever you intended to set. 这是一个有意义的方案,注册用户将具有订户编辑者角色或您打算设置的任何角色。 you need to set restrictions for registered users those will not be able to access wp-admin 您需要为注册用户设置限制,使其无法访问wp-admin

here is the code which can help you to achieve that. 这是可以帮助您实现这一目标的代码。

you need to replace USER_ROLE_NAME_HERE it with role of register user. 您需要将USER_ROLE_NAME_HERE替换为注册用户角色。

function wp_register_user_no_admin_access(){
    $redirect = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : home_url( '/' );
    if ( current_user_can( 'USER_ROLE_NAME_HERE' ) ){
        exit( wp_redirect( $redirect ) );
    }
}
add_action( 'admin_init', 'wp_register_user_no_admin_access', 100 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM