latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Activate download links by levels

Home Forums Community Forum Activate download links by levels

Tagged: 

This topic contains 7 replies, has 3 voices. Last updated by  Emmanuel Genoll 4 years, 1 month ago.

Topic Author Topic
Posted: Friday Nov 9th, 2012 at 11:51 am #31142

Hello,
I need to activate links of download according to the level of the members. I already have a condition to display or not these links if exists. I don’t know how to combine both conditions.

My first contition:

<?php
if(in_array('ziplevel3', get_field('zipfiles')))
	{
 	$freelink = '<a title="You must be a member to download" href="/join">Zip Level 3</a><br/>';
	  echo "$freelink";
	}
if(in_array('ziplevel2', get_field('zipfiles')))
	{
	$freelink = '<a title="You must be a member to download" href="/join">Zip Level 2</a><br/>';
	   echo "$freelink";
	}
if(in_array('ziplevel1', get_field('zipfiles')))
	{
    $freelink = '<a title="You must be a member to download" href="/join">Zip Level 1</a><br/>';
	    echo "$freelink";
	}
?>

The other condition API/Scripting -> The Advanced PHP Conditionnals -> Example 3

<?php } if (current_user_is("s2member_level3")){ ?>
    Some premium content for Level 3 Members.
<?php } else if (current_user_is("s2member_level2")){ ?>
    Some premium content for Level 2 Members.
<?php } else if (current_user_is("s2member_level1")){ ?>
    Some premium content for Level 1 Members.
<?php } else if (current_user_is("s2member_level0")){ ?>
    Some content for Free Subscribers.
<?php } else { ?>
    Some public content.
<?php } ?>

List Of Topic Replies

Viewing 7 replies - 1 through 7 (of 7 total)
Author Replies
Author Replies
Posted: Friday Nov 9th, 2012 at 3:56 pm #31171
Eduan
Username: Eduan
Moderator

Well you can use AND OR statements. AND is && and OR is ||, Like so:

if(in_array('ziplevel2', get_field('zipfiles')) && current_user_is("s2member_level2")) {
	$freelink = '<a title="You must be a member to download" href="/join">Zip Level 2</a><br/>';
	echo "$freelink";
}

Hope this helps. :)

Posted: Friday Nov 9th, 2012 at 4:02 pm #31173

Thanks, I test that tomorrow, now I am going to sleep.

;=/

Posted: Saturday Nov 10th, 2012 at 4:15 am #31189

Sorry but it don’t work :-(
And how to show the value $freelink if the member has no required levels ? How to add and else condition ?

if(in_array('ziplevel2', get_field('zipfiles')) && current_user_is("s2member_level2"))
	{
	$freelink = '<a title="Freelink" href="/join">Zip Level 2</a><br/>';
	$memberlink = '<a title="Member only" href="#">Zip Level 2</a><br/>';
	echo "$memberlink";
	}
Posted: Monday Nov 12th, 2012 at 1:32 pm #31331
Eduan
Username: Eduan
Moderator

Well I checked the code, and I really can’t find what the problem might be. Do you get any error? If so could you please show me a screenshot of it?

To do an else, just put an else statement:

if (in_array('ziplevel2', get_field('zipfiles')) && current_user_is("s2member_level2")) {
	$freelink = '<a title="Freelink" href="/join">Zip Level 2</a><br/>';
	$memberlink = '<a title="Member only" href="#">Zip Level 2</a><br/>';
	echo "${memberlink}";
} else {
	echo 'Content for user with not access';
}

– Eduan

Posted: Wednesday Nov 14th, 2012 at 6:13 am #31550

It works; like this :

if (in_array('ziplevel2', get_field('zipfiles')) && current_user_is("s2member_level2")) {
	$memberlink = '<a title="Member only" href="#">Zip Level 2</a><br/>';
	echo "$memberlink";
} else {
	$freelink = '<a title="Freelink" href="/join">Zip Level 2</a><br/>';
	echo "$freelink";
}

Thank you

Posted: Wednesday Nov 14th, 2012 at 9:10 am #31571

Cool.

You could also do without the variables and just echo the strings:

[hilite pre_code]
if (in_array('ziplevel2', get_field('zipfiles')) && current_user_is('s2member_level2'))
echo 'Zip Level 2
';
else
echo 'Zip Level 2
';
[/hilite]
Posted: Wednesday Nov 14th, 2012 at 9:16 am #31574

Great, thank you

Viewing 7 replies - 1 through 7 (of 7 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.