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.

PHP not working on Login Welcome Page

Home Forums Community Forum PHP not working on Login Welcome Page

This topic contains 11 replies, has 3 voices. Last updated by  Colin Kells 3 years, 12 months ago.

Topic Author Topic
Posted: Tuesday Jan 8th, 2013 at 1:35 pm #36592
Colin Kells
Username: cpufix

Unable to get PHP working on Login Welcome page, [s2 — works ok.
Using these basic commands S2 works PHP does not

[s2If current_user_is(s2member_level1)]
Some premium content for Level 1 Members.
[/s2If] [s2If current_user_is(s2member_level0)]
Some content for Free Subscribers.
[/s2If] [s2If !current_user_can(access_s2member_level0)]
Some public content.
[/s2If]
<?php if(current_user_is("s2member_level1")){ ?>
    Content for Level1 Members.
<?php } ?>
<?php if(current_user_is("s2member_level0")){ ?>
        Content for Free Members.
<?php } ?>

Problem is that neither of the PHP conditions show, seems like PHP is not working.

PHP exec is enabled for each user level.
PHP exec plugin is installed
Test page also not working

  • This topic was modified 4 years ago by  Colin Kells.
  • This topic was modified 4 years ago by  Colin Kells.
  • This topic was modified 4 years ago by  Eduan. Reason: Moved to the customer support forums

List Of Topic Replies

Viewing 11 replies - 1 through 11 (of 11 total)
Author Replies
Author Replies
Posted: Wednesday Jan 9th, 2013 at 7:06 am #36727

Did you post the PHP code in the text tab? Don’t switch to the visual tab or the code won’t work.

Now, if you have the PHP execution plugin correctly installed, PHP should execute… You can also try other PHP exec plugins.

Posted: Wednesday Jan 9th, 2013 at 1:10 pm #36794
Colin Kells
Username: cpufix

Hi Cristian

Code was inserted in TEXT mode.

I have added the line below and the ws_table works fine.

<?php echo do_shortcode('[ws_table id="1"]'); ?>
  • This reply was modified 3 years, 12 months ago by  Colin Kells.
Posted: Saturday Jan 12th, 2013 at 8:06 am #37124

I see. That’s odd then, those conditions should be fine… Could you try this conditional taken from the documentation examples? [hilite path]Dashboard -› s2Member® -› API / Scripting -› Advanced PHP Conditionals -> Example 3[/hilite]

[hilite pre_code]

Some premium content for Level 4 Members.

Some premium content for Level 3 Members.

Some premium content for Level 2 Members.

Some premium content for Level 1 Members.

Some content for Free Subscribers.

Some public content.

[/hilite]

[hilite mono]"s2member_leveln"[/hilite] is the WP role, which you can see with a plugin like User Role Editor.
http://wordpress.org/extend/plugins/user-role-editor/
http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_current_user_is%28%29

Posted: Saturday Jan 12th, 2013 at 3:37 pm #37173
Colin Kells
Username: cpufix

Ok I have changed from “Role Manager” to “User Role Editor” this does seem a lot better to use. Have reset S2 member levels and labels. Removed test users and created new users.

Using the following code

<?php if (current_user_is("s2member_level4")){ ?>
   Some premium content for Level 4 Members.
<?php } else 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 } ?> 

<?php 
if (current_user_can("access_s2member_ccap_free")) 
{
echo "Content for ccap free Members.";
}
elseif (current_user_can("access_s2member_ccap_bapaid"))
{
echo "Content for ccap bapaid Members.";
}
?>

Login using s2member level0 – I get displayed
Some Content For Free Subscribers
Content For ccap free members

Login using s2member level1 – I also get displayed
Some Content For Free Subscribers
Content For ccap free members

This is the problem its seeing all logons as Free Subs.

I’ll look throught the articles that you have included in your reply.
Cheers

Posted: Saturday Jan 12th, 2013 at 3:51 pm #37176
Colin Kells
Username: cpufix

If I use the following code from your article.

<?php
if(current_user_is("subscriber"))
	echo 'You ARE a Free Subscriber at Level #0.';
 
else if(current_user_is("s2member_level1"))
	echo 'You ARE a Member at Level #1.';
 
else if(current_user_can("access_s2member_level2"))
	echo 'You DO have access to content protected at Level #2.';
	# But, (important) they could actually be a Level #3 or #4 Member;
	# because Membership Levels provide incremental access.
?>

And use the following S2

[s2If current_user_is(subscriber)]
You ARE a Free Subscriber at Level #0.
[/s2If]
[s2If current_user_is(s2member_level1)]
You ARE a Member at Level #1.
[/s2If]
[s2If current_user_can(access_s2member_level2)]
You DO have access to content protected at Level #2.
[/s2If]

Logon as Subsriber both PHP and S2 return
You ARE a Free Subscriber at Level #0.

Logon as Level 1
PHP returns – You ARE a Free Subscriber at Level #0.
S2 returns – You ARE a Member at Level #1.

Posted: Sunday Jan 13th, 2013 at 4:15 am #37226
Staff Member

Thanks for the heads up on this thread :-)

I’m reviewing this thread, and I will reply shortly for you :-)

Posted: Sunday Jan 13th, 2013 at 9:20 am #37240
Staff Member

Investigation completed – thanks for your patience.

I just ran the same test you did, together with the shortcode conditionals as well.

<?php
if(current_user_is("subscriber"))
	echo 'You ARE a Free Subscriber at Level #0.';
 
else if(current_user_is("s2member_level1"))
	echo 'You ARE a Member at Level #1.';
 
else if(current_user_can("access_s2member_level2"))
	echo 'You DO have access to content protected at Level #2.';
	# But, (important) they could actually be a Level #3 or #4 Member;
	# because Membership Levels provide incremental access.
?>

[s2If current_user_is(subscriber)]
You ARE a Free Subscriber at Level #0.
[/s2If]
[s2If current_user_is(s2member_level1)]
You ARE a Member at Level #1.
[/s2If]
[s2If current_user_can(access_s2member_level2)]
You DO have access to content protected at Level #2.
[/s2If]

If I login as a Free Subscriber, I get:

You ARE a Free Subscriber at Level #0.
You ARE a Free Subscriber at Level #0.

If I login as a Level #1 Member, I get:

You ARE a Member at Level #1.
You ARE a Member at Level #1.

In short, I’ve been unable to reproduce this on a clean WordPress installation. It sounds to me like your Roles/Capabilities might have become corrupted in some way. Or, I suppose it’s possible that you have another theme/plugin conflicting with s2Member in some way?

Possible solutions.

  • Go to your Dashboard under this section and click the Reset Roles/Capabilities Button.
    Dashboard -› s2Member® -› General Options -› Membership Levels/Labels
  • Test this on a brand new test installation of WordPress, running the default theme, with only the s2Member plugin active. Can you reproduce it there? I was unable to do this.

Please let us know if problems persist :-)

Posted: Sunday Jan 13th, 2013 at 2:04 pm #37284
Colin Kells
Username: cpufix

Hi Jason

Thank you for your reply and help.
I’ll step through your suggestions and see how it goes.

I have tried the Rest Roles several times.

Can you please confirm that you ran the tests on the S2 protected login page and that this was done on Word Press 3.5 ?

The following piece of code works fine and returns the correct condition for the Level 1 member ID

<?php
if(user_is(29, "subscriber"))
	echo 'User ID# 29 is a Free Subscriber at Level #0.';
 
else if(user_is(29, "s2member_level1"))
	echo 'User ID# 29 is a Member at Level #1.';
 
else if(user_can(29, "access_s2member_level2"))
	echo 'User ID# 29 has access to content protected at Level #2.';
	# But, (important) they could actually be a Level #3 or #4 Member;
	# because Membership Levels provide incremental access.
?>

<?php
if(user_is(28, "subscriber"))
	echo 'User ID# 28 is a Free Subscriber at Level #0.';
 
else if(user_is(28, "s2member_level1"))
	echo 'User ID# 28 is a Member at Level #1.';
 
else if(user_can(28, "access_s2member_level2"))
	echo 'User ID# 28 has access to content protected at Level #2.';
	# But, (important) they could actually be a Level #3 or #4 Member;
	# because Membership Levels provide incremental access.
?>

Which to me looks like a problem in the if(current_user_is(“s2member_level1”)).

The function http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_current_user_is%28%29
implies a change at version 3.5 (I assume this is Word Press) as follows:

“Since:
3.5
Parameters:
str $role – A WordPress® Role ID ( i.e. s2member_level[0-9]+, administrator, editor, author, contributor, subscriber ).
Returns:”

Posted: Sunday Jan 13th, 2013 at 2:13 pm #37286
Staff Member

Thanks for the follow-up :-)

Can you please confirm that you ran the tests on the S2 protected login page and that this was done on Word Press 3.5 ?

Yes, my test was run against WordPress v3.5 and WordPress v3.6 alpha.

“Since:
3.5

This is referring to the s2Member version number, which was (in the beginning) based on traditional version numbers instead of the dated format we use now. The last time this s2Member function changed was about 2 years ago.

Please let me know if you find out anything more,
or if you discover a bug. Thanks!

Posted: Sunday Jan 13th, 2013 at 4:06 pm #37303
Colin Kells
Username: cpufix

Hi

I have changed the Theme to a WP default theme and still have the same challenge.
Deactivated pluggins just running:
wp no category base WPML compatible
User role editor
S2 framework and Pro V121213
Exec-PHP V4.9.
Same challenge.

I have noted in the settings of Exec PHP that its reffering to users permitted on articles and not pages.

What pluggin does S2 Member suggest for PHP and User Role Edit?

After this I’ll try fresh installed WP and S2 on another site

  • This reply was modified 3 years, 12 months ago by  Colin Kells.
Posted: Sunday Jan 13th, 2013 at 4:57 pm #37307
Colin Kells
Username: cpufix

Work around solution.

There really is something wrong with if(current_user_is(“s2member_level[1-4]″)) on my site.
I have now created a new role named paid and given it the effective rights of s2member_level1, this
is working fine.

Viewing 11 replies - 1 through 11 (of 11 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.