BpGroupCourses
Exttends Buddypress Group Tab
Description
Source
File: bp-integrations/learndash/buddypress/components/BpGroupCourses.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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | class BpGroupCourses extends BP_Group_Extension { /** * Constructor * * @since BuddyBoss 1.0.0 */ public function __construct() { parent::init( $this ->prepareComponentOptions()); } /** * Displays the settings for all views * * @since BuddyBoss 1.0.0 */ public function settings_screen( $groupId = null) { $groupId = $groupId ?: bp_get_new_group_id(); $hasLdGroup = bp_ld_sync( 'buddypress' )->sync->generator( $groupId )->hasLdGroup(); $ldGroupId = $hasLdGroup ? bp_ld_sync( 'buddypress' )->sync->generator( $groupId )->getLdGroupId() : 0; require bp_locate_template( 'groups/single/admin/edit-courses.php' , false); } /** * Saving the settings for all views * * @since BuddyBoss 1.0.0 */ public function settings_screen_save( $groupId = null) { $generator = bp_ld_sync( 'buddypress' )->sync->generator( $groupId ); if (! bp_ld_sync()->getRequest( 'bp-ld-sync-enable' )) { return $generator ->desyncFromLearndash(); } $generator ->associateToLearndash()->syncBpAdmins(); } /** * 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() ?: 'courses' ; if (! $location = bp_locate_template( "groups/single/courses-{$action}.php" , true)) { bp_locate_template( 'groups/single/courses-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' )->coursesSubMenus()); require bp_locate_template( 'groups/single/courses-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/courses_group_tab_name' , $this ->tabLabel()); $tabSlug = apply_filters( 'bp_ld_sync/courses_group_tab_slug' , 'courses' ); $tabPosition = apply_filters( 'bp_ld_sync/courses_group_tab_position' , 15); // learndash_is_group_leader_user return [ 'name' => $tabName , 'slug' => $tabSlug , 'nav_item_position' => $tabPosition , 'access' => apply_filters( 'bp_ld_sync/courses_group_tab_enabled' , $this ->showTabOnView()), 'screens' => [ 'create' => [ 'enabled' => apply_filters( 'bp_ld_sync/courses_group_tab_enabled/screen=create' , $this ->showTabOnCreate()), 'name' => apply_filters( 'bp_ld_sync/courses_group_tab_name/screen=create' , $tabName ), 'slug' => apply_filters( 'bp_ld_sync/courses_group_tab_slug/screen=create' , $tabSlug ), 'position' => apply_filters( 'bp_ld_sync/courses_group_tab_position/screen=create' , $tabPosition ), // 'screen_callback' => '', // 'save_callback' => '', // ?? ], 'edit' => [ 'enabled' => apply_filters( 'bp_ld_sync/courses_group_tab_enabled/screen=edit' , true), 'name' => apply_filters( 'bp_ld_sync/courses_group_tab_name/screen=edit' , $tabName ), 'slug' => apply_filters( 'bp_ld_sync/courses_group_tab_slug/screen=edit' , $tabSlug ), 'position' => apply_filters( 'bp_ld_sync/courses_group_tab_position/screen=edit' , $tabPosition ), // 'screen_callback' => '', // 'save_callback' => '', // ?? // 'submit_text' => '' ], 'admin' => array ( 'metabox_context' => 'normal' , 'metabox_priority' => 'core' , ), ] ]; } /** * Return the tab label with proper nonce * * @since BuddyBoss 1.0.0 */ protected function tabLabel() { $default = __( 'Courses' , 'buddyboss' ); if (! $currentGroup = groups_get_current_group()) { return $default ; } $coursesCount = count (bp_learndash_get_group_courses( $currentGroup ->id)); return _nx( 'Course' , 'Courses' , $coursesCount , 'bp group tab name' , 'buddyboss' ); } /** * 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' ; } return bp_ld_sync( 'settings' )->get( 'buddypress.tab_access' , true); } /** * Should tha tab be shown on the group create screen * * @since BuddyBoss 1.0.0 */ protected function showTabOnCreate() { return bp_ld_sync( 'settings' )->get( 'buddypress.show_in_bp_create' , true); } } |
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
- settings_screen — Displays the settings for all views
- settings_screen_save — Saving the settings for all views
- showTabOnCreate — Should tha tab be shown on the group create screen
- showTabOnView — Determine who can see the tab
- tabLabel — Return the tab label with proper nonce
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.