Advertisement
vapvarun

Function to add a new tab to display own groups in the BuddyPress profile

Dec 1st, 2023 (edited)
1,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | Software | 0 0
  1. // Function to add a new tab in the BuddyPress profile
  2. function vap_add_groups_created_by_user_tab() {
  3.     global $bp;
  4.  
  5.     bp_core_new_nav_item( array(
  6.         'name' => __('Own Groups', 'buddypress'), // The name of your tab
  7.         'slug' => 'own-groups', // The slug (URL segment) for the tab
  8.         'screen_function' => 'vap_groups_created_by_user_screen', // The function that will load the new tab content
  9.         'position' => 50,
  10.         'parent_url'      => bp_loggedin_user_domain() . '/own-groups/',
  11.         'parent_slug'     => $bp->profile->slug,
  12.     ));
  13. }
  14. add_action( 'bp_setup_nav', 'vap_add_groups_created_by_user_tab' );
  15.  
  16. // Callback function for the new tab content
  17. function vap_groups_created_by_user_screen() {
  18.     add_action( 'bp_template_title', 'vap_groups_created_by_user_title' );
  19.     add_action( 'bp_template_content', 'vap_groups_created_by_user_content' );
  20.     bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  21. }
  22.  
  23. // Function to set the title of your new tab page
  24. function vap_groups_created_by_user_title() {
  25.     echo 'My Created Groups';
  26. }
  27.  
  28. // Function to display the groups created by the user
  29. function vap_groups_created_by_user_content() {
  30.     // Get the displayed user's ID
  31.     $user_id = bp_displayed_user_id();
  32.  
  33.     // Set up the parameters for the group loop
  34.     $args = array(
  35.         'user_id' => $user_id, // Filter to show only groups the user has created
  36.         'per_page' => 10, // How many groups to display per page
  37.         // Add other parameters as needed
  38.     );
  39.  
  40.     // Start the BuddyPress groups loop with these arguments
  41.     if ( bp_has_groups( $args ) ) {
  42.         bp_get_template_part( 'groups/groups-loop' ); // Use the groups loop template
  43.     } else {
  44.         echo 'No groups found.';
  45.     }
  46. }
  47.  
  48. // Add the combined code to your theme's functions.php file or a custom plugin
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement