Page 1 of 1
start restricted file download on log in
Posted:
June 18th, 2011, 6:20 am
by sidera
scenario : a non member visitor clicks the link to download a restricted file (there is only free membership level on this site), then he's redirected to the membership option page. if he registers and logs in I want the requested file to download without him having to do anything, so the site should remember what file had been requested before registration, or if easier to implement just put the link to the requested file on the login welcome page.
Re: start restricted file download on log in
Posted:
June 18th, 2011, 8:06 am
by sidera
Re: start restricted file download on log in
Posted:
June 18th, 2011, 8:47 am
by sidera
just one thing though : I want the redirect to do this :
register -> login -> direct file download -> home page, instead of register -> login -> page
but it seems I can't use the redirect_to without the login part, so I'm stuck on the login page and each time I click on the login button it downloads the file instead of logging in
is that possible?
Re: start restricted file download on log in
Posted:
June 18th, 2011, 10:43 pm
by Cristián Lávaque
You mean something like this? wp-login.php?redirect_to=/%3Fs2member_file_download%3Dexample-file.zip
Re: start restricted file download on log in
Posted:
June 19th, 2011, 6:34 am
by sidera
I tried
/wp-login.php?action=register&redirect_to=wp-login.php?redirect_to=http://example.com/s2member_file_download-example-file.pdf
now I'm looking at another solution : would it be possible to save the file name in a global variable, then display it in a link on the login welcome page?
I tried setting a global $filename variable in a function, but once the user logs in it's out of scope
Re: start restricted file download on log in
Posted:
June 19th, 2011, 11:43 am
by Cristián Lávaque
Hmm... Well, you could store the file URL in $_SESSION too, and pick it up later. The redirection you showed me should work with a bit more tweaking, though. For example, you haven't URL enconded the charaters, that may be causing you trouble.
Re: start restricted file download on log in
Posted:
June 19th, 2011, 2:01 pm
by sidera
ok, so seesion variables don't seem to work well in WordPress, but I used the set_transient function to set a temporary variable that is accessible on every page, and so far it looks good.
- Code: Select all
add_action('genesis_after_post_title','wpc_do_s2member_notify');
function wpc_do_s2member_notify(){
list($seeking, $file) = preg_split("/-/", $_GET["s2member_seeking"], 2);
if(is_page('membership-signup')){
set_transient('wpc_file_name', $file, 1800);
if($seeking === "file"){
?>
<p style="background-color:#ffffe0;padding:10px;border:1px solid #E6DB55;text-align:center;">In order to gain access to this free content, you must become a member. <a href="/wp-login.php?action=register"><u>Click here to register</u></a> and you will be automatically brought back to the free content you were trying to access. If you are an existing member, you can <a href="/wp-login.php"><u>login here</u></a>.</p>
<?php
}
}
if(is_page('login-welcome-page')){
?>
<p style="background-color:#ffffe0;padding:10px;border:1px solid #E6DB55;text-align:center;"><a href="/?s2member_file_download=<?php echo get_transient('wpc_file_name'); ?>">download your file now</a></p>
<?php
}
//delete_transient('wpc_file_name');
}
let me know if you see any problems that I don't
Re: start restricted file download on log in
Posted:
June 19th, 2011, 2:27 pm
by Cristián Lávaque
Now, wouldn't sending the person straigth to the file after login cause trouble to show him other content for members? It'll always send him to the file after getting into his account. Wouldn't it be better to just have a link ot the file in the Login Welcome Page?
Re: start restricted file download on log in
Posted:
June 19th, 2011, 4:21 pm
by sidera
yes, I did set the login welcome page as the default landing page after login. this function just adds a notice with a link to the file they tried to download before registering.
Re: start restricted file download on log in
Posted:
June 19th, 2011, 7:44 pm
by Cristián Lávaque
Cool.