Skip to content

Instantly share code, notes, and snippets.

@modemlooper
Created January 29, 2016 21:40
Show Gist options
  • Save modemlooper/fb70735dd78de7cd2032 to your computer and use it in GitHub Desktop.
Save modemlooper/fb70735dd78de7cd2032 to your computer and use it in GitHub Desktop.
Example on adding a page to user profile
<?php
/**
* Plugin Name: BP Add Page
* Plugin URI: https://webdevstudios.com
* Description: Example on adding a page to BuddyPress profiles
* Author: WebDevStudios
* Author URI: https://webdevstudios.com
* Version: 1.0.0
* License: GPLv2
*/
/**
* adds the profile user nav link
*/
function bp_custom_user_nav_item() {
global $bp;
$args = array(
'name' => __('Portfolio', 'buddypress'),
'slug' => 'portfolio',
'default_subnav_slug' => 'portfolio',
'position' => 50,
'screen_function' => 'bp_custom_user_nav_item_screen',
'item_css_id' => 'portfolio'
);
bp_core_new_nav_item( $args );
}
add_action( 'bp_setup_nav', 'bp_custom_user_nav_item', 99 );
/**
* the calback function from our nav item arguments
*/
function bp_custom_user_nav_item_screen() {
add_action( 'bp_template_content', 'bp_custom_screen_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
/**
* the function hooked to bp_template_content, this hook is in plugns.php
*/
function bp_custom_screen_content() {
echo '<p>The custom content.
You can put a post loop here or something else</P>';
}
@fuadmurad
Copy link

This is excellent. My question is what if I want to create multiple new pages using this? I've tried duplicating and creating a bp-custom-2 but that didn't work and threw an error.

@toluaddy
Copy link

@fuadmurad - you'd have to create a new function by duplicating the entire code above and rename the new function to whatever name works for you...

@lordmatt
Copy link

lordmatt commented Aug 16, 2020

Quick question, does anyone know what globals are available when hooking bp_template_content? For example, if I wanted to show data to users that are not the owner of the profile but allow said owner to edit their own data.

@modemlooper
Copy link
Author

modemlooper commented Aug 17, 2020

All of buddypress is pretty much available when you are on a buddypress page. You could wrap any code in bp_is_my_profile() conditional to check if the user "owns" the profile

@lordmatt
Copy link

You are a star. Thank you. This information has saved me a few hours of head-scratching.

@gercamjr
Copy link

This is pretty awesome. Would there be a way to make these profile pages only viewable to a certain member type/profile type? For example, if I wanted to add a custom page called grades for members that are "students", and then a custom tab called "Student Roll" for members that are "teachers"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment