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.

How to get data about previous page?

Home Forums Community Forum How to get data about previous page?

This topic contains 6 replies, has 2 voices. Last updated by  Cristián Lávaque 3 years, 9 months ago.

Topic Author Topic
Posted: Friday Apr 5th, 2013 at 9:33 pm #46730
fpl
Username: ctl

List Of Topic Replies

Viewing 6 replies - 1 through 6 (of 6 total)
Author Replies
Author Replies
Posted: Saturday Apr 6th, 2013 at 11:13 am #46767
fpl
Username: ctl

EDIT: I’ve been a bit quick pretending that I knew how to get the user’s ccaps (and I meant display them)…

I thought the whole answer was here: http://www.s2member.com/forums/topic/cant-receive-the-users-ccaps-values/

…but if I do as suggested and write:

<?php
$user_capabilities = get_user_option('capabilities', S2MEMBER_CURRENT_USER_ID);
print_r($user_capabilities);

$user_ccaps = explode('|', $user_capabilities);
echo $user_ccaps[1];
?>

I only get the result of print_r:

Array
(
[s2member_level1] => 1
[access_s2member_ccap_module1] => 1
[access_s2member_ccap_module2] => 1
)

Nothing is echoed. I’ve tried other delimiters, no luck. Really can’t figure out how to echo all the ccaps contained in the array, or any of them actually. I’ve tried a bunch of stuff suggested on php.net and stackoverflow, no luck either. Needless to say I’m a PHP ninja… ;)

Anyway, that’s just another question to add to the 2 previous ones.

Thanks for your assistance, the explode() function works miracles on my brain! ;)

Posted: Tuesday Apr 9th, 2013 at 8:53 am #46907

1. How can I get the ccap required for the previously requested post

[hilite path]Dashboard -› s2Member® -› API / Scripting -› Membership Options Page Variables (MOP Vars)[/hilite]

Really can’t figure out how to echo all the ccaps contained in the array, or any of them actually.

Something like this? (not tested)

[hilite pre_code]
foreach ($user_capabilities as $cap => $v) {
if (strpos($cap, 'access_s2member_ccap_') !== false)
echo $cap . "\n";
}
[/hilite]
Posted: Tuesday Apr 9th, 2013 at 11:05 am #46912
fpl
Username: ctl

Thanks, Cristiàn!

1. Okay… I missed that.

2.

<?php
$user_capabilities = get_user_option('capabilities', S2MEMBER_CURRENT_USER_ID);
foreach ($user_capabilities as $cap => $v) {
	if (strpos($cap, 'access_s2member_ccap_') !== false)
		echo $cap . "\n";
}
?>

Returns:

access_s2member_ccap_module1
access_s2member_ccap_module2

Which is a good start ;) but, as you can guess, what I’d like to display is:

You have access to module 1, which contains:
[Links to posts included in module 1]

Posted: Wednesday Apr 10th, 2013 at 12:04 am #46993

Which is a good start ;) but, as you can guess, what I’d like to display is:

Well, then you don’t need to echo the ccaps. Have a list of links for each module inside conditionals for each ccap, for example. The conditions can just check if the key with the ccap is set, for example:

[hilite pre_code]
if(isset($user_capabilities['access_s2member_ccap_module1'])) {
// Links to Module 1 pages.
}
[/hilite]
Posted: Wednesday Apr 10th, 2013 at 8:14 am #47067
fpl
Username: ctl

Well, Cristiàn… you’re totally right.

I don’t know if you’ve ever been in this stupid state, where you don’t even remember why you have to do something, but all you “know” is you have to? It generally means you are knackered and you need a serious break… I went out of the stupid state yesterday, and wrote this awesomeness in my mu-plugins:

<?php function you_can_access()
	{
		echo ("<p><strong>Hi " . S2MEMBER_CURRENT_USER_FIRST_NAME . "!</strong></p><p>You currently have access to:</p>");
		if(current_user_can('access_s2member_ccap_module1')) 
		{
			echo ('
			<h4>Module 1</h4>
			<ul>
			<li>Content 1</li>
			<li>Content 2</li>
			<li>Content 3</li>
			</ul>
				');
		
		
		if(current_user_can('access_s2member_ccap_module2')) 
		{
		// Guess what?
		}

I’ll echo the ccaps… next time. ;)

Thanks again!

Posted: Wednesday Apr 10th, 2013 at 8:34 am #47072

:)

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