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.

Get capability of logged in user [closed]

Home Forums Community Forum Get capability of logged in user [closed]

This topic contains 2 replies, has 2 voices. Last updated by  Eduan 3 years, 10 months ago.

Topic Author Topic
Posted: Friday Feb 22nd, 2013 at 7:47 am #42795
Angela Zou
Username: angelaz

Currently I have added a capability of 15 to a user, and I’d use the capabilities to do other stuff. Here is my code currently partially removed.

add_shortcode( 'my_courses', 'my_courses' );

function my_courses( ) {

	get_currentuserinfo();

	if(!$current_user->caps) {
		var_dump($current_user->caps); //I got NULL here
		foreach($current_user->caps as $course_post_id) {
			//Do stuff here
		}
	}

	return $output;
}

Edit: in addition, I would like to obtain only the capabilities that are created by s2member, excluding any wordpress default capability. Thanks.

List Of Topic Replies

Viewing 2 replies - 1 through 2 (of 2 total)
Author Replies
Author Replies
Posted: Friday Feb 22nd, 2013 at 10:11 am #42821
Angela Zou
Username: angelaz

Never mind, found the solution. It worked like this

global $current_user;
get_currentuserinfo();
if(count($current_user->caps) != 0) {
	foreach($current_user->caps as $key => $value) {
		preg_match("/[0-9]{1,}$/", $key, $course_post_id); //You should match for the string after access_s2member_ccap_*
		//Do stuff with the capability names
	}
}
Posted: Friday Feb 22nd, 2013 at 6:15 pm #42869
Eduan
Username: Eduan
Moderator

Glad you found the solution Angela. :)

Thanks for sharing it too! ;)

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