1. Customize
  2. BuddyPress Integration
  3. Custom user profile tab with GamiPress shortcodes

Custom user profile tab with GamiPress shortcodes

The following snippet shows how to add a custom user profile tab with different GamiPress shortcodes.

Check the shortcodes documentation page where you can find the full list of shortcodes as well as the attributes they support.

Also, all shortcodes has passed the BuddyPress displayed user ID to show earned items by the current displayed user.

function my_prefix_bp_setup_nav() {

    global $bp;

    // Change the name and slug as you wish
    $name = 'Custom Tab';
    $slug = 'custom-tab';

    bp_core_new_nav_item( array(
        'name'                  => $name,
        'slug'                  => $slug,
        'screen_function'       => 'my_prefix_screen',
        'position'              => 40,
        'parent_url'            => bp_loggedin_user_domain() . '/' . $slug . '/',
        'parent_slug'           => $bp->profile->slug,
        'default_subnav_slug'   => $slug
    ) );

}
add_action( 'bp_setup_nav', 'my_prefix_bp_setup_nav' );

function my_prefix_screen() {

    // Register title (optional) and content hooks
    add_action( 'bp_template_title', 'my_prefix_title' );

    add_action( 'bp_template_content', 'my_prefix_content' );

    bp_core_load_template( 'buddypress/members/single/plugins' );

}

function my_prefix_title() {

    echo 'Custom Tab Title';

}

function my_prefix_content() {

    // User displayed ID, to pass to custom shortcodes
    $user_id = bp_displayed_user_id();

    // Here is where you can add anything you want

    // Like GamiPress shortcodes thought the do_shortcode() function

    // Displayed user achievements of all types (hiding the search and filter inputs, and set filter to just completed achievements)
    echo do_shortcode('[gamipress_achievements search="no" filter="no" filter_value="completed" user_id="' . $user_id . '"]');

    // Displayed user points of all types
    echo do_shortcode('[gamipress_points user_id="' . $user_id . '"]');

    // Displayed user ranks of all types
    echo do_shortcode('[gamipress_ranks user_id="' . $user_id . '"]');

    // Displayed user logs
    echo do_shortcode('[gamipress_logs user_id="' . $user_id . '"]');

    // Displayed user earnigns
    echo do_shortcode('[gamipress_earnings user_id="' . $user_id . '"]');

    // Or custom HTML content
    echo '

Custom Tab HTML Content

'; }
Was this article helpful to you? Yes No 1

How can we help?