Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display profile fields in an extra tab in bp-custom.php


  • ufodisko
    Participant

    @ufodisko

    I created an extra tab on the user’s profile page and I would like to display the profile fields in it.

    This is how I created the extra tab in the first place, I created a new bp-custom.php with this inside

    function profile_new_nav_item() {
    
        global $bp;
    
        bp_core_new_nav_item(
            array(
                'name'                => 'About',
                'slug'                => 'about',
              'default_subnav_slug' => 'extra_sub_tab', // We add this submenu item below
                'screen_function'     => 'view_manage_tab_main'
            )
        );
    }
    
    add_action( 'bp_setup_nav', 'profile_new_nav_item', 10 );
    
    function view_manage_tab_main() {
        add_action( 'bp_template_content', 'bp_template_content_main_function' );
        bp_core_load_template( 'template_content' );
    }
    
    function bp_template_content_main_function() {
        if ( ! is_user_logged_in() ) {
            wp_login_form( array( 'echo' => true ) );
        }
    }
    
    function profile_new_subnav_item() {
        global $bp;
    
        bp_core_new_subnav_item( array(
            'name'            => 'Extra Sub Tab',
            'slug'            => 'extra_sub_tab',
            'parent_url'      => $bp->loggedin_user->domain . $bp->bp_nav[ 'about' ][ 'slug' ] . '/',
            'parent_slug'     => $bp->bp_nav[ 'about' ][ 'slug' ],
            'position'        => 10,
            'screen_function' => 'view_manage_sub_tab_main'
        ) );
    }
    
    add_action( 'bp_setup_nav', 'profile_new_subnav_item', 10 );
    
    function view_manage_sub_tab_main() {
        add_action( 'bp_template_content', 'bp_template_content_sub_function' );
        bp_core_load_template( 'template_content' );
    }
    
    function bp_template_content_sub_function() {
        if ( is_user_logged_in() ) {
            echo 'you are here';
        } else {
            wp_login_form( array( 'echo' => true ) );
        }
    }

    See where it says “echo you are here” in the last function, I would like to display the profile fields there. I have the code below but I can’t figure out how to embed it there.

    <div class="bp-widget <?php bp_the_profile_group_slug(); ?>">
    <h4><?php bp_the_profile_group_name(); ?></h4>
    <table class="profile-fields">
        <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
            <?php if ( bp_field_has_data() ) : ?>
                <tr<?php bp_field_css_class(); ?>>
                    <td class="label"><?php bp_the_profile_field_name(); ?></td>
                    <td class="data"><?php bp_the_profile_field_value(); ?></td>
                </tr>
            <?php endif; ?>
            <?php
            do_action( 'bp_profile_field_item' ); ?>
        <?php endwhile; ?>
    </table></div>
  • The topic ‘Display profile fields in an extra tab in bp-custom.php’ is closed to new replies.
Skip to toolbar