Wordpress - Protect page by login

柔情痞子 提交于 2020-01-25 05:05:55

问题


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?


回答1:


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




回答2:


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:


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.



来源:https://stackoverflow.com/questions/6993482/wordpress-protect-page-by-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!