Guest User

Untitled

a guest
Jun 10th, 2024
1,035
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.98 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: BuddyPress Group Test
  4. Plugin URI: n/a
  5. Description: Test adding group tab
  6. Version: 0.0.1
  7. Author: n/a
  8. Author URI: n/a
  9. License: AGPLv3
  10. */
  11.  
  12. add_action('bp_actions', function()
  13. {  
  14.     if(bp_is_group())
  15.     {
  16.         $group_slug = bp_get_current_group_slug();
  17.         bp_core_remove_subnav_item("{$group_slug}_manage", 'group-avatar', 'groups');
  18.     }
  19.     else
  20.     {
  21.         bp_core_remove_subnav_item('profile', 'change-avatar', 'members');
  22.     }
  23. });
  24.  
  25. add_action('bp_setup_nav', function()
  26. {
  27.     $bp = buddypress();
  28.     if(bp_is_group())
  29.     {
  30.         $group_slug = bp_get_current_group_slug();
  31.         $tab = bp_core_new_subnav_item(
  32.         [
  33.             'name' => 'Change Group Photo',
  34.             'slug' => 'change-group-photo',
  35.             'parent_url' => trailingslashit(bp_get_group_permalink($group_slug)) . 'admin/',
  36.             'parent_slug' => "{$group_slug}_manage",
  37.             'position' => 30,
  38.             'screen_function' => function() use($group_slug)
  39.             {
  40.                 bp_core_load_template(apply_filters('bp_core_template_plugin', 'groups/single/plugins'));
  41.                 add_action('bp_template_content', function()
  42.                 {
  43.                     echo '<h1>GROUP</h1>';
  44.                 });
  45.             },
  46.         ]);
  47.     }
  48.     else
  49.     {
  50.         $tab = bp_core_new_subnav_item(
  51.         [
  52.             'name' => 'Change Profile Photo',
  53.             'slug' => 'change-profile-photo',
  54.             'parent_url' => trailingslashit($bp->loggedin_user->domain . $bp->profile->slug),
  55.             'parent_slug' => $bp->profile->slug,
  56.             'position' => 30,
  57.             'screen_function' => function()
  58.             {
  59.                 bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
  60.                 add_action('bp_template_content', function()
  61.                 {
  62.                     echo '<h1>USER</h1>';
  63.                 });
  64.             },
  65.         ]);
  66.     }
  67. }, 10);
Advertisement
Comments
  • koka-boka
    2 years (edited)
    # PHP 2.35 KB | 0 0
    1. Hello @kkjdroid. I'm not sure I understood you correctly. Still, I made some changes, try it.
    2.  
    3. <?php
    4. /*
    5. Plugin Name: BuddyPress Group Test
    6. Plugin URI: n/a
    7. Description: Test adding group tab
    8. Version: 0.0.1
    9. Author: n/a
    10. Author URI: n/a
    11. License: AGPLv3
    12. */
    13.  
    14. add_action('bp_actions', function() {  
    15.     if (bp_is_group()) {
    16.         $group = groups_get_current_group();
    17.         if ($group) {
    18.             $group_slug = $group->slug;
    19.             bp_core_remove_subnav_item($group_slug . '_manage', 'group-avatar', 'groups');
    20.         }
    21.     } else {
    22.         bp_core_remove_subnav_item('profile', 'change-avatar', 'members');
    23.     }
    24. });
    25.  
    26. add_action('bp_setup_nav', function() {
    27.     $bp = buddypress();
    28.     if (bp_is_group()) {
    29.         $group = groups_get_current_group();
    30.         if ($group) {
    31.             $group_slug = $group->slug;
    32.             $parent_url = trailingslashit(bp_get_group_permalink($group)) . 'admin/';
    33.             bp_core_new_subnav_item([
    34.                 'name' => 'Change Group Photo',
    35.                 'slug' => 'change-group-photo',
    36.                 'parent_url' => $parent_url,
    37.                 'parent_slug' => $group_slug . '_manage',
    38.                 'position' => 30,
    39.                 'screen_function' => function() {
    40.                     bp_core_load_template(apply_filters('bp_core_template_plugin', 'groups/single/plugins'));
    41.                     add_action('bp_template_content', function() {
    42.                         echo '<h1>GROUP</h1>';
    43.                     });
    44.                 },
    45.             ]);
    46.         }
    47.     } else {
    48.         if (is_user_logged_in()) {
    49.             $user = wp_get_current_user();
    50.             $parent_url = trailingslashit($bp->loggedin_user->domain . $bp->profile->slug);
    51.             bp_core_new_subnav_item([
    52.                 'name' => 'Change Profile Photo',
    53.                 'slug' => 'change-profile-photo',
    54.                 'parent_url' => $parent_url,
    55.                 'parent_slug' => $bp->profile->slug,
    56.                 'position' => 30,
    57.                 'screen_function' => function() {
    58.                     bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
    59.                     add_action('bp_template_content', function() {
    60.                         echo '<h1>USER</h1>';
    61.                     });
    62.                 },
    63.             ]);
    64.         }
    65.     }
    66. }, 10);
    67. ?>
Add Comment
Please, Sign In to add comment