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 keep some *some* ccap's after demotion

Home Forums Community Forum How to keep some *some* ccap's after demotion

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

Topic Author Topic
Posted: Thursday Oct 18th, 2012 at 11:32 am #28848

Okay, first let me thank you for all of your help so far. I am getting S2member figured out — it is certainly fantastic.

I am using MailChimp to have the capability to send emails to everyone (the MailChimp list) and separate emails to different types (MailChimp Groups). S2member works great to manage the MailChimp side as my S2 users are created, expire, renew, or are even deleted. I have used the http://www.s2member.com/kb/changing-the-eot-demotion-level-dynamically/ hack to setup for dynamic demoting of users — works great!

Further, I am starting to understand what I can and can’t do with amr-user to generate lists for my S2member users. CCap’s work well to provide needed filtering. However, I need some of my ccap’s used for the amr-list filtering to not be removed when the EOT is reached.

Now to my question. It appears to me that the ccap’s are being removed in the hack I have created using the hack described above. I am looking at the code immediately below where the dynamic demotions are set:

/* added by WPE based on Dynamic EOT hack post in the S2member forum */

$existing_role = c_ws_plugin__s2member_user_access::user_access_role ($user);

if($existing_role === 's2member_level12')          // Corporate Member
	$demotion_role = 's2member_level6';         // expired Corporate Member

elseif($existing_role === 's2member_level11')    // Corporate Alternate
	$demotion_role = 's2member_level5';         // expired Corporate Alternate

elseif($existing_role === 's2member_level10')    // Corporate Member-at-Large
	$demotion_role = 's2member_level4';         // expired Corporate Member-at-Large

elseif($existing_role === 's2member_level9')     // Individual Member
	$demotion_role = 's2member_level3';        // expired Individual Member
	
else      						 	     // Guest
	$demotion_role = c_ws_plugin__s2member_option_forces::force_demotion_role("subscriber");

Then, it appears that the code immediately after this block is used to remove the data from various fields to include the ccap’s.

eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
do_action ("ws_plugin__s2member_during_auto_eot_system_during_before_demote", get_defined_vars ());
do_action ("ws_plugin__s2member_during_collective_mods", $user_id, get_defined_vars (), $eot_del_type, "modification", $demotion_role);
do_action ("ws_plugin__s2member_during_collective_eots", $user_id, get_defined_vars (), $eot_del_type, "modification");
unset ($__refs, $__v); /* Unset defined __refs, __v. */
/**/
if ($existing_role !== $demotion_role) /* Only if NOT the existing Role. */
	$user->set_role ($demotion_role); /* Give User the demotion Role. */
/**/
foreach ($user->allcaps as $cap => $cap_enabled)
	if ( preg_match ("/^access_s2member_ccap_/", $cap) )
		$user->remove_cap ($ccap = $cap);               
/**/
delete_user_option ($user_id, "s2member_custom");     
delete_user_option ($user_id, "s2member_subscr_id");

Specifically, the foreach loop appears to be removing the ccap’s.

Two questions:

1) can I add an if statement after

	if ( preg_match ("/^access_s2member_ccap_/", $cap) ) 

    that would allow me to test for specific ccap's, e.g. access_s2member_corp_mbr, 
    and skip the removal of that ccap?  If so, what would that if statement look like?
    
2) can I add a ccap if another is to be removed, e.g, could I test for ccap = active with
      
      if ( preg_match ("/^access_s2member_ccap_active/", $cap) )  
      
     and then add a ccap "access_s2member_inactive"?  If so, how?

Thank you in advance,
Bill

  • This topic was modified 4 years, 2 months ago by  Eduan. Reason: Removed unnecessary pre tags

List Of Topic Replies

Viewing 2 replies - 1 through 2 (of 2 total)
Author Replies
Author Replies
Posted: Thursday Oct 18th, 2012 at 4:48 pm #28904

Okay, I have answered question 1 above with this code:

<pre>
/*
 * ccap corp_mbr,active added through registration or renewal of corporate memberships
 * ccap inactive added (not working yet) to corporate membership when demoted due to EOT 
 *
 * code below prevents removal of ccap for values = corp_mbr, bod_mbr, active, inactive
*/
	foreach ($user->allcaps as $cap => $cap_enabled)
		if ( preg_match ("/^access_s2member_ccap_/", $cap) )
			if ( !preg_match ("/^access_s2member_ccap_corp_mbr/", $cap) &&
			     !preg_match ("/^access_s2member_ccap_bod_mbr/",  $cap) &&
			     !preg_match ("/^access_s2member_ccap_active/",   $cap) &&
			     !preg_match ("/^access_s2member_ccap_inactive/", $cap)	 ) 

					$user->remove_cap ($ccap = $cap); 

</pre>

Do you see anything wrong with this code?

Next, I have experimented with the question 1 inserting this code in the demoting section of the code in the original post above:

<pre>
	/* added by WPE based on Dynamic EOT hack post in the S2member forum */
	
	$existing_role = c_ws_plugin__s2member_user_access::user_access_role ($user);

	if($existing_role === 's2member_level12') {     		// Corporate Member
		$demotion_role = 's2member_level6';    		// expired Corporate Member
		$user->add_cap("access_s2member_inactive");
		$user->remove_cap("access_s2member_active");
	}
	else
		$demotion_role = c_ws_plugin__s2member_option_forces::force_demotion_role("subscriber");
</pre>

This code (and there are actually a number of elseif’s to cover all of the s2member_levels) does work correctly to demote the role from level12 to level6; however, it does not add the ccap = inactive and remove ccap = active.

What am I doing wrong?

Thanks,
Bill

Posted: Friday Oct 19th, 2012 at 9:05 am #28997

Do you see anything wrong with this code?

I think it’s okay.

however, it does not add the ccap = inactive and remove ccap = active.

Not sure, I’d need to play with this and test to find what’s wrong. But you’re getting the hang of it, since your other hacks are working, I’m sure you’ll figure it out soon. :)

I am getting S2member figured out — it is certainly fantastic.

Thanks for the kudos!

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.