Updated version (0.2) of Custom Profile Filters for BuddyPress

I’m releasing a new version of my Custom Profile Filters for BuddyPress plugin. The initial version, described here, gave BuddyPress users more control over which terms in their profiles become linked to a community-wide profile search. The new version gives BP administrators the ability to tweak these links even more. Here’s what’s new:

  1. Some profile information – phone numbers, IM handles, and so on – is unique to the individual user. Thus there’s no real need to have this information linked to a community-wide search. Using this plugin, administrators can specify certain profile fields that will remain non-linked. By default, profile fields called Skype ID, Phone, and IM will not be processed as links, but you can tweak this to be whichever fields you want. See readme.txt and custom-profile-filters-for-buddypress.php for more information.
  2. Other fields, especially those social networking sites where each user’s handle is attached to a profile page, can be more usefully linked to those user profiles than to a search of the community. For example, it makes more sense for the contents of the Twitter field to link to an individual’s Twitter page rather than to other users in the community who have the same Twitter handle (hopefully no one!). With this plugin, administrators can specify that certain fields will turn the user’s social networking ID into a profile link. By default, the plugin recognizes fields called Twitter, Delicious ID, YouTube ID, Flickr ID, and FriendFeed ID. See custom-profile-filters-for-buddypress.php for more information and to change these settings.

I also added a little bit of code to make sure that BuddyPress can recognize email addresses with periods before the @-sign.

You can see some of these things at work in my profile here on the CUNY Academic Commons: https://commons.gc.cuny.edu/members/boonebgorges. You’ll notice that the Twitter field shows a link to my Twitter profile, even though I just entered my handle in the Edit Profile screen.

Grab the latest version from the trunk http://svn.wp-plugins.org/custom-profile-filters-for-buddypress/ or download it here: custom-profile-filters-for-buddypress-v02.zip

52 thoughts on “Updated version (0.2) of Custom Profile Filters for BuddyPress”

  1. Hi Boone,

    I have a question about your filter.

    Let’s say I use a custom variable to get one variable.
    $bio = xprofile_get_field_data( ‘Bio’, bp_get_the_site_member_user_id() );

    How can I make sure your filter is triggered so I can utilize the square bracket linking?

  2. Hi Ray,

    It depends on when you define $bio.

    Here’s the way things normally work. The profile-loop template calls bp_the_profile_field_value for each field in xprofile, which then calls bp_get_the_profile_field_value. These custom profile filters are hooked to bp_get_the_profile_field_value. So if you’re isolating information from the bio after bp_get_the_profile_field_value has been run (i.e. if $bio gets defined in the page template), then the filter should already have run on it.

    If, on the other hand, $bio gets pulled earlier in the process (like in a separate plugin, or if you’ve hacked the core) then you’ll have to apply the filter manually. As it’s written, you can’t just run the bracket filter on a single string (it runs as a loop on every profile field). But you could try one of two things: 1) you could rework the bracket filter (lines 60-68, more or less) into their own function, which can then be called both in its current location as well as in your code (eg $bio = bp_add_links_to_bracketed_text($bio)), or 2) you could reproduce all of the filter code immediately after you define $bio (taking 60-68, pasting it into your code, changing the first “elseif” to “if”, and changing all instances of $field_value to $bio).

    Good luck!

  3. Thanks for that explanation, Boone.
    That was helpful.

    I think I’ll try method #1 first and we’ll go from there!

    One follow up question, I noticed that the $social_networking_fields in your plugin have a nofollow link (which is good!).

    I couldn’t find “nofollow” in your plugin, so i’m guessing another hook or filter in WordPress is handling the $social_networking_fields? Okay, just looked into it a bit… seems like it’s the make_clickable() function in WordPress.

    What’s the easiest way I could add the target attribute so those links open in a new window?

  4. Hi Ray,

    My best suggestion is to copy the make_clickable() function (out of /wp-includes/formatting.php), copy it into this plugin (or some other plugin, if you’d prefer), and rename it – maybe something like make_clickable_target_new(). Make the necessary change to the function – it’s pretty easy to see where, in the last line of the function, you can add target=”_blank” or whatever. Then change line 94 in the custom profile filter plugin to reader $new_values[] = make_clickable_target_new( $value );.

    This is probably the best way to do it, since (a) you can avoid hacking the core, and (b) it will only apply to URLs in BP, not all over your WPMU installation.

  5. Hey Boone,

    Sorry to bother you again.
    I copied the make_clickable() function as well as the _make_url_clickable_cb() function over to your plugin, and have made the necessary changes.

    However, for some reason, the $new_values[] array isn’t taking to the new function.

    I even called $new_values[] = fhdhlkfjahsldkhflkdhs($value);
    Just to see if an error would throw… but nothing happened.

    Any idea why?

  6. Hi Ray,

    I’m not exactly sure why you’re having a hard time getting $new_values to take new members. But I did manage to get the target=blank bit working, albeit with a bit of messing around. Check out this file: http://dev.commons.gc.cuny.edu/files/2009/07/bp-profile-custom-filtersphp.zip. Here’s what to look for:
    1) Like you, I copied over make_clickable() as well as _make_url_clickable_cb().
    2) Added the target=blank info to _make_url_clickable_cb, changed the names of the two functions, and changed the call in make_clickable_custom to point to _make_url_clickable_cb_custom()
    3) Changing the make_clickable() that already exists in the plugin (line 124 in this version) to make_clickable_custom() catches the external links OTHER THAN the ones in the social networking fields (i.e. it gets the blog link). This tells me that I messed something up in the logic of the plugin. I’ll fix it in a future version – thanks for bringing it to my attention. In the meantime, you can make the target=blank apply to social networking fields as well by adding the line $field_value = make_clickable_custom( $field_value ); to the social networking block, as I have at line 79.

    I’ll add fixing this quirk to my to-do list. Thanks, Ray!

  7. Ahh okay. So it wasn’t entirely my fault 😉

    Step 3 was what drove me mad!

    Thanks for posting that code, Boone.
    That worked perfectly.

    Glad I could help debug your plugin!

  8. I’m creating a sports networking site and would like it when a user selects their favorite teams, instead of showing a list of all members who also like a particular team, it instead links to a static page I have created specifically with information on the team?

  9. Hi DW –

    This shouldn’t be too difficult. There’ll be a couple steps. (This is a rough and untested outline, but if you know a bit of PHP it shouldn’t be too much trouble to implement)
    – First, set up an array (or multiple arrays) associating team names (to be identified in the profiles) with the URLs of the static pages. If you’re going to rely on users to type in team names themselves, you’ll want to allow for multiple permutations of a given team. For instance:
    $teamarray = Array(
    ["Chicago Bears"] => 'http://mysite.com/bears';
    ["Bears"] => 'http://mysite.com/bears';
    ["Chicago"] => 'http://mysite.com/bears';
    ["Green Bay"] => 'http://mysite.com/packers';
    )

    and so on. Do this before the line while ( strpos( $field_value, ']') ) {
    – Next, break up the action in the while loop so that the text between square brackets gets put into its own variable, such as $linktext (it’s not set up that way right now)
    – Then do something like this
    if ( array_key_exists( $teamarray, $linktext ) )
    $field_value = substr($field_value, 0, $open_delin_pos) . '<a href="' . $teamarray[$linktext] . substr($field_value, $open_delin_pos+1, $close_delin_pos - $open_delin_pos - 1) . '" rel="nofollow">' . substr($field_value, $open_delin_pos+1, $close_delin_pos - $open_delin_pos - 1) . '</a>' . substr($field_value, $close_delin_pos+1);

    Again, I haven’t tested this, but it should work with some minimal tweakage. Good luck.

  10. uhmm.what do i do when i try to change my layout but my customize profile is all blank;; nothing is there?

  11. Hi Aly,

    What do you mean by “change your layout”? Do you mean that you’re changing your theme? And exactly what is “all blank”: the edit profile page, the profile page, the fields on the profile page?

  12. Hi Boone,

    First of all, thanks for the wonderful plugin. Love it very much.

    Question: Is it possible to hide the full URL-output? For example: If you fill in your twitter username the profile only shows your username and not the full URL. Especially with longer URL’s it makes my profile page look bad.

    Thanks in advance.

  13. Hi Boone,

    Another question: in Holland we use a social network site called Hyves with an URL like http://username.hyves.nl (username before site-URL). Is it possible to automate that link too? That users only have to fill in their username?

    I look forward to see your reply.

  14. Hi Boone,
    I may have missed the boat here, but how can I make a link from a standard url.
    I tried [http://www.mysite.com] inside a text field but it still took me to the members search.
    Hope you can help
    Cheers
    Paul

  15. Hi Paul,

    The URL all by itself should work: http://www.mysite.com. No brackets. It’s possible that URL detection will break if you’re using brackets elsewhere in the field, however (I can’t remember off the top of my head). Thus, if you just enter http://www.mysite.com it should link; if you enter “My website is http://www.mysite.com” it should link; but if you enter “My [website] is http://www.mysite.com“, only the word “website” will link.

    Let me know if you’re able to get it working.

    Boone

  16. Thanks Boone.
    Yes, full url does work. duh! It didn’t without your plugin, so I went straight into test the [square brackets] without trying the full url…

    FWIW, in the meantime I found an alternative fix as well:

    in the $social_networking_fields = array
    ‘Website URL’ =>’www.’ ,
    It works as long as the instructions clear in the field description about how to format the url. i.e. with [mydomain.com] and no http:// or www.

    I think the full url is better!

    Thanks for your help and a cool little plugin that opens up the profile field options in a very easy to manage way.

    Paul

  17. just wanted to stop by and thank you for the plugin,
    it is really amazing and a time safer,

    thanks for sharing it with the bp and mu community!

  18. I wasn’t able to get this to work, and it’s a shame since it’s exactly what I was looking for (I want rid of ALL links in profiles)

    Am I right in thinking after enabling the plugin, you can’t edit anything via the admin panel? You need to edit the php file in Dreamweaver?

    I never saw anything back-end, so edited the file, and here’s what I done:

    $no_link_fields = array( // Enter the field ID of any field that you want to appear as plain, non-clickable text. Don’t forget to separate with commas.

        ‘Gender ‘     ,
        ‘Phone’     ,
        ‘IM’       
       
        );

     

    However after uploading the file again, there was no changes on the ‘Gener’ section on user profiles.

    I’m using 1.1.3/ 2.8.6

    Any help would be great, otherwise I guess I’ll just need to put up with the links 🙂

  19. tom – I’m not sure why it’s not working. Is it possible that the field names should have trailing spaces? (eg ‘Gender ‘ instead of ‘Gender’)

    You’re correct that there is currently no administrative panel. All configuration must be done in the PHP file. At some point I’ll add Dashboard options for changing the settings, but I’m kind of waiting for the backend of BuddyPress to be rebuilt somewhat to make it easier.

    If you want to turn off linking in ALL fields, then there might be a better way than my plugin. See this thread: http://buddypress.org/forums/topic/remove-automatic-links-in-profile#post-32749 See my message about the remove_filter code? That’s what you need. 

  20. Sorry not sure what you mean with trailing spaces, but just looked at your other link, and tried adding:

    remove_filter( 'bp_get_the_profile_field_value',
    'xprofile_filter_link_profile_data', 2 );

    to bp-custom.php but it’s not removed any linking fields. Do I need to chance the number 2, and add the ID of each profile field I wish to remove the link from? If so- How do I find the ID in number form? I can’t see those anywhere.

  21. Hi Tom. The 2 at the end of the remove_filter code is the priority argument. It shouldn’t have anything to do with the field ids.

    Try the following code in bp-custom.php:

    <?php

    function remove_xprofile_links() {
    remove_filter( ‘bp_get_the_profile_field_value‘, ‘xprofile_filter_link_profile_data’, 2, 2 );
    }
    add_action( ‘plugins_loaded’, ‘remove_xprofile_links’ );
    ?>

  22. Aha.. got it. I think maybe what you posted displayed incorrectly due to not wrapping the code in tags (Hopefully this will post correctly):

    function remove_xprofile_links() {
    remove_filter(“bp_get_the_profile_field_value”,”xprofile_filter_link_profile_data”, 2 );
    }
    add_action( “plugins_loaded”, “remove_xprofile_links” );

    ..Of course.. post it inside php tags. All working fine & dandy now thank you very much for your help 🙂

  23. Hi James. Sure, you can make any profile field non-linked by adding its name to $no_link_fields around line 14. Users can remove links from a given profile field by adding some brackets: eg “[]Intel Q6700”.

    I see you’re using BP 1.2 – and I can’t guarantee that the plugin will work perfectly for 1.2 just yet. I’ll be updating within the next week.

  24. Yeah I’ve listed the custom profile fields already and it removes the underline but keeps the link active. Might be a bug with 1.2 possibly?

  25. Right, the [] works but just entering the custom field name into $no_link_fields doesn’t work, it keeps the link active. Hope this helps you with your update :o)

  26. Oops, doesn’t seem to work with a standard WP install. I uploaded and activated it and there’s no options page.

  27. Sorry Boone, didn’t read the instructions right (changing the parameters in the PHP file) and got it working.

    Thanks,
    Gene

  28. Boone,
    Thanks for this is a great help, but just to let you know, I too could not get the plugin working (version 0.3.1 downloaded from WP).
    I’m using BP1.1.2 WPMU2.8.6
    I clicked on your download link for version 02.zip above which incorporates the functions and plugin in one file and it worked fine.

    Thanks

    Robin

  29. Hi Robin,

    If you’re running version BP 1.1.x, you’ll have to make a modification to the plugin in order for it to load. In the main plugin file (custom-profile-filters-for-buddypress.php) looks for the lines that look like this:

    function custom_profile_filters_for_buddypress_init() {
    require( dirname( __FILE__ ) . '/custom-profile-filters-for-buddypress-bp-functions.php' );
    }
    add_action( 'bp_init', 'custom_profile_filters_for_buddypress_init' );

    Remove the first, third and fourth lines, so that only this remains:

    require( dirname( __FILE__ ) . '/custom-profile-filters-for-buddypress-bp-functions.php' );

    That should do the trick.

  30. Boone, thanks for that.
    Now I have it working I don’t like to touch stuff, and I know that when I finally upgrade from 1.1.2 to 1.2 its going to be real work with a lot of my plugins.
    The developers on Buddypress are just awesome, perhaps too awesome as its difficult to keep up…never mind good problem to have. Keep up the good work and thanks again for the quick response.

  31. Hi Boone, thanks for this great plugin. I’ve used it to filter an URL-link to an image and convert it to a img src tag so the image is displayed on the public profile. Awesome.

    I am trying to figure out how to in the best way allow the user to upload an image to my server (a logo) in the ‘edit profile’. Could your plugin be used on the edit-side as well you think? So I can display a form where the can upload the image. Or display a button with link to the Media function on my blog. (If I let them use it)

  32. Hi Oyvind – Glad it’s helpful to you!

    I don’t think this plugin has what you need to do what you’re looking to do. I take it that you’d like to have logos *in addition to* avatars (if logos are to take the place of avatars, wouldn’t you just change the word ‘avatar’ to ‘logo’?) I haven’t heard of anyone adding file uploads to the profile page, but I assume it could be done: try hooking a custom field to bp_custom_profile_edit_fields to create the upload field, and then grabbing the $_FILES global when xprofile_screen_edit_profile is called and saving the file somewhere. (You’ll also have to make sure that an enctype is given to the form tag on the profile edit page.) You might have a look at http://wordpress.org/extend/plugins/forum-attachments-for-buddypress/ to see the kinds of mechanism required to save files in a BP plugin.

    (I wish there was an easier answer – that BP or even WP had a ready-made API for uploading files. Sadly, that’s not yet the case!)

    You could also create a link to the Media function on your blog, as you suggest, but there are a few hurdles: 1) You’ll want to use a custom role plugin (like http://wordpress.org/extend/plugins/members/) that allows you to give upload_file rights to Subscribers; 2) When files are uploaded through the WP Add Media panel, they are named/sorted by date and not type, which means that users would have to copy and paste the URL into a custom field that you create on the profile pages. At that point, you could use my plugin in order to show images rather than links whenever it encounters a profile field called “Logo”.

    Sorry for the longwindedness – good luck!

  33. Hey boone! kickass plugin! =)
    Im googling around for youtube video embeds in custom profile fields and it brought me here!
    its so annoying, i have Youtube embeds working on activity stream just from normal yt links, but whatever i try for profile fields fail.
    Do you know a way of doing this with your plugin?

  34. I have tried to use the buddypress adminbar (of my buddypress page) outside the BP/WP in a normal php/html page. it seems that it loads the bar but it don´t show up. Just wanted to ask if this is possible?

  35. I think this plugin is just what I need. I have 2 sites, and one needs the member profile to have a link to the second sites member profile. I plan to put an extra field in the first sites user profile (using xProfiles ACL), asking for the user name of the second site. Clicking on this, will then take the viewer to the the profile on the second site (don’t ask why, it’s complicated!) Not knowing much PHP, how would I do this? Thanks in advance.

  36. Dean – If the new fields you created are WP profile fields (the kind you fill out on your Dashboard profile) as opposed to BP xprofile fields (the kind you fill out from Edit Profile on the front end) then I’m afraid this plugin won’t help you much.

    If you are indeed using a BP field for this purpose, you can use the plugin as a kind of template for what you want to do. Essentially, you will take the function cpfb_add_social_networking_links() and rewrite it so that it checks to see whether $bp_this_field_name matches the name of your added profile field, and if so, then rewrite the content of the profile field to be a link.

    Good luck!

  37. Hi Boone, this is a great Plugin. I have a directory site in the UK with various counties on the homepage. Is there any way of adapting the code from Custom Profile Filters to pickup words on the homepage? That way when someone clicks London they will be directed London profiles.

    Any help is appreciated.

    Andy

  38. HI, I deactivated the plugin but the links stayed. Is there a way to remove those links now?

  39. Hi Boone – Another happy chappy user here 🙂 I have removed all the links I want by coding ‘custom-profile-filters-for-buddypress.php’

    However, can you suggest a way to make the email address ‘clickable” as a mailto link? (eg, name@domain.com is clickable – but does not go to the members’ directory, it creates a new email message using the mailto protocol)

    (Maybe it’s not possible? Your profile still links your email to your members’ directory…)

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image