Wordpress - Protect page by login

2019-08-12 17:33发布

I've a site and I would create a simply "Members only" page. I would add a protection to a page content so only editors and administrators can access.

This page should be visible to all users, but when a guest click on it, the page content is protected by username/password. When user fill these fields, the page automatically redirect to protect content.

Is there a plugin, or method, that I can consider?

3条回答
Lonely孤独者°
2楼-- · 2019-08-12 18:25

Wordpress has builtin "password-protect page" feature. If you are using some kind of a standard theme, all you need is to set a password inside a "publish" box at the page editor page (password field is hidden behind some link).

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-08-12 18:33

There probely is some plugin for this kind of stuff, i mostly build my own themes, and implement it there.

if its just one page you want to protect, you could make a own template file for that page. if the page name is "secrets", you could in the teames folder copy the page.php (or index.php) to page-secrets.php, and add some php code to protect that page.

a relly simple version could be:

<?php
        get_header();
        if($_POST['password'] == 'the password')
        {
                ...
        }
        else
        {
                echo "<h2>This page is password protected</h2>";
                echo "<form action='?' method='post'>";
                echo "<label><span>Password</span>";
                echo "<input type='password' name='password' /></label>";
                echo "<input type='submit' name='Authenticate' />";
                echo "</form>";
        }
        get_footer();
?>

where ... is the copied content from page.php (or index.php) between the get_header(); and get_footer(); rows

查看更多
来,给爷笑一个
4楼-- · 2019-08-12 18:34

I advice you to use the "members" plugin

http://wordpress.org/extend/plugins/members/

it allows to protect page with role. If you protect page with 'subscriber', user must be logged.

查看更多
登录 后发表回答