Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
Add s2member custom profile field to SP profile
Avatar
Thorsten B
Member
Offline
Aug 20, 2013 - 12:45 pm

We're using s2member on our eclass site for which I created a single custom profile field called 'Blog URL' in addition to the standard WP website field (user_url). Would it be possible to pull this field on to the SP profile so that students could edit it from there as well? It's a matter of keeping things in sync across their s2 member profile and SP profile.

Avatar
Yellow Swordfish
Glinton, England
SP Master
Offline
Aug 20, 2013 - 1:19 pm

Do you know where s2member stores this data? If it sticks rigidly to the WP API then it should store it in the usermeta table. And if it does that - and you do really need to check - then use our Custom profile fields plugin to create the SAME field and make sure the name is identical. Actually t is not the name it is the slug - make sure that you name it using the slug that s2member created.

If this woks then your data will be pulled into SP although you will have to add the field to the profile form if you want iti there. which is covered in the codex article for the custom fields plugin.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Thorsten B
Member
Offline
Aug 20, 2013 - 2:40 pm

Thanks so much for the quick response. I had a look at the backend. While s2mmeber does store it's custom fields in usermeta it does so as an array, unfortunately. It's meta_key value is simply wp_s2member_custom_fields and then an array of all custom fields stored in meta_value. I think this option is not going to work.

Avatar
Yellow Swordfish
Glinton, England
SP Master
Offline
Aug 20, 2013 - 3:22 pm

What a horrible and very non-standard thing to do.
OK never fear - there is another way.
Do you know how to code WordPress filters? - I.e., Apply_filter and add_filter calls?

andy-signature.png
YELLOW
SWORDFISH
Avatar
Thorsten B
Member
Offline
Aug 20, 2013 - 4:18 pm

I am not too familiar with Wordpress filters (i.e. haven't used them) but I am sure I can figure things out with a few tips in the right direction.

Avatar
Yellow Swordfish
Glinton, England
SP Master
Offline
Aug 20, 2013 - 4:33 pm

OK - there are two parts to this and tonight I am just going to cover part 1 which is getting your sp2member data into the Simple:Press user object. I have not tried this but it should work...

Open up the spFunctions.php file of your Simple:Press theme (in the theme /templates folder) so you can make an edit. You can actually use the built in theme editor for this in the SP themes section of the admin.

At the bottom of the file - but before the closing php tag of course, copy and then paste in this code:

add_filter('sph_user_class_meta', 'add_my_field');
function add_my_field($list) {
    $list['wp_s2member_custom_fields'] = '';
    return $list;
}

first thing after you save this is to run a forum page to make sure you have got it all right!

Then next - go to the forum admin > Toolbox > Data Inspector and turn on the option to see 'spThisUser'. Next time you run a forum page you will see the SP user data object. You will be the only user to see it. Look down for the values of the custom fields to see if they have been included. They should be pretty near the top after the initial list of items.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Thorsten B
Member
Offline
Aug 20, 2013 - 4:57 pm

Thank you so much. So far so good, the s2member custom fields are included (I've added a second one in the meantime for additional testing):

[wp_s2member_custom_fields] => Array ( [blog_category] => Personal Blog [blogurl] => http://cognizantdreamer.com )<br /><br />
Avatar
Yellow Swordfish
Glinton, England
SP Master
Offline
Aug 20, 2013 - 5:29 pm

Well - in the same /templates folder you will find two profile templates - one for the popup profile view and another when the profile is used as a page. You will only be using one of them.

If you take a few minutes to just scan through it you will see all the fields that are displayed on the popup or page - in sequence. So the first thing is to decide where you want to display your custom data. And the try to echo it out like this:

echo $spProfileUser->wp_s2member_custom_fields['blogurl'];

Of course you will probably want to style it and maybe show it in two columns like the current display and we can do that. First thing is to make sure it is working.

 

andy-signature.png
YELLOW
SWORDFISH
Avatar
Thorsten B
Member
Offline
Aug 21, 2013 - 2:32 am

Added it to profile popup for testing - working perfectly well. Looking good so far.

Avatar
Yellow Swordfish
Glinton, England
SP Master
Offline
Aug 21, 2013 - 4:52 am

The awesome power of WordPress filters and the beauty of template driven displays. Now one last thing...

As always we recommend that you create your own SP theme so that any customisation is not lost during a future update. (http://codex.simple-press.com/.....g-a-theme/)

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 619
Members: 17361
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625