BP_Nouveau_Customizer_Group_Nav

A specific Group Nav class to make it possible to set new positions for buddypress()->groups->nav.

Description

Source

File: bp-templates/bp-nouveau/includes/groups/classes.php

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
class BP_Nouveau_Customizer_Group_Nav extends BP_Core_Nav {
    /**
     * Constructor
     *
     * @param int $object_id Optional. The random group ID used to generate the nav.
     */
    public function __construct( $object_id = 0 ) {
        $error = new WP_Error( 'missing_parameter' );
 
        if ( empty( $object_id ) || ! bp_current_user_can( 'bp_moderate' ) || ! did_action( 'admin_init' ) ) {
            return $error;
        }
 
        $group = groups_get_group( array( 'group_id' => $object_id ) );
        if ( empty( $group->id ) ) {
            return $error;
        }
 
        $this->group = $group;
 
        parent::__construct( $group->id );
        $this->setup_nav();
    }
 
    /**
     * Checks whether a property is set.
     *
     * Overrides BP_Core_Nav::__isset() to avoid looking into its nav property.
     *
     * @since BuddyPress 3.0.0
     *
     * @param string $key The property.
     *
     * @return bool True if the property is set, false otherwise.
     */
    public function __isset( $key ) {
        return isset( $this->{$key} );
    }
 
    /**
     * Gets a property.
     *
     * Overrides BP_Core_Nav::__isset() to avoid looking into its nav property.
     *
     * @since BuddyPress 3.0.0
     *
     * @param string $key The property.
     *
     * @return mixed The value corresponding to the property.
     */
    public function __get( $key ) {
        if ( ! isset( $this->{$key} ) ) {
            $this->{$key} = null;
        }
 
        return $this->{$key};
    }
 
    /**
     * Sets a property.
     *
     * Overrides BP_Core_Nav::__isset() to avoid adding a value to its nav property.
     *
     * @since BuddyPress 3.0.0
     *
     * @param string $key The property.
     *
     * @param mixed $value The value of the property.
     */
    public function __set( $key, $value ) {
        $this->{$key} = $value;
    }
 
    /**
     * Setup a temporary nav with only the needed parameters.
     *
     * @since BuddyPress 3.0.0
     */
    protected function setup_nav() {
        $nav_items = array(
            'root'    => array(
                'name'                => __( 'My Groups', 'buddyboss' ),
                'slug'                => $this->group->slug,
                'position'            => -1,
                /** This filter is documented in bp-groups/classes/class-bp-groups-component.php. */
                'default_subnav_slug' => apply_filters( 'bp_groups_default_extension', defined( 'BP_GROUPS_DEFAULT_EXTENSION' ) ? BP_GROUPS_DEFAULT_EXTENSION : 'home' ),
            ),
            'members'    => array(
                'name'        => __( 'Members', 'buddyboss' ),
                'slug'        => 'members',
                'parent_slug' => $this->group->slug,
                'position'    => 10,
            ),
            'invites' => array(
                'name'        => __( 'Send Invites', 'buddyboss' ),
                'slug'        => 'send-invites',
                'parent_slug' => $this->group->slug,
                'position'    => 70,
            ),
            'manage'  => array(
                'name'        => __( 'Manage', 'buddyboss' ),
                'slug'        => 'admin',
                'parent_slug' => $this->group->slug,
                'position'    => 1000,
            ),
        );
 
        if ( bp_is_active( 'forums' ) && function_exists( 'bbp_is_group_forums_active' ) ) {
            if ( bbp_is_group_forums_active() ) {
                $nav_items['forum'] = array(
                    'name'        => __( 'Discussions', 'buddyboss' ),
                    'slug'        => get_option( '_bbp_forum_slug', 'forum' ),
                    'parent_slug' => $this->group->slug,
                    'position'    => 30,
                );
            }
        }
 
        if ( bp_enable_group_hierarchies() ) {
            $nav_items['subgroups'] = array(
                'name'        => __( 'Subgroups', 'buddyboss' ),
                'slug'        => 'subgroups',
                'parent_slug' => $this->group->slug,
                'position'    => 30,
            );
        }
 
        if ( function_exists( 'bp_ld_sync' ) ) {
            $va = bp_ld_sync( 'settings' )->get( 'buddypress.enabled', true );
            if ( '1' === $va ) {
                $nav_items['courses'] = array(
                    'name'        => __( 'Courses', 'buddyboss' ),
                    'slug'        => 'courses',
                    'parent_slug' => $this->group->slug,
                    'position'    => 40,
                );
            }
        }
 
        if ( function_exists( 'bp_ld_sync' ) ) {
            $va = bp_ld_sync( 'settings' )->get( 'reports.enabled', true );
            if ( '1' === $va ) {
                $nav_items['reports'] = array(
                    'name'        => __( 'Reports', 'buddyboss' ),
                    'slug'        => 'reports',
                    'parent_slug' => $this->group->slug,
                    'position'    => 40,
                );
            }
        }
 
        if ( bp_is_active( 'activity' ) ) {
            $nav_items['activity'] = array(
                'name'        => __( 'Feed', 'buddyboss' ),
                'slug'        => 'activity',
                'parent_slug' => $this->group->slug,
                'position'    => 20,
            );
        }
 
        // Required params
        $required_params = array(
            'slug'              => true,
            'name'              => true,
            'nav_item_position' => true,
        );
 
        // Now find nav items plugins are creating within their Group extensions!
        foreach ( get_declared_classes() as $class ) {
            if ( is_subclass_of( $class, 'BP_Group_Extension' ) ) {
                $extension = new $class;
 
                if ( ! empty( $extension->params ) && ! array_diff_key( $required_params, $extension->params ) ) {
                    $nav_items[ $extension->params['slug'] ] = array(
                        'name'        => $extension->params['name'],
                        'slug'        => $extension->params['slug'],
                        'parent_slug' => $this->group->slug,
                        'position'    => $extension->params['nav_item_position'],
                    );
                }
            }
        }
 
        // Now we got all, create the temporary nav.
        foreach ( $nav_items as $nav_item ) {
            $this->add_nav( $nav_item );
        }
    }
 
    /**
     * Front template: do not look into group's template hierarchy.
     *
     * @since BuddyPress 3.0.0
     *
     * @param array $templates The list of possible group front templates.
     *
     * @return array The list of "global" group front templates.
     */
    public function all_groups_fronts( $templates = array() ) {
        return array_intersect( array(
            'groups/single/front.php',
            'groups/single/default-front.php',
        ), $templates );
    }
 
    /**
     * Get the original order for the group navigation.
     *
     * @since BuddyPress 3.0.0
     *
     * @return array a list of nav items slugs ordered.
     */
    public function get_default_value() {
        $default_nav = $this->get_secondary( array( 'parent_slug' => $this->group->slug ) );
        return wp_list_pluck( $default_nav, 'slug' );
    }
 
    /**
     * Get the list of nav items ordered according to the Site owner preferences.
     *
     * @since BuddyPress 3.0.0
     *
     * @return array the nav items ordered.
     */
    public function get_group_nav() {
        // Eventually reset the order
        bp_nouveau_set_nav_item_order( $this, bp_nouveau_get_appearance_settings( 'group_nav_order' ), $this->group->slug );
 
        return $this->get_secondary( array( 'parent_slug' => $this->group->slug ) );
    }
}

Changelog

Changelog
Version Description
BuddyPress 3.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.