Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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>';
}
@joebenny

This comment has been minimized.

Copy link

joebenny commented Apr 3, 2017

good work. trying to upload plugin but experiencing difficulties with installation failed report.

@nikimaria87

This comment has been minimized.

Copy link

nikimaria87 commented Nov 20, 2018

@joebenny - if you create a a file called bp-custom.php and add that file to your /wp-content/plugins/ this is where you can add custom code. I copied the code above to my bp-custom.php file and it works flawlessly.

@nikimaria87

This comment has been minimized.

Copy link

nikimaria87 commented Nov 20, 2018

Add the code below to grab content from the page id of your choice. Swap out the page id with the one corresponding to your website. The post or page id in in the URL if you are editing the page. For example, mine is post.php?post=28&action=edit and post=28 means my post id is 28. I am going to be putting together a custom function to allow users to take practice exams and view results as well so I will be adding some extra code to my account for anyone looking to make use of Gravity forms within BuddyPress. Also please be sure you paste the above code, as well as the code below to the bp-custom.php file. If you do not have the file (as it doesn't come standard with BuddyPress) create the file in your editor, add , and place all of your content within the php tags.

/**

  • the function hooked to bp_template_content, this hook is in plugns.php. The hook
  • will call the content of the Portfolio page to the navigation item.
    */

function bp_custom_screen_content() {
$my_id = 28;
$post_id_28 = get_post($my_id);
$content = $post_id_28->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;

@fuadmurad

This comment has been minimized.

Copy link

fuadmurad commented Nov 15, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.