BuddyDev

Search

[Resolved] xprofile field group

  • Participant
    Level: Initiated
    Posts: 3
    saran on #3975

    Hello Brajesh and Ravi,

    Is it possible to move xprofile field group to a custom buddypress profile tab.I have created a field group and want to show it in a different tab not in user’s profile tab.Please guide!

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #3981

    Hi Saran,
    Welcome back.
    Yes, It is doable and here is an example. Please make sure to change the profile group ID in the code.

    
    
    //step 1: Add a new Tab
    function buddydev_setup_new_xprofile_tab() {
    
        $slug = bp_get_profile_slug();
    
        bp_core_new_subnav_item( array(
            'name'          => 'About',//label
            'slug'          => 'about',//slug
            'parent_slug'   => $slug,
            'position'      => 12,
            'parent_url'    => trailingslashit( bp_loggedin_user_domain() . $slug )  ,
            'screen_function' => 'buddydev_screen_profile_data'
        ));
    }
    
    add_action( 'bp_setup_nav', 'buddydev_setup_new_xprofile_tab' );
    
    //Step 2: Load the plugins template file
    function buddydev_screen_profile_data() {
        //filter loop
        add_filter( 'bp_after_has_profile_parse_args', 'buddydev_filter_args_for_profile_group' );
        //load loop
        add_action( 'bp_template_content', 'buddydev_show_profile_group_data');
    
        bp_core_load_template( 'members/single/plugins');
    }
    
    function buddydev_filter_args_for_profile_group( $args ) {
        ///CHANGE IT
        $args['profile_group_id']  = 2; //Your Profile Group ID Here
    
        return $args;
    }
    //Load the loop
    function buddydev_show_profile_group_data() {
    
        bp_get_template_part( 'members/single/profile/profile-loop' );
    }
    
    

    Please do let me know how it goes with you.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 3
    saran on #3997

    Hi Brajesh,

    Thank u very much for relying. As expected you put me in right direction. You people are great. Though i wanted to move the profile group into a new main nav tab like Activity, Profile etc. May be i did not elaborate it clearly to you first but with some little changes in your code it was easily achiveable.
    Here i am posting code in case someone else need the same

    function buddydev_modifyy_user_profile_tab() {

    bp_core_new_nav_item( array(
    ‘name’ => ‘My Startup’,
    ‘slug’ => ‘mystartup’,
    ‘screen_function’ => ‘buddydev_screen_profile_data’,
    ‘position’ => 30,
    ‘default_subnav_slug’ => ‘mystartup-sub’,
    ‘show_for_displayed_user’ => true,
    )
    );

    }
    add_action( ‘bp_setup_nav’, ‘buddydev_modifyy_user_profile_tab’, 8 );

    function buddydev_screen_profile_data() {
    //filter loop
    add_filter( ‘bp_after_has_profile_parse_args’, ‘buddydev_filter_args_for_profile_group’ );
    //load loop
    add_action( ‘bp_template_content’, ‘buddydev_show_profile_group_data’);

    bp_core_load_template( ‘members/single/plugins’);
    }

    function buddydev_filter_args_for_profile_group( $args ) {
    ///CHANGE IT
    $args[‘profile_group_id’] = ‘5’; //Your Profile Group ID Here

    return $args;
    }
    //Load the loop
    function buddydev_show_profile_group_data() {
    $profileslug = bp_get_profile_slug();
    if ( bp_is_my_profile() ) :
    echo “Edit“;
    endif;
    bp_get_template_part( ‘members/single/profile/profile-loop’ );
    }
    function hide_profile_group( $grpid ) {
    if ( is_user_logged_in() && !bp_is_profile_edit() ) {
    $myfield = xprofile_get_field_data( ‘My Startup’ );
    $grpid[‘exclude_groups’] = ‘5’;
    }
    return $grpid;
    }
    add_filter( ‘bp_after_has_profile_parse_args’, ‘hide_profile_group’ );

    Your Forum is awesome. Learning a lot from here. Thanks once again 🙂

The topic ‘ [Resolved] xprofile field group’ is closed to new replies.

This topic is: resolved