PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

start restricted file download on log in

s2Member Plugin. A Membership plugin for WordPress®.

start restricted file download on log in

Postby sidera » June 18th, 2011, 6:20 am

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.
User avatar
sidera
Registered User
Registered User
 
Posts: 21
Joined: March 4, 2011

Re: start restricted file download on log in

Postby sidera » June 18th, 2011, 8:06 am

ok, I found a solution using redirect_to
http://keithjameslock.com/offering-free ... ore-money/
User avatar
sidera
Registered User
Registered User
 
Posts: 21
Joined: March 4, 2011

Re: start restricted file download on log in

Postby sidera » June 18th, 2011, 8:47 am

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?
User avatar
sidera
Registered User
Registered User
 
Posts: 21
Joined: March 4, 2011

Re: start restricted file download on log in

Postby Cristián Lávaque » June 18th, 2011, 10:43 pm

You mean something like this? wp-login.php?redirect_to=/%3Fs2member_file_download%3Dexample-file.zip
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: start restricted file download on log in

Postby sidera » June 19th, 2011, 6:34 am

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
User avatar
sidera
Registered User
Registered User
 
Posts: 21
Joined: March 4, 2011

Re: start restricted file download on log in

Postby Cristián Lávaque » June 19th, 2011, 11:43 am

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.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: start restricted file download on log in

Postby sidera » June 19th, 2011, 2:01 pm

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
User avatar
sidera
Registered User
Registered User
 
Posts: 21
Joined: March 4, 2011

Re: start restricted file download on log in

Postby Cristián Lávaque » June 19th, 2011, 2:27 pm

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?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: start restricted file download on log in

Postby sidera » June 19th, 2011, 4:21 pm

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.
User avatar
sidera
Registered User
Registered User
 
Posts: 21
Joined: March 4, 2011

Re: start restricted file download on log in

Postby Cristián Lávaque » June 19th, 2011, 7:44 pm

Cool. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 1 guest

cron