Purely Genius Way to Add Custom Profile Fields
-
Everyone has been asking about how to add custom fields for profiles. I too have wanted to do some customization to the profile, but without having to modify the core or profile source. Here is what I did to make a wicked simple mp3 player for the site I’m working on.
Step 1, Create a group, and a few sub fields for that group. For this example it was “Audio Details”, then I created a sub field “favorite Band of All time” and “Favorite Album of All Time”.
Step 2. Write some code, I created a simple filter, based on a post by Andy, http://buddypress.org/forums/topic.php?id=584#post-2599 which replaced the output of the profile field with that of the mp3 widget.
Step 3. Because I didn’t want it to replace every profile field, and this is the magic, I wrote a 2nd filter, which looks at the group name, and turns on and off filtering, for different purposes. Since I didn’t want url linking filtering adding to the field value, I turned that off, and turned on my mp3 widget filter. The next time the group runs, it turns back on the default filters and removes my mp3 filters.
Step 4. Enjoy
http://gorgeousgamers.com/beta/members/bradmkjr/
If you have any question, feel free to ask. Also for those who may want some custom version for their own site, I’m willing to release the code as beerware.
Thanks,
Brad
-
This is a good solution (or hack) for when this has to be in the profile page. I can easily see this expanding into it’s own page for bigger sites. And I forgot about the filter hint from Andy. Good job.
Filters are very useful, I’ve tried to include filters on every template tag, so you can modify template tag output as you see fit.
when are you going to release it and also can you apply it for youtube media ?
*bump*
It would be helpful to see your code, Brad. Are you willing to share?
Here it is, save as bp-music.php and copy into your muplugins
you must create a profile details group “Audio Details”, and all values will be replaced by a music player.
Check out a working copy on:
http://gorgeousgamers.com/beta/members/bradmkjr/
Brad
http://gorgeousgamers.com/beta/
<?php
/*
* Created on Dec 29, 2008
*
* Project Buddypress Addons
*
* File bp-music.php
*
*/
function bp_profile_music_player( $field_value =””, $field_type = “”, $field_id = “” ) {
if($field_value == “”)
return “Nothing to show”;
else
{ // clean up input
return “<script type=’text/javascript’>
var amzn_wdgt={widget:’MP3Clips’};
amzn_wdgt.tag=’gorgeousgamers-20′;
amzn_wdgt.widgetType=’ASINList’;
amzn_wdgt.keywords='”.addslashes($field_value).”‘;
amzn_wdgt.title=’What I’ve been listening to lately…’;
amzn_wdgt.width=’250′;
amzn_wdgt.height=’250′;
amzn_wdgt.shuffleTracks=’True’;
amzn_wdgt.marketPlace=’US’;
</script>
<script type=’text/javascript’ src=’http://wms.assoc-amazon.com/20070822/US/js/swfobject_1_5.js’>
</script>”;
}
}
function bp_profile_music_groups( $group_name =””) {
if($group_name == “Audio Details”){
remove_filter( ‘bp_the_profile_field_value’, ‘xprofile_filter_link_profile_data’, 2);
add_filter( ‘bp_the_profile_field_value’, ‘bp_profile_music_player’, 2, 3);
}else{
add_filter( ‘bp_the_profile_field_value’, ‘xprofile_filter_link_profile_data’, 2, 3);
remove_filter( ‘bp_the_profile_field_value’, ‘bp_profile_music_player’, 2);
}
return $group_name;
}
add_filter( ‘bp_the_profile_group_name’, ‘bp_profile_music_groups’, 10, 1 );
?>
one more hint plz…. can you give an example of what would be entered into the profile field…. does it have to be a music file?
so, http://mywebsite.com/mysong.mp3 ?
I’m confused as to where the audio file is located/uploaded/pulled from….
does the user upload a file? or simpley enter a link to an audio file? or enter artist names/song name and it’s pulled from amazon?
(thanks)
it pulls from your text a keyword and gets the player from amazon
The magic line is this:
amzn_wdgt.keywords='”.addslashes($field_value).”‘;
I have started working on other versions, which could show netflix queue, hulu queue, or youtube streams. They all revolve around similar ideas.
This method has sort of been replaced by custom boxes, but due to the profile loop showing all fields, there is no easy way to get the users “favorite song, artist, band”, without it also displaying inside of the loop
quick question:
I uploaded the BP-music.php file to the mu-plugins folder
and the styles/css for the entire site went crazy
…almost like the “remove filter” removed everything from everything…
I had not yet created a group called “Audio Details” when i uploaded the file…
is that why it didn’t work?
It did the same thing to me.I fixed that by deleting bp-music.php and puting the code directly in bp-xprofile-filters.php.I don’t know if it’s a good issue but it’s currently working, thanks Fishbowl81.
I’ve also adapted the code to display user’s ebay listings: http://lesitedelasneaker.com/bp/users/members/admin/profile
(Sorry for my english)
@keston, I like your ebay plugin. Can you share it?
@keston, I like your ebay plugin. Can you share it?
I’ll try to set a little plugin or something later, but for the moment you can follow this method, it’s the Fishbowl81’s code adapted for ebay editor kit:
Edit your bp-xprofile-filters.php by placing the following code after the custom buddypress filters:
/* Display ebay listings field */
function bp_profile_ebay_display( $field_value "", $field_type = "", $field_id = "" ) {
{ // clean up input
return "<script language='JavaScript' src='http://lapi.ebay.com/ws/eBayISAPI.dll?EKServer&ai=lwa%7Bfwvw%7Esa%7Cwsyw%60&bdrcolor=CCCCCC&cid=0&eksize=1&encode=UTF-8&endcolor=FF0000&endtime=n&fbgcolor=FFFFFF&fntcolor=000000&fs=0&hdrcolor=FFFFFF&hdrimage=1&hdrsrch=n&img=y&lnkcolor=75179C&logo=3&num=5&numbid=n&paypal=n&popup=n&prvd=9&r0=4&shipcost=n&si=".addslashes($field_value)."&sid=BP&siteid=0&sort=MetaEndSort&sortby=endtime&sortdir=asc&srchdesc=n&tbgcolor=FFFFFF&tlecolor=FFFFFF&tlefs=0&tlfcolor=000000&toolid=10004&track=5336248810&watchcat=63850&width=350'></script>";
}
}
function bp_profile_ebay_groups( $group_name "") {
if($group_name == "My Ebay listings"){
remove_filter( 'bp_the_profile_field_value', 'xprofile_filter_link_profile_data', 2);
add_filter( 'bp_the_profile_field_value', 'bp_profile_ebay_display', 2, 3);
}else{
add_filter( 'bp_the_profile_field_value', 'xprofile_filter_link_profile_data', 2, 3);
remove_filter( 'bp_the_profile_field_value', 'bp_profile_ebay_display', 2);
}
return $group_name;
}
add_filter( 'bp_the_profile_group_name', 'bp_profile_ebay_groups', 10, 1 );
Also it depend of your css code but it can be useful to put this in your member theme’s stylesheet (base or your custom stylesheet).
td.data table td{
margin:0px;padding:0px;
Then create a profile field group named “My Ebay listings” and a profile field like ebay username and you’re done!
thank you
Thanks for the effort…please create a plugin for it. Also is it a ebay widget,so if can one get lastFM widget?
Hello, Im pretty new to php and i pasted the custom profile code into my bp-xprofile-filters.php file, and it killed my site, i just get the error: Parse error: syntax error, unexpected ‘”‘, expecting ‘)’ in /home/richied/plainprofile.com/wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-filters.php on line 158
i tried deleting and re-installing buddypress but im still getting it! site url is: plainprofile.com
Any help would be HUGELY appreciated!!!!
It’s a syntax error so you need to examine the line it’s referring to and check and correct the syntax php met an unexpected double quote mark and seems to be suggesting there ought to have been an ) closing parentheses. this is an extremely old post you have dragged up and I would expect this plugin/code to necessarily work given the version updates to BP since this was written.
btw editing core files in this manner is not advised really, if it’s a filter it ought to be written to a functions.php file living in a child theme
- The topic ‘Purely Genius Way to Add Custom Profile Fields’ is closed to new replies.