简体   繁体   English

Wordpress:如何在没有权限的情况下尝试访问网站时重定向

[英]Wordpress: How to redirect when trying to access a site without permissions

I'm building a community-website with wordpress 4.8 and bbPress Version 2.5.12 installed. 我正在建立一个安装了wordpress 4.8和bbPress版本2.5.12的社区网站。 I also installed a plugin called Paid Memberships Pro (and an extension that's made for bbPress) that handles the permissions in my forum. 我还安装了一个名为Paid Memberships Pro的插件(以及为bbPress制作的扩展程序),用于处理论坛中的权限。

What I would like to add is a redirect to a page on my site which is happening in the moment somebody without the permissions clicks on the member-area. 我要添加的是重定向到我网站上的页面的操作,此操作是在没有权限的人单击成员区域时发生的。 The page that will open will speak about the benefits of joining. 将打开的页面将介绍加入的好处。

Wordpress itself and the member plugin both only allow me to insert a text that is displayed in case somebody without the permissions try to enter the member-area. WordPress本身和成员插件都只允许我插入显示的文本,以防万一没有权限的人尝试进入成员区域。 This text is small and doesn't contain enough information and I rather prefer to redirect to another page. 这段文字很小,没有足够的信息,我宁愿重定向到另一个页面。

I have two problems with this. 我有两个问题。

First I am not sure if I rather change this in the wordpress settings or the plugin settings. 首先,我不确定是否要在wordpress设置或插件设置中更改此设置。 Right now the plugin overrides the settings of wordpress (meaning if I have two different texts in wordpress and the plugin it picks the text from the plugin). 现在,该插件会覆盖wordpress的设置(这意味着如果我在wordpress中有两个不同的文本,并且该插件会从插件中选择文本)。 So I could change it in the plugin or I change it in wordpress but have to simultaneously tell wordpress to read it's own file instead of the one in the plugins directory (I would say it makes more sense to change it in the plugin but I wanted to make sure). 因此,我可以在插件中进行更改,也可以在wordpress中进行更改,但必须同时告诉wordpress读取其自身的文件,而不是plugins目录中的文件(我想说在插件中进行更改更有意义,但我想确保;确定)。

Second I don't know how to change this code so that it's actually redirecting. 其次,我不知道如何更改此代码,以使其实际进行重定向。 I only got as far as breaking the site or nothing at all is happening. 我只知道破坏站点还是什么都没有发生。

If I go to the file feedback-no-access.php in the bbpress-folder it includes the following code: 如果我转到bbpress文件夹中的文件feedback-no-access.php,它将包含以下代码:

<?php

/**
 * No Access Feedback Part
 *
 * @package bbPress
 * @subpackage Theme
 */

?>

<div id="forum-private" class="bbp-forum-content">
    <h1 class="entry-title"><?php _e( 'Private', 'bbpress' ); ?></h1>
    <div class="entry-content">
        <div class="bbp-template-notice info">
            <p><?php _e( 'You do not have permission to view this forum.', 
'bbpress' ); ?></p>
        </div>
    </div>
</div><!-- #forum-private -->

In the members-plugin I find the following lines: 在members-plugin中,我找到以下几行:

/**
 * Error Message Option
 */
function pmprobb_option_error_message() {
    $options = pmprobb_getOptions();    
    if(isset($options['error_message']))
        $error_message = $options['error_message'];
    else
        $error_message = "";    
    ?>
    <input id='pmprobb_option_error_message' name='pmprobb_option_error_message' size='40' type='text' value='<?php echo esc_attr($error_message);?>' />
    <small>This message is shown when users attempt to view a forum or thread they don't have access to.</small>
    <?php
}

I tried to edit this second block of code so that it's not searching for this message but redirecting to an url I want to point to. 我试图编辑第二段代码,以便它不搜索此消息,而是重定向到我要指向的URL。 But nothing really worked out and I hope that somebody can help me out with that! 但是什么都没有解决,我希望有人可以帮助我! Thank you 谢谢

I could solve it by myself without changing the code (which wasn't really possible for me as I don't have enough knowledge). 我可以自己解决它而无需更改代码(由于我没有足够的知识,这对我来说实际上是不可能的)。

I found a plugin called redirection and it works perfectly fine. 我找到了一个名为重定向的插件,它工作正常。 Whenever I click on a forum that I have no access to it redirects me to the page I want it to go to. 每当我单击无权访问的论坛时,都会将我重定向到我要访问的页面。 I don't know if this is a good practice but it works perfectly fine! 我不知道这是否是个好习惯,但是效果很好!

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

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