Display content with php Custom Capabilities

I have been trying to display a section on my site using ez-php for custom capabilities.

I have no problem determining if the user is logged in or out by using the following code

[php]if(is_user_not_logged_in()):[/php]

then adding text and images here for logged out users

[php]elseif(is_user_logged_in()):[/php]

then adding text and images here for logged in users.

[php]endif;[/php]

All works fine.

Now come the next bit. I want to display a few boxes if a user does not have a custom cap.

[php]if(current_user_cannot(“access_s2member_ccap_test”)):[/php]

bit of text for the custom capps

[php]endif;[/php]

Yet no matter what I try I can’t get it to work?

On the other hand If I use the [s2if] short code I can get a result, however only with some basic text. I found the php route to be far more powerful.

Any ideas would be greatly appreciated.

Thanks in advance for your help

Your problem is that “is_user_logged_in()” id a WP function (works with or without s2M), but “current_user_cannot()” is s2M only function (can’t work in WP or PHP environment). So use [s2If current_user_cannot(…)] shortcodes (check “API / Scripting”) instead, both functions works there.

1 Like

Hey Krumch, Thanks for the reply

As I mentions I can use the [2sif] shortcode however I found that only works with bit of text.

What I am using is ezphp as it allows me to include more in the hidden section. This works great for visual composer

under API/scripting/advanced/php conditionals there are examples of code that I have adapted.

Under example #6 you will find this snippet

<?php if(current_user_cannot("access_s2member_level4") && (current_user_can("access_s2member_level2") || current_user_can_for_blog(24, "access_s2member_level2"))) { ?>

I found out that the problem comes from && being rendered as &amp &amp in the wordpress text editor.

I have found a workaround by ending the else if statement and then applying the php snippet as a separate piece of code afterwards, thus avoiding the && problem. Then I use another plugin called Visual composer member to create a row that is only visible to logged in members.

Not ideal but it works for now.

If you have any ideas about how join together the two arguments and get around the && then that would be a lot easier and be useful for later pages I am planning. I tried using AND but that didn’t seem to work.

I sure that many people want to use Visual composer with 2smember and ezphp seems like the way to go.

Any ideas are much appreciated

All the best

Colin