BP_Nouveau_Groups

Groups Loader class

Description

Source

File: bp-templates/bp-nouveau/includes/groups/loader.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
class BP_Nouveau_Groups {
    /**
     * Constructor
     *
     * @since BuddyPress 3.0.0
     */
    public function __construct() {
        $this->setup_globals();
        $this->includes();
        $this->setup_actions();
        $this->setup_filters();
    }
 
    /**
     * Globals
     *
     * @since BuddyPress 3.0.0
     */
    protected function setup_globals() {
        $this->dir                   = trailingslashit( dirname( __FILE__ ) );
        $this->is_group_home_sidebar = false;
    }
 
    /**
     * Include needed files
     *
     * @since BuddyPress 3.0.0
     */
    protected function includes() {
        require $this->dir . 'functions.php';
        require $this->dir . 'classes.php';
        require $this->dir . 'template-tags.php';
 
        // Test suite requires the AJAX functions early.
        if ( function_exists( 'tests_add_filter' ) ) {
            require $this->dir . 'ajax.php';
 
        // Load AJAX code only on AJAX requests.
        } else {
            add_action( 'admin_init', function() {
                if ( defined( 'DOING_AJAX' ) && true === DOING_AJAX && 0 === strpos( $_REQUEST['action'], 'groups_' ) ) {
                    require $this->dir . 'ajax.php';
                }
            } );
        }
    }
 
    /**
     * Register do_action() hooks
     *
     * @since BuddyPress 3.0.0
     */
    protected function setup_actions() {
        if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
            add_action( 'groups_setup_nav', 'bp_nouveau_group_setup_nav' );
        }
 
        add_action( 'bp_nouveau_enqueue_scripts', 'bp_nouveau_groups_enqueue_scripts' );
 
        // Avoid Notices for BuddyPress Legacy Backcompat
        remove_action( 'bp_groups_directory_group_filter', 'bp_group_backcompat_create_nav_item', 1000 );
 
        // Register the Groups Notifications filters
        add_action( 'bp_nouveau_notifications_init_filters', 'bp_nouveau_groups_notification_filters' );
 
        // Actions to check whether we are in the Group's default front page sidebar
        add_action( 'dynamic_sidebar_before', array( $this, 'group_home_sidebar_set' ), 10, 1 );
        add_action( 'dynamic_sidebar_after', array( $this, 'group_home_sidebar_unset' ), 10, 1 );
 
        // Add a new nav item to settings to let users choose their group invites preferences
        if ( bp_is_active( 'friends' ) && ! bp_nouveau_groups_disallow_all_members_invites() ) {
            add_action( 'bp_settings_setup_nav', 'bp_nouveau_groups_invites_restriction_nav' );
        }
    }
 
    /**
     * Register add_filter() hooks
     *
     * @since BuddyPress 3.0.0
     */
    protected function setup_filters() {
        add_filter( 'bp_nouveau_register_scripts', 'bp_nouveau_groups_register_scripts', 10, 1 );
        add_filter( 'bp_core_get_js_strings', 'bp_nouveau_groups_localize_scripts', 10, 1 );
        add_filter( 'groups_create_group_steps', 'bp_nouveau_group_invites_create_steps', 10, 1 );
 
        $buttons = array(
            'groups_leave_group',
            'groups_join_group',
            'groups_accept_invite',
            'groups_reject_invite',
            'groups_membership_requested',
            'groups_request_membership',
            'groups_group_membership',
        );
 
        foreach ( $buttons as $button ) {
            add_filter( 'bp_button_' . $button, 'bp_nouveau_ajax_button', 10, 5 );
        }
 
        // Add sections in the BP Template Pack panel of the customizer.
        add_filter( 'bp_nouveau_customizer_sections', 'bp_nouveau_groups_customizer_sections', 10, 1 );
 
        // Add settings into the Groups sections of the customizer.
        add_filter( 'bp_nouveau_customizer_settings', 'bp_nouveau_groups_customizer_settings', 10, 1 );
 
        // Add controls into the Groups sections of the customizer.
        add_filter( 'bp_nouveau_customizer_controls', 'bp_nouveau_groups_customizer_controls', 10, 1 );
 
        // Add the group's default front template to hieararchy if user enabled it (Enabled by default).
        add_filter( 'bp_groups_get_front_template', 'bp_nouveau_group_reset_front_template', 10, 2 );
 
        // Add a new nav item to settings to let users choose their group invites preferences
        if ( bp_is_active( 'friends' ) && ! bp_nouveau_groups_disallow_all_members_invites() ) {
            add_filter( 'bp_settings_admin_nav', 'bp_nouveau_groups_invites_restriction_admin_nav', 10, 1 );
        }
    }
 
    /**
     * Add filters to be sure the (BuddyBoss) widgets display will be consistent
     * with the current group's default front page.
     *
     * @since BuddyPress 3.0.0
     *
     * @param string $sidebar_index The Sidebar identifier.
     */
    public function group_home_sidebar_set( $sidebar_index = '' ) {
        if ( 'sidebar-buddypress-groups' !== $sidebar_index ) {
            return;
        }
 
        $this->is_group_home_sidebar = true;
 
        // Add needed filters.
        bp_nouveau_groups_add_home_widget_filters();
    }
 
    /**
     * Remove filters to be sure the (BuddyBoss) widgets display will no more take
     * the current group displayed in account.
     *
     * @since BuddyPress 3.0.0
     *
     * @param string $sidebar_index The Sidebar identifier.
     */
    public function group_home_sidebar_unset( $sidebar_index = '' ) {
        if ( 'sidebar-buddypress-groups' !== $sidebar_index ) {
            return;
        }
 
        $this->is_group_home_sidebar = false;
 
        // Remove no more needed filters.
        bp_nouveau_groups_remove_home_widget_filters();
    }
}

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.