PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Custom Capabilities Question

s2Member Plugin. A Membership plugin for WordPress®.

Custom Capabilities Question

Postby fcp2011 » July 19th, 2011, 5:01 pm

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
User avatar
fcp2011
Experienced User
Experienced User
 
Posts: 72
Joined: March 30, 2011

Re: Custom Capabilities Question

Postby Cristián Lávaque » July 20th, 2011, 2:02 pm

I think s2Member custom capabilities are stored in a serialized array in wp_usermeta/wp_capabilities/.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Capabilities Question

Postby fcp2011 » July 20th, 2011, 5:24 pm

ok, so how do I add custom capabilities to existing members accounts?
User avatar
fcp2011
Experienced User
Experienced User
 
Posts: 72
Joined: March 30, 2011

Re: Custom Capabilities Question

Postby Cristián Lávaque » July 21st, 2011, 12:06 am

Go to their profile pages to add them manually. WP Admin -> Users -> Edit user -> s2Member Configuration & Profile Fields -> Custom Capabilities

If you have s2Member Pro, you can edit users in bulk and import them using the Export and Import tools. WP Admin -> s2Member -> Import/Export

I hope that helps. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Capabilities Question

Postby fcp2011 » July 21st, 2011, 8:57 pm

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
User avatar
fcp2011
Experienced User
Experienced User
 
Posts: 72
Joined: March 30, 2011

Re: Custom Capabilities Question

Postby Cristián Lávaque » July 21st, 2011, 10:30 pm

I double checked and they are stored in the usermeta table. Look for the rows that say wp_capabilities.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Capabilities Question

Postby fcp2011 » July 22nd, 2011, 3:13 pm

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.
User avatar
fcp2011
Experienced User
Experienced User
 
Posts: 72
Joined: March 30, 2011

Re: Custom Capabilities Question

Postby Cristián Lávaque » July 22nd, 2011, 10:56 pm

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_cap
https://codex.wordpress.org/Function_Re ... remove_cap

I hope that helps. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Capabilities Question

Postby fcp2011 » August 2nd, 2011, 7:16 pm

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?
User avatar
fcp2011
Experienced User
Experienced User
 
Posts: 72
Joined: March 30, 2011

Re: Custom Capabilities Question

Postby fcp2011 » August 3rd, 2011, 1:32 pm

Ok, this does not work. It gives me a fatal error; something to do with a non object. Any other ideas?
User avatar
fcp2011
Experienced User
Experienced User
 
Posts: 72
Joined: March 30, 2011

Re: Custom Capabilities Question

Postby fcp2011 » August 3rd, 2011, 6:37 pm

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
User avatar
fcp2011
Experienced User
Experienced User
 
Posts: 72
Joined: March 30, 2011

Re: Custom Capabilities Question

Postby fcp2011 » August 3rd, 2011, 11:34 pm

Bump. Sorry but really need to get this solved.
User avatar
fcp2011
Experienced User
Experienced User
 
Posts: 72
Joined: March 30, 2011

Re: Custom Capabilities Question

Postby Cristián Lávaque » August 3rd, 2011, 11:56 pm

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#p28963

Does that help?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Capabilities Question

Postby fcp2011 » August 4th, 2011, 11:30 am

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.
User avatar
fcp2011
Experienced User
Experienced User
 
Posts: 72
Joined: March 30, 2011

Re: Custom Capabilities Question

Postby fcp2011 » August 4th, 2011, 5:02 pm

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.
Last edited by Cristián Lávaque on August 5th, 2011, 12:53 am, edited 1 time in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
fcp2011
Experienced User
Experienced User
 
Posts: 72
Joined: March 30, 2011


Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 2 guests

cron