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.
Like the direct download link example here: www.externallink.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.
How to do?
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>';
or this one:
$link_to_output = apply_filters( 'public_link_root', 'ourwebsite.com' ) . '/resources/whatever/here';
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:
echo '<a href="' . custom_link() . '">View Resources</a>';
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.