Add custom tab to profile page
-
This should be simple but haven’t been able to find info on how to do this.
I want to add a custom tab/link with content to the bbPress profile page (NOT using Buddypress at all), I’ve come across people saying it can be done, but no actual guide/info to how it can be done.
Any help appreciated. Thanks.
-
@deeve007 – it’s doable, but you’ll need to do some coding.
The key file you want is
wp-content/plugins/bbpress/templates/default/bbpress/user-details.php
so
create a directory on your theme called ‘bbpress’
ie wp-content/themes/%your-theme-name%/bbpresswhere %your-theme-name% is the name of your theme
find
wp-content/plugins/bbpress/templates/default/bbpress/user-details.php
Make a copy of this file, and put in in the directory called bbpress that you created above, so you end up with
wp-content/themes/%your-theme-name%/bbpress/user-details.phpbbPress will now use this template instead of the original
and you can amend thisyou’ll see the tabs in this file.
Do come back with what you are trying to do if you need further help
I’ve been able to do that, add a link, but how do I have that link then load content that will appear in the content area and under the profile URL?
that depends.
Can you outline exactly what you are aiming for eg I want a picture of fred to appear when they click a link saying ‘fred’
Why should that make a difference? Once I can find out how this is done I could add any content.
To keep it simple, let’s just say hard coded text to display, when the user clicks on a link called “Read this”.
Thanks.
Arguing with those trying to help you is probably not the best way forward.
How to do a link is easily googled, but I’ve put one in here that you can add to the template
<li> <span class="vcard bbp-user-profile-link"> <a class="url fn n" href="www.mysite.com/read-this" title="read this">Read this</a> </span> </li>
It was a legit question, not an argument, does it make any difference what the content is that I want to display?
And adding the link is the simple part, but after hours of googling I’ve not come across any guide to how to have that linked content appear within the user profile, rather than link away from the profile to another part of the site.
ok, I’ve spent several annoying hours trying to work out how to do this, and failed miserably!!
I expect the answer is just a few brief lines of code, and linked to the way bbpress handles both templates and wp-rewrite, but can’t fathom it out in the files
Sorry, but I am having to give up !
Thanks. Yep, tried so many things myself, seems ridiculous that this is so hard!
Only work around I can think of is to create user-details.php and user-profile.php pages, then have the links on user-detail page change content via Jquery that is on the user-profile page, in different DIVs, rather than go to separate pages. Then you could add further content to the user-profile page easy enough.
If that makes sense?
Hello! I have the same situation.
There isn’t a problem to add link to user profile navigation. But the problem is to ‘register’ that page in such way, that it contents would render properly under ‘base_url/forums/users/someuser/your-custom-page/’ url. bbPress allows to see other user’s profile info too.
I also couldn’t not find any guide how to do this or find it in plugin code. But if that page will be private (only for one user, like ‘Edit profile’ which disappears on others user acc pages) there is a workaround.
You can create page template, copy ‘single-user.php’ contents to it and create page for this template in admin. Then add a link in profile page. Also you should add filters to ‘bbp_get_user_id’ and ‘bbp_get_displayed_user_field’ to make everything work correctly on that page. (I can provide code if you’re interested).Compared to BuddyPress, or a membership plugin like MemberPress, this is a surprisingly tedious thing to do in bbPress. I got 3/4 of the way to building it when I decided I really wanted the function on the membership account page and not in bbPress after all.
But suppose you wanted to add a tab for a page on which a user could upload an avatar using one of the many WordPress avatar plugins. Here, roughly, are the steps you would follow:
- First, you have to create the tab. This is done by adding another list-item in bbpress/templates/default/bbpress/user-details.php.
- In the other menu items on this template, you’ll notice that the href for the link is created by a function like ‘bbp_user_profile_edit_url()’. That’s because the user’s display name has to be part of the link. So, what you’ve got to do next is look in bbpress/includes/users/template.php and find that function. Then you’ve got to copy it, rename it, and modify it so that it creates the link you want (e.g., ‘/forums/users/username/avatar/’ ).
- Next, you’ve got set up bbPress to parse that link. The parsing function is bbp_parse_query(), which is found at the bottom of bbpress/includes/core/template-functions.php. This function reads the URI and sets conditional tags (e.g., ‘bbpress_is_single_user_edit’) depending on what the URI is. The function is called from bbpress/includes/core/actions.php. You’ll need to copy this function somewhere else and rename it. Then remove the action that calls it and add an action that calls your function. Then, you’ll need to modify your function such that if the URI ends in ‘avatar’ it sets a conditional tag, e.g., ‘bbpress_is_single_user_avatar’.
- Templates are loaded based on the conditional tags, and there are functions that return true or false depending on what conditional tags are present, e.g. ‘bbp_is_single_user_edit()’. These are found in bbpress/includes/common/tempate.php. You’ll have to create one of these that returns true for ‘bbpress_is_single_user_avatar’.
- Once you’ve got that, then you can conditionally load the templates you want for the page. Templates are loaded in bbpress/includes/core/template-loader.php. The function is bbp_template_include_theme_supports(). It has a filter, so you can add a conditional that loads a template when ‘bbp_is_single_user_avatar()’ is true.
As I said, I got about 3/4 of the way to doing this when I realized that it would be clearer in my application to have the avatar in the account area of my membership plugin. But I think this is roughly how you would do it in bbPress.
Here’s my solution. It’s not as neat as it should be, but it works, without mucking around in bbpress or its core functions.
In this example, I’m adding a tab/page for ‘events’. My theme is ‘rebalance-child’.
1. Copy user-profile.php and user-details.php to /bbpress/ in your theme folder.
2. Near the top of user-details.php, add something like this:
$profile_sub = ""; if (isset($_GET["sub"])) { $profile_sub = $_GET["sub"]; } if ($profile_sub != "events") { $profile_sub = ""; }
3. Replace the code that displays the first bullet (‘Profile’) with something like this:
<li class="<?php if ( bbp_is_single_user_profile() && $profile_sub == "" ) :?>current<?php endif; ?>"> <span class="vcard bbp-user-profile-link"> <a class="url fn n" href="<?php bbp_user_profile_url(); ?>" title="<?php printf( esc_attr__( "%s's Profile", 'bbpress' ), bbp_get_displayed_user_field( 'display_name' ) ); ?>" rel="me"><?php esc_html_e( 'Profile', 'bbpress' ); ?></a> </span> </li> <li class="<?php if ( bbp_is_single_user_profile() && $profile_sub == "events") :?>current<?php endif; ?>"> <span class="vcard bbp-user-profile-link"> <a class="url fn n" href="<?php bbp_user_profile_url(); ?>?sub=events" title="<?php printf( esc_attr__( "%s's Events", 'rebalance-child' ), bbp_get_displayed_user_field( 'display_name' ) ); ?>"><?php esc_html_e( 'Events', 'rebalance-child' ); ?></a> </span> </li>
4. Update user-profile.php to display something else, based on the value of the ‘sub’ query string parameter. So, something like this:
<?php if ($_GET["sub"] == "events") { //stuff related to events// } else { //regular stuff// } ?>
Above, ‘//regular stuff/’ would be the content that was in user-profile.php before.
Hello! I want to add a new tab to the User profile with the “private messages” shortcode (separate plugin). In order for users to be able to operate with their message box inside the profile.
May be done by @mastababa way?
Where need to put the message-shortcode at the last stage of example coding (or first make a page with a shortcode and then insert it?)Yeah, that should be fine, @neon67.
In my point 4, above, you would add a tab for your private chats and then just include the shortcode via a print do_shortcode().
- You must be logged in to reply to this topic.