简体   繁体   English

限制wordpress多站点订户访问未分配给他们的站点上的内容

[英]restrict wordpress multisite subscribers access to content on sites they aren't assigned to

We have a Wordpress mutlisite. 我们有一个Wordpress多功能版。 We have value added resellers that have been approved as Wordpress users and are assigned - as subscribers - to specific sites where they can access marketing materials no one else can access. 我们拥有已被批准为Wordpress用户的增值经销商,并已将其(作为订户)分配给特定站点,使他们可以访问其他人无法访问的营销材料。 I have confirmed this in the Wordpress Network Admin (tab) -> Users (tab). 我已经在Wordpress网络管理员(标签)->用户(标签)中确认了这一点。 We have two sites with separate marketing materials and each user is only assigned to one site. 我们有两个具有不同营销材料的站点,每个用户仅分配给一个站点。

To access the marketing materials the users go to a partner page and there is a button with a link that takes them to the marketing page. 要访问营销材料,用户将转到合作伙伴页面,并且带有链接的按钮会将其带到营销页面。 The link in the button is dynamically generated based on if the person is a logged in user or not. 该按钮中的链接是基于该人是否是已登录用户而动态生成的。 If they are a logged in user, then the link goes to the marketing page, if not, then the link goes to the register/sign-in page. 如果他们是登录用户,则该链接转到营销页面,如果不是,则该链接转到注册/登录页面。

We recently discovered logged-in users could access the marketing materials on BOTH sites regardless of which site they are assigned to. 我们最近发现,已登录的用户可以访问两个站点上的营销材料,无论他们分配到哪个站点。 Currently the only people who can't get to the marketing materials page are people who aren't logged in. 当前,唯一无法进入营销材料页面的人是未登录的人。

If I understand the code, all it does is check if there is a logged in user on the page - then give them a link, in the button, for the marketing page. 如果我理解该代码,它所做的就是检查页面上是否有登录用户-然后在按钮中为他们提供营销页面的链接。

We use Advanced Custom Fields to grab information from different fields on the pages to help create the two links we need to chose between for the button. 我们使用“高级自定义字段”从页面上的不同字段获取信息,以帮助创建我们需要在按钮之间进行选择的两个链接。 Here is the php to set the link that is inserted: 这是设置插入链接的php:

$portal_left_link  = get_field( 'portal_left_link' ); // the link for the marketing page

$register_global = get_field( 'register_login_link', 'option' ); // trying to find this value
$register_override = get_field( 'register_url_override' ); // trying to find this value

$register_login_link = ( ! empty( $register_override ) ) ? $register_override : $register_global; // not sure yet what this does
$register_login_link .= '?redirect_to=' . $portal_left_link; // concatenates a redirect for the (button) link to the portal page to be carried over to the register/sign-in page for when the user needs signs-in

$left_link = is_user_logged_in() ? $portal_left_link : $register_login_link; // i think this says if the user is logged in then give them the portal link, otherwise give them the register/sign-in link

And the button the code is pulled into: 并将代码插入按钮:

<a href="<?php echo esc_url( $left_link ); ?>" class="btn">Login</a>

What I need is code that checks: 我需要的是用于检查的代码:

  • if there is a logged in user; 如果有登录用户;
  • what site the user is assigned to; 用户分配到的站点;
  • does the site the user is on match the site the user is assigned to; 用户所在的网站与该用户分配的网站是否匹配;
  • if all the these statements are a match, then insert a link to the marketing page. 如果所有这些语句均匹配,则插入指向营销页面的链接。
  • Otherwise, insert a link to the register/sign-in page. 否则,请插入指向注册/登录页面的链接。

You can check if a user is a member of a site with this method: 您可以使用以下方法检查用户是否是网站的成员:

https://codex.wordpress.org/Function_Reference/is_user_member_of_blog https://codex.wordpress.org/Function_Reference/is_user_member_of_blog

So your code could look something like this: 因此您的代码可能如下所示:

$portal_left_link = get_field( 'portal_left_link' ); // the link for the marketing page
if (is_user_logged_in() && is_user_member_of_blog()) // check if the user is logged in and a member of the blog
{
    $left_link = $portal_left_link;
    $left_link_text = "Go To Marketing Page";
}
else
{
    $register_global = get_field( 'register_login_link', 'option' ); // trying to find this value
    $register_override = get_field( 'register_url_override' ); // trying to find this value
    $register_login_link = ( ! empty( $register_override ) ) ? $register_override : $register_global; // not sure yet what this does
    $register_login_link .= '?redirect_to=' . $portal_left_link; // concatenates a redirect for the (button) link to the portal page to be carried over to the register/sign-in page for when the user needs signs-in
    $left_link = $register_login_link;
    $left_link_text = "Login";
}
// code for button
<a href="<?php echo esc_url( $left_link ); ?>" class="btn"><?php echo $left_link_text; ?></a>

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

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