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.

Custom Capabilities CCAP

Home Forums Community Forum Custom Capabilities CCAP

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

Topic Author Topic
Posted: Sunday May 26th, 2013 at 1:17 pm #50659

Greetings,

I’m trying to work on a method of providing Custom Capabilities to users based on the time they’ve been a member. I have all the theory down, but I fear I may be doing something very very wrong with a simple basic point.

This is the main part of the code I am working with. I’ll add additional s2Member Conditionals to ensure it operates as intended, but for some reason, even a stripped down version isn’t worked. Anyone care to help?

add_cap('access_s2member_ccap_product');
		$user->remove_cap('access_s2member_ccap_sample');
		
	}

?>

There doesn’t appear to be any issues, I don’t get any error reports on the page, but the Custom Capabilities are just not working. I’m going to turn on logging, and edit this post afterwards with any findings.

List Of Topic Replies

Viewing 2 replies - 1 through 2 (of 2 total)
Author Replies
Author Replies
Posted: Monday May 27th, 2013 at 4:28 am #50700

Update:

I’ve done some more work on it, this is the result so far, and still nothing is working. Anyone at Level #2 is not being provided with the CCAP Product or having their Sample CCAP removed.

<?php

	if (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 2)
    {

		$user = wp_get_current_user();
		$user->add_cap ("access_s2member_ccap_product");
		$user->remove_cap ("access_s2member_ccap_sample");
		
	}

?>

Update #2:

I’ve just put this inside my Header.php file and it is now working. I fear it may have been something to do with my CRON Job, as I just set up email notifications within it, and I’m getting errors that it doesn’t exist, while I can access the directory in my browser.

Posted: Tuesday May 28th, 2013 at 11:11 pm #50781
Bruce
Username: Bruce
Staff Member

Thank you for your inquiry.

Sorry for the delay in response.

As per our Support Policy, we cannot debug custom code, but I can give you some general guidelines to follow when you’re working with upgrading User’s roles.

The first is that you should always hook into something past the init hook if you’re doing the changes from within a Must-Use plugin. If you do not, the code will fire before WordPress has created the Current User’s object. This is the reason it began working in this edit:

I’ve just put this inside my Header.php file and it is now working. I fear it may have been something to do with my CRON Job, as I just set up email notifications within it, and I’m getting errors that it doesn’t exist, while I can access the directory in my browser.


Here’s an example of how your code should look if you’re giving all level 2 Users the Custom Capability product, and removing the Custom Capability sample.

<?php
add_action('init', 's2hack_ccap_changes');
function s2hack_ccap_changes()
	{
		if(current_user_is('s2member_level2') /* See: Dashboard -› s2Member® -› API / Scripting -› Advanced PHP Conditionals*/)
			{
				$user = wp_get_current_user(); /* wp_get_current_user() get's a WordPress WP_User Object, giving access to the methods used below. See: http://codex.wordpress.org/Class_Reference/WP_User */
				
				if(!$user->has_cap('access_s2member_ccap_product'))
					$user->add_cap ('access_s2member_ccap_product');
					
				if($user->has_cap('access_s2member_ccap_sample'))
					$user->remove_cap ('access_s2member_ccap_sample');
			}
	}
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.