BpGroupReports
Exttends Buddypress Group Tab
Description
Source
File: bp-integrations/learndash/buddypress/components/BpGroupReports.php
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | class BpGroupReports extends BP_Group_Extension { /** * Constructor * * @since BuddyBoss 1.0.0 */ public function __construct() { parent::init( $this ->prepareComponentOptions()); } /** * Display the tab content based on the selected sub tab * * @since BuddyBoss 1.0.0 */ public function display( $groupId = null) { $this ->loadSubMenuTemplate( $groupId ); $action = bp_action_variable() ?: 'reports' ; if (! $location = bp_locate_template( "groups/single/reports-{$action}.php" , true)) { bp_locate_template( 'groups/single/reports-404.php' , true); } } /** * Display the tab sub menu before the tab content * * @since BuddyBoss 1.0.0 */ protected function loadSubMenuTemplate( $groupId ) { $groupId = $groupId ?: bp_get_new_group_id(); $hasLdGroup = bp_ld_sync( 'buddypress' )->sync->generator( $groupId )->hasLdGroup(); $currentMenu = bp_action_variable(); $subMenus = array_map ( function ( $menu ) { $menu [ 'url' ] = bp_ld_sync( 'buddypress' )->subMenuLink( $menu [ 'slug' ]); return $menu ; }, bp_ld_sync( 'buddypress' )->reportsSubMenus()); require bp_locate_template( 'groups/single/reports-nav.php' , false, false); } /** * Arguments to pass into the buddypress group extension class * * @since BuddyBoss 1.0.0 */ protected function prepareComponentOptions() { $tabName = apply_filters( 'bp_ld_sync/reports_group_tab_name' , __( 'Reports' , 'buddyboss' )); $tabSlug = apply_filters( 'bp_ld_sync/reports_group_tab_slug' , 'reports' ); $tabPosition = apply_filters( 'bp_ld_sync/reports_group_tab_position' , 15); return [ 'name' => $tabName , 'slug' => $tabSlug , 'nav_item_position' => $tabPosition , 'access' => apply_filters( 'bp_ld_sync/reports_group_tab_enabled' , $this ->showTabOnView()), 'screens' => [ 'create' => [ 'enabled' => false, ], 'edit' => [ 'enabled' => false, ], 'admin' => [ 'enabled' => false, ], ] ]; } /** * Determine who can see the tab * * @since BuddyBoss 1.0.0 */ protected function showTabOnView() { if (! $currentGroup = groups_get_current_group()) { return 'noone' ; } $generator = bp_ld_sync( 'buddypress' )->sync->generator( $currentGroup ->id); if (! $generator ->hasLdGroup()) { return 'noone' ; } if (! learndash_group_enrolled_courses( $generator ->getLdGroupId())) { return 'noone' ; } // admin can always view if (learndash_is_admin_user()) { return true; } foreach (bp_ld_sync( 'settings' )->get( 'reports.access' , []) as $type ) { $function = "groups_is_user_{$type}" ; if (function_exists( $function ) && call_user_func_array( $function , [bp_loggedin_user_id(), $currentGroup ->id])) { return true; } } return 'noone' ; } } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.0 | Introduced. |
Methods
- __construct — Constructor
- display — Display the tab content based on the selected sub tab
- loadSubMenuTemplate — Display the tab sub menu before the tab content
- prepareComponentOptions — Arguments to pass into the buddypress group extension class
- showTabOnView — Determine who can see the tab
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.