How do I move profile subnavs to Settings subnav
-
Hi
Was hoping someone could assist me on the code to move the profile subnavs to the settings subnav. Tried a lot of methods after searching for the answer online but came up short. Even went into the xprofile-loader and settings-loader php files but fell short. Got the links to appear in the settings subnav but View Profile and Change Avatar didn’t work. Edit profile worked but kept returning to the profile tab when clicked. Thanks!
-
I’d like to know how to do this, too. Some of the subnav items would make more sense for my application if they were grouped differently.
Hi @josephfrio13yahoocom and @lflier
Component navigation is set-up in the component’s class. For example, the
setup_nav
method within theBP_Friends_Component
class does this for the Friends component. See here for exactly how it’s done.To my knowledge, there is no easy way to move subnavs around.
Thanks Henry,
I was afraid of that…
But here’s a happy thought… Suppose you took the screen function from the subnav in the Profile nav that you want to move to Settings and assigned it to a new subnav item you created in Settings. Then you just remove the subnav from the Profile nav and the effect is just like moving the subnav from Profile to Settings.
Haven’t tried it, but I suspect it would work.
@lflier that sounds like a good approach. The screen function will be already written for you and as you say, creating the new subnav and removing the unwanted one is easy enough.
Hey guys,
Not really an expert at this at all. I really appreciate the replies though — that’s awesome!
I went into the profile-loader.php and settings-loader.php files and tried to move around some things but nothing worked properly… but I guess what I’m asking is: is there any code you suggest that I could do a search/replace or whatnot to make this last suggestion easier? Would be much appreciated.
Thanks all!
@josephfrio13yahoocom you have a fine question. I am one step away from being able to answer it for you. I know how to create and delete subnavs, and I know how to set up screen functions for the subnavs I create. But I am not yet able to connect a new subnav with an existing BuddyPress screen function.
I tried the following code last night, but was unsuccessful:
function setup_custom_nav() { global $bp; bp_core_new_subnav_item( array( 'name' => __( 'Change Avatarr', 'buddypress' ), 'slug' => 'change-avatarr', 'parent_url' => $bp->loggedin_user->domain . 'settings/', 'parent_slug' => 'settings', 'screen_function' => 'lf_screen_function', 'position' => 30, ) ); } add_action( 'bp_setup_nav', 'setup_custom_nav'); function lf_screen_function() { add_action( 'bp_template_content', 'xprofile_screen_change_avatar' ); bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) ); }
What I get from this is another whole site-generator division inside the already existing one. I get the same thing if I put ‘xprofile_screen_change_avatar’ in directly for the screen function.
I’m getting the screen function from here: https://github.com/buddypress/BuddyPress/blob/12bc8cb1b6000d73be2d43e1c34e26c42b5ff215/src/bp-xprofile/bp-xprofile-loader.php#L216
In your
setup_custom_nav
function, instead of:'screen_function' => 'lf_screen_function',
Maybe you can do this:
'screen_function' => 'xprofile_screen_change_avatar',
And you won’t need your
lf_screen_function()
function.I haven’t tested this, but don’t see why doing that isn’t possible.
Thanks, Henry. Your suggestion is intuitive and it was my original plan, too. I tried it that way first and failed (same result as above).
Then I went back to the code I had used in my own site, which is the lf_screen_function() that adds an action to the function that gives the desired output, which, in this case appears to be the xprofile_screen_change_avatar function. But that also failed.
There’s got to be a way to do it, though.
Can you try making a copy of
xprofile_screen_change_avatar
in functions.php and renaming it tocustom_xprofile_screen_change_avatar
Then try:
'screen_function' => 'custom_xprofile_screen_change_avatar',
Same output as before.
Take a look at this example screen function from the BP Skeleton Component:
Instead of trying to re-use the
xprofile_screen_change_avatar
, perhaps try creating your own using this as a guide. Boone Gorges looks after the BP Skeleton Component, so the techniques used within it are good practice and provide lots of useful comments on how to get things done.Thanks. I’ll try this as time permits.
In the meantime I can share with @josephfrio13yahoocom what I know about changing the BuddyPress subnav section:
1. You’ve seen a working example of creating a new subnav in the code I posted earlier. Just substitute your own output function for the xprofile_screen_change_avatar function in the line:
add_action( 'bp_template_content', 'xprofile_screen_change_avatar' );
2. To remove a subnav item see my post here.
3. To change the default subnav, which you will have to do if you want to delete a default subnav, see the BuddyPress codex here, which has a nice example.
I’m sure Henry could do better, but I hope this gets you started. All of this can be done in a functions.php file. No modifications of the BP core should be necessary.
@lflier couldn’t do any better than this if I tried. It all looks good to me 🙂
@henrywright and @lflier thanks a bunch for the time on this, it’s much appreciated! I’m going to play around with the information you gave me and see if I can come up with something a little later. I’ll keep you posted on my progress! Can’t thank you guys enough for your time and I look forward to reaching out soon, hopefully with some success! Great forum 🙂
Look like I’m getting this…
Tried a bunch of things but can’t get around this above image. Doesn’t even look like the page is loading properly. Was attempting the Change Avatarr subnav.
Let me know if you have any further suggestions. Thanks again!
I was able to get the avatar form to show up with this snippet:
function setup_custom_nav() { global $bp; bp_core_new_subnav_item( array( 'name' => __( 'Change Avatar', 'buddypress' ), 'slug' => 'change-avatar', 'parent_url' => $bp->loggedin_user->domain . 'settings/', 'parent_slug' => 'settings', 'screen_function' => 'ca_screen_function', 'position' => 30, ) ); } add_action( 'bp_setup_nav', 'setup_custom_nav'); function ca_screen_function() { add_action( 'bp_template_content', 'change_profile_picture_screen_content' ); bp_core_load_template( apply_filters( 'xprofile_template_change_avatar', 'members/single/plugins' ) ); xprofile_screen_change_avatar(); } function change_profile_picture_screen_content() { bp_get_template_part( 'members/single/profile/change-avatar' ); }
But when I try to upload a new avatar the resizing/cropping screen doesn’t show up.
I found a working version from here:
- The topic ‘How do I move profile subnavs to Settings subnav’ is closed to new replies.