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 stopped working recently

Home Forums Community Forum Custom capabilities stopped working recently

This topic contains 3 replies, has 2 voices. Last updated by  Raam Dev 4 years, 5 months ago.

Topic Author Topic
Posted: Monday Jul 9th, 2012 at 11:15 pm #18755

I wrote a plugin months ago which added a custom capability when certain members register. Here’s the part business end of the code:

//Look at new registrations...
add_action('user_register', 'check_if_student', 1);

//Check if they qualify as a student or not...
function check_if_student($user_id) {
	$user = new WP_User($user_id);
	$user_data = get_userdata($user_id);
	$user_email = $user_data->user_email;
	
	if (check_email($user_email) ) {
		$user->add_cap("access_s2member_ccap_student");
	} else { //do nothin!
	 }
}

//This happens when a user tries to visit a restricted access page...
add_filter('ws_plugin__s2member_sp_access_excluded', 'special_access', 1, 2);

function special_access($excluded, $vars) {
	if (current_user_can('access_s2member_ccap_student')) {
		
		$current_user = wp_get_current_user();
		$current_user_id = $current_user->ID;
		
		//expired_check returns true if NOT expired yet (still good)
		if ( not_expired_check() &&  not_stop_student_check() ) {
			$excluded = TRUE;
			return $excluded;
		} else {
			$excluded = FALSE;
		}
		
	}
}

We started getting complaints a couple weeks ago that the plugin is no longer working. (Members with the “student” custom capability no longer are able to access the areas that are restricted by that capability) A lot of things have happened in that time, including the upgrade to WP v3.4 as well as the subsequent s2member update. Any chance this would have an effect on what I’m doing?

  • This topic was modified 4 years, 6 months ago by  Brett Adcock.

List Of Topic Replies

Viewing 3 replies - 1 through 3 (of 3 total)
Author Replies
Author Replies
Posted: Wednesday Jul 11th, 2012 at 12:52 am #18860
Raam Dev
Username: Raam
Staff Member

Hi Brett,

I don’t know of any changes in s2Member or WordPress that would affect the operation of that code, but there are lots of other custom functions that the code points to (e.g., check_email(), not_stop_student_check()).

To debug the problem, I suggest logging or printing out each step through the code to see where things stop working and go from there.

Posted: Wednesday Jul 11th, 2012 at 12:00 pm #18933

Thanks for the advice. We found the problem and you were basically right. There was a bug in one of our custom functions that was breaking the system.

Posted: Friday Jul 13th, 2012 at 12:51 am #19108
Raam Dev
Username: Raam
Staff Member

Glad to help, Brett!

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