如何屏蔽所有帖子中的外部下载链接并限制成员? [英] How to mask external download links in all posts and restrict to members?

查看:79
本文介绍了如何屏蔽所有帖子中的外部下载链接并限制成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将外部下载链接屏蔽为内部链接,并且只能由登录用户访问?即使登录成员登录并查看帖子也不应该看到外部下载站点域。它应该为每个人掩盖。如果他们没有登录到wordpress网站,如果他们将网址复制/粘贴到他们的浏览器中,他们就不应该访问下载网址。

How to mask external download links as internal links and to be only accessible by logged-in users? And even logged-in members shouldn't see the external download site domain if they logged-in and looked at posts. It should be masked for everyone. Plus they shouldn't get access to download url if they copy/paste the url into their browser if they don't logged-in to wordpress site.

喜欢直接下载此处的链接示例: www.externallink.com/direct-download-link1

Like the direct download link example here: www.externallink.com/direct-download-link1

我们希望将其屏蔽为作为我们的内部网址: www.ourwebsiteurl.com/direct-download-link1

We want to mask it like as our internal url: www.ourwebsiteurl.com/direct-download-link1

此上述链接仅应登录会员可以访问。

and this above link should only be accessible by logged-in members.

怎么办?

我们在函数内部尝试过以下代码.php和单个post.php。但什么都没发生,没有任何改变我们完全控制外部下载链接网站。它是基于perl的脚本,它生成不同的下载链接。

We've tried below codes inside functions.php and single post.php. But nothing happened, nothing changed. We have full control of external download link site. And it is perl based script which generates different download links.

$user = wp_get_current_user();
if( $user->exists ) {
    add_filter( 'public_link_root', function() { return 'example.com'; } );
}



$some_link = apply_filters('public_link_root', 'ourwebsite.com') . '/resources';
echo '<a href="' . $some_link . '">View Resources</a>';

或这一个:

$link_to_output = apply_filters( 'public_link_root', 'ourwebsite.com' ) . '/resources/whatever/here';

或在functions.php中:

or in functions.php:

function custom_link() {
     $user = wp_get_current_user();
     return (is_user_logged_in())? "www.example.com/direct-download-link1":"just_a_dummy_link";
}

single.php:

single.php:

echo '<a href="' . custom_link() . '">View Resources</a>';

我预计www.externallink.com域名的所有网址都将更改为www.ourwebsiteurl.com但上面的代码没有改变。即使是已登录的成员也应屏蔽这些链接。如果这些链接未登录,则将这些链接复制并粘贴到浏览器中,这些链接应该不起作用。

I expected to all urls of www.externallink.com domain will be changed to www.ourwebsiteurl.com but nothing changed with above codes. The links should be masked for even logged-in members. And those links shouldn't be work if they copy and paste those urls into their browser if they are not logged-in.

推荐答案

更新

OP的评论:
重定向怎么样?可以看出我知道我至少想要隐藏这些网址,以便大多数人不会知道它。

最简单的方法是编辑服务器上的.htaccess文件

The easiest way is to edit the .htaccess file on your server

Redirect 301 /resources https://external.com/direct-download-link1

已修改

也许您可以使用<$ c $创建自己的自定义函数c> is_user_logged_in()(请参阅 doc )。在任何想要设置链接的地方,请调用自定义函数:

Perhaps you can create your own custom function using is_user_logged_in() (see doc). Anywhere you want to put a link, call your custom function:

所以在functions.php中:

So in functions.php:

function custom_link() {
    // will only show link when user is logged in
    if (is_user_logged_in()) {
        // this only shows the "internal" link which will be redirected to external link
        echo '<a href="https://www.example.com/resources">View Resources</a>';
    }
}

在您的页面上:

   custom_link(); //will not show link if user not logged in

这篇关于如何屏蔽所有帖子中的外部下载链接并限制成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆