Skip to content

Instantly share code, notes, and snippets.

@igorbenic
Last active March 9, 2016 16:40
Show Gist options
  • Save igorbenic/65a638dac4a958635e98 to your computer and use it in GitHub Desktop.
Save igorbenic/65a638dac4a958635e98 to your computer and use it in GitHub Desktop.
Add a new Tab to BuddyPress Profile Page | http://www.ibenic.com/add-new-tab-buddypress-profile-page/
<?php
function ibenic_buddypress_tab() {
global $bp;
bp_core_new_nav_item( array(
'name' => __( 'My recent Posts', 'ibenic' ),
'slug' => 'recent-posts',
'position' => 100,
'screen_function' => 'ibenic_budypress_recent_posts',
'show_for_displayed_user' => true,
'item_css_id' => 'ibenic_budypress_recent_posts'
) );
}
add_action( 'bp_setup_nav', 'ibenic_buddypress_tab', 1000 );
<?php
bp_core_new_nav_item(
array(
'name' => __('Messages', 'buddypress'),
'slug' => $bp->messages->slug,
'position' => 50,
'show_for_displayed_user' => false,
'screen_function' => 'messages_screen_inbox',
'default_subnav_slug' => 'inbox',
'item_css_id' => $bp->messages->id
)
);
<?php
function ibenic_budypress_recent_posts () {
add_action( 'bp_template_title', 'ibenic_buddypress_recent_posts_title' );
add_action( 'bp_template_content', 'ibenic_buddypress_recent_posts_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
<?php
function ibenic_buddypress_recent_posts_content() {
$profileUserID = bp_displayed_user_id();
if( $profileUserID > 0 ) {
$posts = get_posts( array(
'author' => $profileUserID,
'posts_per_page' => 5,
));
if( is_array( $posts ) && ! empty( $posts ) ) {
echo '<ul>';
foreach( $posts as $post ){
setup_postdata( $post );
?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php
}
echo '</ul>';
}
}
}
<?php
function ibenic_buddypress_recent_posts_title() {
_e( 'My Recent Posts', 'ibenic' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment