BP_LearnDash_Admin_Integration_Tab

Setup the BuddyBoss LearnDash admin tab.

Description

Source

File: bp-integrations/learndash/bp-admin-learndash-tab.php

17
18
19
20
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
class BP_LearnDash_Admin_Integration_Tab extends BP_Admin_Integration_tab {
    protected $current_section;
 
    /**
     * Initialize Admin Integration Tab
     *
     * @since BuddyBoss 1.0.0
     */
    public function initialize() {
        $this->tab_order = 20;
        $this->intro_template = $this->root_path . '/templates/admin/integration-tab-intro.php';
    }
 
    /**
     * Save learndash settings with setting helper class
     *
     * @since BuddyBoss 1.0.0
     */
    public function settings_save() {
        $settings = bp_ld_sync('settings');
 
        if ($values = bp_ld_sync()->getRequest($settings->getName())) {
            $settings->set(null, $values)->update();
        }
    }
 
    /**
     * Register setting fields
     *
     * @since BuddyBoss 1.0.0
     */
    public function register_fields() {
 
        $fields = apply_filters('bp_integrations_learndash_fields', array(
            'buddypress' => [$this, 'registerBuddypressSettings'],
            'learndash' => [$this, 'registerLearnDashSettings'],
            //'reports' => [$this, 'registerReportsSettings'],
        ), $this);
 
        foreach ($fields as $key => $callback) {
            call_user_func($callback);
 
            /**
             * Action to add additional fields into each learndash setting sections
             *
             * @since BuddyBoss 1.0.0
             */
            do_action('bp_integrations_learndash_field_added', $key, $this);
        }
    }
 
    /**
     * Load the settings html
     *
     * @since BuddyBoss 1.0.0
     */
    public function form_html() {
        // Check Group component active.
        if (!bp_is_active('groups')) {
            if (is_file($this->intro_template)) {
                require $this->intro_template;
            }
 
            return;
        }
 
        parent::form_html();
    }
 
    /**
     * Register Buddypress related settings
     *
     * @since BuddyBoss 1.0.0
     */
    public function registerBuddypressSettings() {
        $this->current_section = 'buddypress';
 
        $this->add_section(
            'bp_ld_sync-buddypress',
            __('Social groups <span>&rarr; LearnDash groups</span>', 'buddyboss')
        );
 
        $this->add_checkbox_field(
            'enabled',
            __('Social Group Sync', 'buddyboss'),
            [
                'input_text' => sprintf(
                    __('Enable group sync functionality <b>FROM</b> <a href="%s">BuddyBoss Social Groups</a> <b>TO</b> <a href="%s">LearnDash Groups</a>', 'buddyboss'),
                    add_query_arg([
                        'page' => 'bp-groups',
                    ], admin_url('admin.php')),
                    add_query_arg([
                        'post_type' => 'groups',
                    ], admin_url('edit.php'))
                ),
                'input_run_js' => 'buddypress_enabled',
            ]
        );
 
        $this->add_checkbox_field(
            'show_in_bp_create',
            __('Create LearnDash Group', 'buddyboss'),
            [
                'input_text' => __('Allow social group organizers to create associated LearnDash groups during the group creation process', 'buddyboss'),
                'input_run_js' => 'buddypress_show_in_bp_create',
                'class' => 'js-show-on-buddypress_enabled',
            ]
        );
 
        $this->add_checkbox_field(
            'show_in_bp_manage',
            __('Manage LearnDash Group', 'buddyboss'),
            [
                'input_text' => __('Allow social group organizers to manage associated LearnDash groups after the group creation process', 'buddyboss'),
                'class' => 'js-show-on-buddypress_enabled',
            ]
        );
 
        $this->add_select_field(
            'tab_access',
            __('Course Tab Visibility', 'buddyboss'),
            [
                'input_options' => [
                    'anyone' => __('Anyone', 'buddyboss'),
                    'loggedin' => __('Loggedin Users', 'buddyboss'),
                    'member' => __('Group Members', 'buddyboss'),
                    'noone' => __('No one', 'buddyboss'),
                ],
                'input_default' => 'admin',
                'input_description' => __('Select who can see the course tab in social groups', 'buddyboss'),
                'class' => 'js-show-on-buddypress_enabled',
            ]
        );
 
        $this->add_checkbox_field(
            'default_auto_sync',
            __('Auto Create LearnDash Group', 'buddyboss'),
            [
                'input_text' => __('Automatically create and associate a LearnDash group upon creation', 'buddyboss'),
                'input_description' => __('Required if you want an associated LearnDash group, and course tab is disabled during creation', 'buddyboss'),
                'class' => 'js-show-on-buddypress_enabled',
            ]
        );
 
        $this->add_checkbox_field(
            'delete_ld_on_delete',
            __('Auto Delete LearnDash Group', 'buddyboss'),
            [
                'input_text' => __('Automatically delete the associated LearnDash group when the social group is deleted', 'buddyboss'),
                'input_description' => __('Uncheck this to delete the group manually', 'buddyboss'),
                'class' => 'js-show-on-buddypress_enabled',
            ]
        );
 
        $this->add_select_field(
            'default_admin_sync_to',
            __('Sync Organizers', 'buddyboss'),
            [
                'input_options' => [
                    'admin' => __('Group Leader', 'buddyboss'),
                    'user' => __('Group User', 'buddyboss'),
                    'none' => __('None', 'buddyboss'),
                ],
                'input_default' => 'admin',
                'input_description' => __('Social group "Organizers" will be assigned to the above role in LearnDash groups', 'buddyboss'),
                'class' => 'js-show-on-buddypress_enabled',
            ]
        );
 
        $this->add_select_field(
            'default_mod_sync_to',
            __('Sync Moderators', 'buddyboss'),
            [
                'input_options' => [
                    'admin' => __('Group Leader', 'buddyboss'),
                    'user' => __('Group User', 'buddyboss'),
                    'none' => __('None', 'buddyboss'),
                ],
                'input_default' => 'admin',
                'input_description' => __('Social group "Moderators" will be assigned to the above role in LearnDash groups', 'buddyboss'),
                'class' => 'js-show-on-buddypress_enabled',
            ]
        );
 
        $this->add_select_field(
            'default_user_sync_to',
            __('Sync Members', 'buddyboss'),
            [
                'input_options' => [
                    'user' => __('Group User', 'buddyboss'),
                    'none' => __('None', 'buddyboss'),
                ],
                'input_default' => 'user',
                'input_description' => __('Social group "Members" will be assigned to the above role in LearnDash groups', 'buddyboss'),
                'class' => 'js-show-on-buddypress_enabled',
            ]
        );
 
        // Register View Tutorial button.
        $this->add_field( 'bp-privacy-tutorial-bb-to-ld-sync','', [$this, 'bp_privacy_tutorial_bb_to_ld_sync' ] );
    }
 
    /**
     * Register View Tutorial button.
     *
     * @since BuddyBoss 1.0.0
     */
    public function bp_privacy_tutorial_bb_to_ld_sync() {
        ?>
 
        <p>
            <a class="button" href="<?php echo bp_core_help_docs_link( 'integrations/learndash/courses-with-social-groups.md' ); ?>"><?php _e( 'View Tutorial', 'buddyboss' ); ?></a>
        </p>
 
        <?php
    }
 
    /**
     * Register LearnDash related settings
     *
     * @since BuddyBoss 1.0.0
     */
    public function registerLearnDashSettings() {
        $this->current_section = 'learndash';
 
        $this->add_section(
            'bp_ld_sync-learndash',
            __('LearnDash groups <span>&rarr; Social groups</span>', 'buddyboss')
        );
 
        $this->add_checkbox_field(
            'enabled',
            __('LearnDash Group Sync', 'buddyboss'),
            [
                'input_text' => sprintf(
                    __('Enable group sync functionality <b>FROM</b> <a href="%s">LearnDash Groups</a> <b>TO</b> <a href="%s">BuddyBoss Social Groups</a>', 'buddyboss'),
                    add_query_arg([
                        'post_type' => 'groups',
                    ], admin_url('edit.php')),
                    add_query_arg([
                        'page' => 'bp-groups',
                    ], admin_url('admin.php'))
                ),
                'input_run_js' => 'learndash_enabled',
            ]
        );
 
        $this->add_checkbox_field(
            'default_auto_sync',
            __('Auto Create Social Group', 'buddyboss'),
            [
                'input_text' => __('Automatically create and associate a Social Group upon creation', 'buddyboss'),
                'class' => 'js-show-on-learndash_enabled',
            ]
        );
 
        $this->add_select_field(
            'default_bp_privacy',
            __('Social Group Privacy', 'buddyboss'),
            [
                'input_options' => [
                    'public' => __('Public', 'buddyboss'),
                    'private' => __('Private', 'buddyboss'),
                    'hidden' => __('Hidden', 'buddyboss'),
                ],
                'input_default' => 'private',
                'input_description' => __('Select the default social group Privacy setting upon creation', 'buddyboss'),
                'class' => 'js-show-on-learndash_enabled',
            ]
        );
 
        $this->add_select_field(
            'default_bp_invite_status',
            __('Social Group Invite Status', 'buddyboss'),
            [
                'input_options' => [
                    'members' => __('All group members', 'buddyboss'),
                    'mods' => __('Group organizers and moderators only', 'buddyboss'),
                    'admins' => __('Group organizers only', 'buddyboss'),
                ],
                'input_default' => 'mods',
                'input_description' => __('Select which group members can invite others to join the group', 'buddyboss'),
                'class' => 'js-show-on-learndash_enabled',
            ]
        );
 
        $this->add_checkbox_field(
            'delete_bp_on_delete',
            __('Auto Delete Social Group', 'buddyboss'),
            [
                'input_text' => __('Automatically delete the associated Social Group when the LearnDash group is deleted', 'buddyboss'),
                'class' => 'js-show-on-learndash_enabled',
            ]
        );
 
        $this->add_select_field(
            'default_admin_sync_to',
            __('Sync Leaders', 'buddyboss'),
            [
                'input_options' => [
                    'admin' => __('Organizer', 'buddyboss'),
                    'mod' => __('Moderator', 'buddyboss'),
                    'user' => __('Member', 'buddyboss'),
                    'none' => __('None', 'buddyboss'),
                ],
                'input_default' => 'admin',
                'input_description' => __('LearnDash "Group Leaders" will be assigned to the above role in social groups', 'buddyboss'),
                'class' => 'js-show-on-learndash_enabled',
            ]
        );
 
        $this->add_select_field(
            'default_user_sync_to',
            __('Sync Users', 'buddyboss'),
            [
                'input_options' => [
                    'admin' => __('Organizer', 'buddyboss'),
                    'mod' => __('Moderator', 'buddyboss'),
                    'user' => __('Member', 'buddyboss'),
                    'none' => __('None', 'buddyboss'),
                ],
                'input_default' => 'user',
                'input_description' => __('LearnDash "Group Users" will be assigned to the above role in social groups', 'buddyboss'),
                'class' => 'js-show-on-learndash_enabled',
            ]
        );
 
        // Register View Tutorial button.
        $this->add_field( 'bp-privacy-tutorial-ld-to-bb-sync','', [$this, 'bp_privacy_tutorial_ld_to_bb_sync' ] );
    }
 
    /**
     * Register View Tutorial button.
     *
     * @since BuddyBoss 1.0.0
     */
    public function bp_privacy_tutorial_ld_to_bb_sync() {
        ?>
 
        <p>
            <a class="button" href="<?php echo bp_core_help_docs_link( 'integrations/learndash/courses-with-social-groups.md' ); ?>"><?php _e( 'View Tutorial', 'buddyboss' ); ?></a>
        </p>
 
        <?php
    }
 
    /**
     * Register reports related settings
     *
     * @since BuddyBoss 1.0.0
     */
    public function registerReportsSettings() {
        $this->current_section = 'reports';
 
        /**
         * Hide the report section from platform
         */
        $this->add_section(
            'bp_ld_sync-reports',
            __('Group Reports Settings', 'buddyboss'),
            [$this, 'learndash_groups_report_description']
        );
 
        $this->add_checkbox_field(
            'enabled',
            __('Group Reports', 'buddyboss'),
            [
                'input_text' => __('Enable Social Group Report for LearnDash', 'buddyboss'),
                'input_run_js' => 'reports_enabled',
            ]
        );
 
        $this->add_field(
            'access',
            __('Report Access', 'buddyboss'),
            [$this, 'output_report_access_setting'],
            [],
            [
                'class' => 'js-show-on-reports_enabled',
            ]
        );
 
        $this->add_input_field(
            'per_page',
            __('Report Results Per Page', 'buddyboss'),
            [
                'input_type' => 'number',
                'input_description' => __('Number of report results displayed per page', 'buddyboss'),
                'class' => 'js-show-on-reports_enabled',
            ]
        );
    }
 
    /**
     * Description for reports setting section
     *
     * @since BuddyBoss 1.0.0
     */
    public function learndash_groups_report_description() {
        echo wpautop(
            __('Control the setting for social group\'s reports.', 'buddyboss')
        );
    }
 
    /**
     * Dropdown options for report aceess setting
     *
     * @since BuddyBoss 1.0.0
     */
    public function output_report_access_setting() {
        $input_field = 'access';
        $input_value = $this->get_input_value($input_field, []);
        $input_name = $this->get_input_name($input_field);
        $input_options = [
            'admin' => __('Organizers', 'buddyboss'),
            'mod' => __('Moderators', 'buddyboss'),
            'member' => __('Members', 'buddyboss'),
        ];
 
        foreach ($input_options as $key => $value) {
            $checked = in_array($key, $input_value) ? 'checked' : '';
            printf('
                <p>
                    <label>
                        <input type="checkbox" name="%s[]" value="%s" %s>%s</option>
                    </label>
                </p>
            ', $input_name, $key, $checked, $value);
        }
 
        echo $this->render_input_description(__('Select which roles can view reports', 'buddyboss'));
    }
 
    /**
     * Overwrite the input name
     *
     * @since BuddyBoss 1.0.0
     */
    protected function get_input_name($name) {
        return bp_ld_sync('settings')->getName("{$this->current_section}.{$name}");
    }
 
    /**
     * Overwrite the input value
     *
     * @since BuddyBoss 1.0.0
     */
    protected function get_input_value($key, $default = '') {
        return bp_ld_sync('settings')->get("{$this->current_section}.{$key}", $default);
    }
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Methods

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.