Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function buddydev_modify_user_nav() {
- $bp = buddypress();
- // rename general settings tab
- $bp->bp_options_nav['settings']['general']['name'] = 'Account Details';
- // remove profile menu tab
- //remove edit/change avatar from profile sub menu
- //unset($bp->bp_options_nav['profile']['edit']);
- //unset($bp->bp_options_nav['profile']['change-avatar']);
- bp_core_remove_subnav_item( $bp->profile->slug, 'edit' );
- bp_core_remove_subnav_item( $bp->profile->slug, 'change-avatar' );
- $user_url = bp_loggedin_user_domain();
- // add 'Change profile picture' sub-menu tab
- bp_core_new_subnav_item( array(
- 'name' => 'Change Profile Picture',
- 'slug' => 'change-profile-picture',
- 'parent_url' => trailingslashit( $user_url . $bp->settings->slug ),
- 'parent_slug' => $bp->settings->slug,
- 'screen_function' => 'buddydev_modified_avatar_screen_handler',
- 'position' => 30,
- 'user_has_access' => bp_is_my_profile()
- )
- );
- //add edit profile sub menu under settings
- bp_core_new_subnav_item( array(
- 'name' => 'Edit Profile',
- 'slug' => 'edit-profile',
- 'parent_url' => trailingslashit( $user_url . $bp->settings->slug ),
- 'parent_slug' => $bp->settings->slug,
- 'screen_function' => 'buddydev_modified_edit_profile_screen_handler',
- 'position' => 40,
- 'user_has_access' => bp_is_my_profile()
- )
- );
- }
- add_action( 'bp_setup_nav', 'buddydev_modify_user_nav', 100 );
- //modified screen handler
- function buddydev_modified_avatar_screen_handler(){
- //hook custom function to get theh screen content on the plugins template
- add_action( 'bp_template_content', 'buddydev_screen_content_change_avatar' );
- xprofile_screen_change_avatar();
- }
- //load plugins template on change avatar
- function buddydev_filter_change_avatar_template( $template ) {
- return 'members/single/plugins';
- }
- add_filter('xprofile_template_change_avatar', 'buddydev_filter_change_avatar_template' );
- //ask BuddyPress to show the change-avatar file content using plugins template
- function buddydev_screen_content_change_avatar() {
- bp_get_template_part( 'members/single/profile/change-avatar' );
- }
- //For Edit profile, It is a little bit tricky as BuddyPress uses the profile/edit url a lot
- function buddydev_modified_edit_profile_screen_handler() {
- //if the group is not set, redirect to first group
- if ( ! bp_action_variable( 1 ) ) {
- bp_core_redirect( trailingslashit( bp_displayed_user_domain() . buddypress()->settings->slug . '/edit-profile/group/1' ) );
- }
- add_action( 'bp_template_content', 'buddydev_screen_content_edit_profile' );
- xprofile_screen_edit_profile();
- }
- //filter xprofile template, ask buddypress to load plugins template
- function buddydev_filter_edit_profile_template( $template ) {
- return 'members/single/plugins';
- }
- add_filter( 'xprofile_template_edit_profile', 'buddydev_filter_edit_profile_template' );
- //show the edit profile content
- function buddydev_screen_content_edit_profile() {
- bp_get_template_part( 'members/single/profile/edit' );
- }
- //now, all the filters below modify various Profile specific url to go to settings
- //modify edit profile form action url to point to settings screen url
- function buddydev_filter_edit_profile_form_url( $url ) {
- global $group;
- return trailingslashit( bp_displayed_user_domain() . buddypress()->settings->slug . '/edit-profile/group/' . $group->id );
- }
- add_filter( 'bp_get_the_profile_group_edit_form_action', 'buddydev_filter_edit_profile_form_url' );
- //filter the Profile Field group link to point to settings url
- function buddydev_filter_edit_profile_group_tabs( $tabs, $groups, $group_name ) {
- //instead of processing, let us go with string replamenet :)
- $profile_url = trailingslashit( bp_displayed_user_domain() . buddypress()->profile->slug . '/edit/group/' );
- $settings_url = trailingslashit( bp_displayed_user_domain() . buddypress()->settings->slug . '/edit-profile/group/' );
- $tabs = str_replace( $profile_url, $settings_url, $tabs );
- return $tabs;
- }
- add_filter( 'xprofile_filter_profile_group_tabs', 'buddydev_filter_edit_profile_group_tabs', 10, 3 );
- //we use this to redirect early
- function buddydev_redirect_on_profile_update ( $user_id, $posted_field_ids, $errors, $old_values, $new_values ) {
- if ( ! empty( $errors ) ) {
- bp_core_add_message( __( 'There was a problem updating some of your profile information. Please try again.', 'buddypress' ), 'error' );
- } else {
- bp_core_add_message( __( 'Changes saved.', 'buddypress' ) );
- }
- // Redirect back to the edit screen to display the updates and message
- bp_core_redirect( trailingslashit( bp_displayed_user_domain() . buddypress()->settings->slug . '/edit-profile/group/' . bp_action_variable( 1 ) ) );
- }
- add_action( 'xprofile_updated_profile', 'buddydev_redirect_on_profile_update', 10, 5 );
- //and the last but the most important one, BuddyPress will not show empty groups on settings/edit profile, we force it
- function buddydev_modify_has_profile_args( $args ) {
- if( bp_is_settings_component() && bp_is_current_action( 'edit-profile') ) {
- $args['hide_empty_groups'] = false;
- $args['hide_empty_fields'] = false;
- }
- return $args;
- }
- add_filter( 'bp_after_has_profile_parse_args', 'buddydev_modify_has_profile_args' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement