Page 1 of 1
Custom Capabilities Question
Posted:
July 19th, 2011, 5:01 pm
by fcp2011
I am trying to figure out where the custom capabilities information is actually stored for each user and how to add to it using gravity forms. When I view the user's information, I can see the custom capabilities in this section: s2Member Configuration & Profile Fields
If I use the paypal shortcode options s2member provides, I can see the ccaps holds my custom capability. Now lets say I want to use a normal html form, or gravity forms to enter my custom capability, how would I accomplish this?
Thanks
Re: Custom Capabilities Question
Posted:
July 20th, 2011, 2:02 pm
by Cristián Lávaque
I think s2Member custom capabilities are stored in a serialized array in wp_usermeta/wp_capabilities/.
Re: Custom Capabilities Question
Posted:
July 20th, 2011, 5:24 pm
by fcp2011
ok, so how do I add custom capabilities to existing members accounts?
Re: Custom Capabilities Question
Posted:
July 21st, 2011, 12:06 am
by Cristián Lávaque
Go to their profile pages to add them manually.
WP Admin -> Users -> Edit user -> s2Member Configuration & Profile Fields -> Custom CapabilitiesIf you have s2Member Pro, you can edit users in bulk and import them using the Export and Import tools.
WP Admin -> s2Member -> Import/ExportI hope that helps.
Re: Custom Capabilities Question
Posted:
July 21st, 2011, 8:57 pm
by fcp2011
The custom capabilities don't seem to be located in the table you refer too. I can edit them in the individual user screens but i need a way to use a button to do that. I do have Pro.
Thanks
Re: Custom Capabilities Question
Posted:
July 21st, 2011, 10:30 pm
by Cristián Lávaque
I double checked and they are stored in the usermeta table. Look for the rows that say wp_capabilities.
Re: Custom Capabilities Question
Posted:
July 22nd, 2011, 3:13 pm
by fcp2011
Ok, found it. Had a stupid day obviously. Now, is there any documentation that addresses dealing with the string/array formating? Here is what I have found:
The first one is without a custom capability
a:1:{s:15:"s2member_level1";s:1:"1";}
The second one here is with a "trial" capability
a:2:{s:15:"s2member_level1";s:1:"1";s:26:"access_s2member_ccap_trial";s:1:"1";}
I see that the a:1 changes to a:2 and that the string/array adds a s:1 of 1 as well at the end. When I subsequently remove the "trial" from the user's side, it changes back.
Any help or documentation on this would be great. Is there a filter or function that is available that can be accessed to add the custom capabilities of a user programatically vice manually?
Thanks for your help on this and all matters.
Re: Custom Capabilities Question
Posted:
July 22nd, 2011, 10:56 pm
by Cristián Lávaque
Oh, that's a serialized array.
You can do something like this to add an s2Member custom capability:
- Code: Select all
<?php
$user = wp_get_current_user();
$user->add_cap("access_s2member_ccap_music");
?>
https://codex.wordpress.org/Function_Reference/add_caphttps://codex.wordpress.org/Function_Re ... remove_capI hope that helps.
Re: Custom Capabilities Question
Posted:
August 2nd, 2011, 7:16 pm
by fcp2011
The code you gave me adds a capability to a role. Is this going to work when I try to add the capability to a user?
Re: Custom Capabilities Question
Posted:
August 3rd, 2011, 1:32 pm
by fcp2011
Ok, this does not work. It gives me a fatal error; something to do with a non object. Any other ideas?
Re: Custom Capabilities Question
Posted:
August 3rd, 2011, 6:37 pm
by fcp2011
Ok tried your code and got this following error:
$user_id->add_cap ("access_s2member_ccap_test");
Fatal error: Call to a member function add_cap() on a non-object in /home3/freecla3/public_html/wp-content/themes/Superb/functions.php on line 502
Re: Custom Capabilities Question
Posted:
August 3rd, 2011, 11:34 pm
by fcp2011
Bump. Sorry but really need to get this solved.
Re: Custom Capabilities Question
Posted:
August 3rd, 2011, 11:56 pm
by Cristián Lávaque
I imagine $user_id is an integer, not an object, which is why you're getting that error. Read my example above and notice the line before the one where the cap is added.
viewtopic.php?f=4&t=14172#p28963Does that help?
Re: Custom Capabilities Question
Posted:
August 4th, 2011, 11:30 am
by fcp2011
so am i supposed to use the user id (number) or the user's username? The problem is when I run this code, the user is not logged in yet, so I have to capture the info from the register form.
Re: Custom Capabilities Question
Posted:
August 4th, 2011, 5:02 pm
by fcp2011
very much. I finally got it. Thanks. Here is the solution I used:
- Code: Select all
add_action("gform_user_registered", "add_custom_user_meta", 10, 3);
function add_custom_user_meta($user_id, $config, $entry) {
wp_set_current_user( $user_id );
$user = wp_get_current_user();
$user->add_cap("access_s2member_ccap_music");
}
i know the set current user fuction returns the WP_user object, I just don't know how to access the return value.