[英]WordPress : Password Protected Page
I need help with regards to WordPress Password Protect page/s. 我需要有关WordPress密码保护页面的帮助。
After inputting a password, you are usually redirected to the same page where you entered or just showing you the content after inputting password. 输入密码后,通常会将您重定向到您输入的页面,或者仅在输入密码后显示内容。
What I want is that, after I input the correct password, it redirects to another page of my site. 我想要的是,输入正确的密码后,它会重定向到我网站的另一页。 How is that possible?
那怎么可能? As much as possible, I won't be using any plugins.
我将尽可能不使用任何插件。
Below is my code for functions.php
: 以下是我的
functions.php
代码:
<?php
function my_password_form() {
global $post;
$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
$output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
<p><strong>'.__("Cakes").'</strong></p>
<p>' . __("This page is password-protected. Please input password below.") . '</p>
<center><label for="' . $label . '">' . __("Password:") . '<input name="post_password" id="' . $label . '" type="password" size="40" style="height:20px;"/></label><input type="image" src="images/btn_member02.png" name="Submit" value="' . esc_attr__("Submit") . '"/></center>
</form>
';
return $output;
}
add_filter('the_password_form', 'my_password_form');
?>
As an example, when I input the correct password on page www.mysite.com/memberlogin
, I should be redirected to www.mysite.com/memberpage
. 例如,当我在
www.mysite.com/memberlogin
页面上输入正确的密码时,应将我重定向到www.mysite.com/memberpage
。
I have write the following code for your problem. 我已经为您的问题编写了以下代码。 Please check the following code which may useful for you ( Write this code in your functions.php ):-
请检查以下对您可能有用的代码(将此代码写在您的functions.php中):-
<?php
add_action( 'login_form_postpass', 'redirectPasswordProtectedPage' );
function redirectPasswordProtectedPage()
{
if ( ! empty( $_POST['post_password'] ) ) {
/** @var wpdb $wpdb */
global $wpdb;
$query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_password = %s", trim($_POST['post_password']) );
$password_posts = $wpdb->get_row( $query );
if ( isset( $password_posts ) ) {
$post_id = $password_posts->ID;
wp_safe_redirect(get_permalink(25));
exit;
}
}
}
?>
I found a thread and forgot to copy the link but here is the code: 我找到了一个线程,忘了复制链接,但这是代码:
<?php
echo "<script type='text/javascript'>\nwindow.location = 'http://www.google.com'</script>";
?>
I placed that code in my password protected page. 我将该代码放在了受密码保护的页面中。 After inputting the password, it redirects me to another page - which what I wanted it to do.
输入密码后,它会将我重定向到另一个页面,即我想要的页面。
Your form action should be wp-login.php?action=postpass
, not wp-pass.php
您的表单操作应该是
wp-login.php?action=postpass
,而不是wp-pass.php
Source: Using Password Protection 来源: 使用密码保护
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.