Meta tags:
description= ;
keywords= wordpress buddypress bbpress community support forums;
Headings (most frequently used words):
the, buddypress, user, id, functions, to, codex, playing, with, in, different, contexts, steps, explore, two, main, get, discover, other, great, when, extending, some, loops, additional, resources, contents, article, contributors, want, help,
Text of the page (most frequently used words):
the (93), you (33), user (31), buddypress (19), profile (16), functions (14), #function (14), loop (13), members (12), update (12), bp_displayed_user_id (12), this (12), bp_plugin_filter_latest_update (11), two (10), displayed (10), span (10), that (10), org (9), with (9), logged (8), developer (8), can (8), and (8), strong (8), are (8), about (7), codex (7), when (7), return (7), add_filter (7), also (6), get (6), check (6), user_id (6), color (6), using (6), wordpress (5), see (5), other (5), some (5), main (5), playing (5), different (5), friends (5), bp_get_member_user_id (5), style (5), your (5), member (5), result (5), will (5), page (5), blog (4), support (4), documentation (4), resources (4), contexts (4), activity (4), good (4), has (4), bp_is_user (4), bp_get_activity_latest_update (4), need (4), code (4), one (4), template (4), bp_loggedin_user_id (4), there (4), log (3), trac (3), feedback (3), forums (3), bbpress (3), means (3), mathieu (3), discover (3), great (3), loops (3), explore (3), group (3), their (3), specific (3), bp_get_member_latest_update (3), same (3), his (3), case (3), red (3), header (3), simply (3), here (3), first (3), tag (3), filter (3), capture (3), use (3), information (3), plugin (3), register (2), not (2), anonymous (2), skip (2), which (2), our (2), ago (2), years (2), additional (2), extending (2), steps (2), wp_get_current_user (2), again (2), tab (2), each (2), else (2), get_member_user (2), imath (2), actually (2), visiting (2), displaying (2), checking (2), why (2), empty (2), edit (2), screen (2), step (2), saw (2), orange (2), let (2), inside (2), display (2), avoid (2), useful (2), add (2), for (2), friend (2), current (2), write (2), pages (2), been (2), set (2), thanks (2), scenarios (2), provides (2), these (2), users (2), web (2), toolbar, terms, service, privacy, contact, gpl, follow, twitter, rss, matt, volunteer, powered, contribute, too, interested, updating, existing, articles, creating, entirely, new, ones, please, read, standards, guidelines, want, help, updated, published, michael, beckwith, viet, mercime, article, contributors, contents, bp_get_group_member_id, bp_get_activity_user_id, offer, context, now, another, areas, bravo, green, moi, have, only, although, adapt, particular, before, surely, wonder, changed, seems, solve, issue, understand, activate, navigation, what, while, works, fine, call, rescue, component, second, discovered, earlier, way, take, few, seconds, three, parts, was, best, straight, point, previous, adding, doing, thing, than, except, runs, bp_member_latest_update, goal, shown, should, definitively, having, interaction, instance, functionality, extension, logged_in, begin, example, illustrate, latest, posted, like, most, tags, returned, value, eventually, extend, print, ids, php, active, theme, bp_activity_latest_update, equal, equality, inform, bp_is_my_profile, requested, know, informing, reached, bp_core_set_uri_globals, class, bp_core, additionnal, whose, thankfully, interesting, then, cases, must, handle, caution, fortunately, unwanted, behaviors, core, taking, care, very, chance, got, play, finest, element, identifying, home, download, news, involved, bottom, top, search, categories, content, wayback, machine, http, archive, 20221210085842, https, timestamps, fail, success, 2023, 2022, 2021, jan, dec, nov, sep, 2014, may, 2026, captures,
Text of the page (random words):
playing with the user s id in different contexts buddypress codex 34 captures 13 sep 2014 20 may 2026 nov dec jan 10 2021 2022 2023 success fail about this capture timestamps the wayback machine http web archive org web 20221210085842 https codex buddypress org developer playing with the users id in different contexts skip to content pages categories search top bottom about documentation get involved news support download buddypress codex codex home developer resources playing with the user s id in different contexts playing with the user s id in different contexts buddypress core is first taking care of the members as a result when you write a buddypress plugin there is a very good chance that you ve got to play with the finest element identifying the users their id there are two scenarios the logged in user and the user whose profile is displayed thankfully buddypress provides you with two interesting functions to get the user id for these scenarios then there are other specific cases in which you must handle these two main functions with caution fortunately again buddypress provides other functions to avoid some unwanted behaviors steps explore the two main functions to get the user s id discover other useful functions when playing inside some buddypress loops additionnal resources explore the two main functions to get the user s id the function bp_loggedin_user_id will return you the current logged in user id that has been set thanks to the bp_core class using the wordpress function wp_get_current_user the function bp_displayed_user_id will return the id of the displayed user that has been set thanks to the bp_core_set_uri_globals function when a profile page is requested this also means that you can simply know if you are on a profile page by checking if the bp_displayed_user_id function is not empty the function bp_is_user informing you that you ve reached a profile page is actually using this check when the two are equal it means that the logged in user is visiting one of his profile pages the buddypress function bp_is_my_profile is using this equality to inform you if that s the case let s begin an example to illustrate the use of the two functions in the member s header there s a template tag buddypress is using to display the latest activity the displayed user posted bp_activity_latest_update like most of buddypress template tags you can filter the returned value to eventually extend it in your plugin here you will simply print user ids in the functions php of your active theme or in your plugin you can write function bp_plugin_filter_latest_update update update strong span style color red logged_in bp_loggedin_user_id span span style color orange displayed bp_displayed_user_id span strong return update add_filter bp_get_activity_latest_update bp_plugin_filter_latest_update 10 1 here s a screen capture of the result of this great extension bp_loggedin_user_id vs bp_displayed_user_id as you can see if your goal is to display information about the user displayed as shown in this case you should definitively use bp_displayed_user_id to avoid having the information of the logged in user on each profile you can also see that imath is the logged in user as the two functions return the same result in a user s profile the bp_loggedin_user_id will be useful to add some interaction with the user displayed for instance the add friend functionality is using the logged in user id to check if the current user is friend with the displayed user discover other great functions when extending some buddypress loops to go straight to the point let s edit our previous code by adding a filter to the bp_member_latest_update template tag this function is doing the same thing than the one you saw in first step except that it runs inside the members loop function bp_plugin_filter_latest_update update in step 1 you saw that bp_displayed_user_id was the best function to use when displaying information about the user in his profile page update strong span style color orange displayed bp_displayed_user_id span strong return update add_filter bp_get_activity_latest_update bp_plugin_filter_latest_update 10 1 add_filter bp_get_member_latest_update bp_plugin_filter_latest_update 10 1 take a few seconds to check the result of this code in the three parts of this screen capture bp_displayed_user_id and the members loop as you can see while bp_displayed_user_id works fine in the member s header it is empty in the members loop so we need to call two functions to the rescue the first one is a template tag specific to the member component bp_get_member_user_id and the second one is the function you discovered earlier to check you are on a user s profile page bp_is_user so you need to edit the filter this way function bp_plugin_filter_latest_update update if bp_is_user user_id displayed bp_displayed_user_id else user_id get_member_user bp_get_member_user_id update strong span style color red user_id span strong return update add_filter bp_get_activity_latest_update bp_plugin_filter_latest_update 10 1 add_filter bp_get_member_latest_update bp_plugin_filter_latest_update 10 1 if you check the result of this code you will surely wonder why i ve changed the color of the id to red as it seems to solve the issue in the members loop and in the member s header to understand why you simply need to activate the friends navigation of the user s profile and here s what you ll see members loop in member s profile friends mathieu imath and moi have the same id actually only mathieu has the good id as you are visiting his profile in the friends tab although you are on a user s profile you also are in a members loop displaying user s friends so you need to adapt your code to this particular case by also checking the bp_get_member_user_id before using bp_displayed_user_id function bp_plugin_filter_latest_update update if bp_is_user bp_get_member_user_id user_id displayed bp_displayed_user_id else user_id get_member_user bp_get_member_user_id update strong span style color green user_id span strong return update add_filter bp_get_activity_latest_update bp_plugin_filter_latest_update 10 1 add_filter bp_get_member_latest_update bp_plugin_filter_latest_update 10 1 now you can check again the logged in user s profile another profile the friends tab of a user s profile and the main members loop each user has the good id in the different areas bravo the activity and the group members loop also offer their specific functions to get the good user id in their context activity loop bp_get_activity_user_id group members loop bp_get_group_member_id additional resources wp_get_current_user in wordpress codex the members loop the group members loop the activity loop contents steps explore the two main functions to get the user s id discover other great functions when extending some buddypress loops additional resources log in register article contributors 4 mercime 4 mathieu viet 1 michael beckwith updated 6 years ago published 9 years ago want to help the buddypress codex is volunteer powered which means you can contribute too if you re interested in updating existing articles or creating entirely new ones please read our codex standards guidelines see also wordpress org bbpress org buddypress org matt blog rss follow buddypress on twitter gpl contact us privacy terms of service skip to toolbar wordpress org about wordpress documentation support forums feedback developer trac developer blog bbpress org about bbpress documentation support forums feedback developer trac developer blog buddypress org about buddypress documentation support forums feedback developer trac developer blog buddypress org log in anonymous anonymous not logged in register log in
|