bp_core_admin_components_options()

Creates reusable markup for component setup on the Components and Pages dashboard panel.

Description

Source

File: bp-core/admin/bp-core-admin-components.php

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
function bp_core_admin_components_options() {
 
    // Declare local variables.
    $deactivated_components = array();
 
    /**
     * Filters the array of available components.
     *
     * @since BuddyPress 1.5.0
     *
     * @param mixed $value Active components.
     */
    $active_components      = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
 
    $default_components  = bp_core_admin_get_components( 'default' ); // The default components (if none are previously selected).
    $optional_components = bp_core_admin_get_components( 'optional' );
    $required_components = bp_core_admin_get_components( 'required' );
 
    if ( isset( $optional_components['blogs'] ) ) {
        unset( $optional_components['blogs'] );
    }
 
    // Merge optional and required together.
    $all_components = $required_components + $optional_components;
 
    // If this is an upgrade from before BuddyPress 1.5, we'll have to convert
    // deactivated components into activated ones.
    if ( empty( $active_components ) ) {
        $deactivated_components = bp_get_option( 'bp-deactivated-components' );
        if ( !empty( $deactivated_components ) ) {
 
            // Trim off namespace and filename.
            $trimmed = array();
            foreach ( array_keys( (array) $deactivated_components ) as $component ) {
                $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) );
            }
 
            // Loop through the optional components to create an active component array.
            foreach ( array_keys( (array) $optional_components ) as $ocomponent ) {
                if ( !in_array( $ocomponent, $trimmed ) ) {
                    $active_components[$ocomponent] = 1;
                }
            }
        }
    }
 
    // On new install, set active components to default.
    if ( empty( $active_components ) ) {
        $active_components = $default_components;
    }
 
    $inactive_components       = array_diff( array_keys( $all_components ) , array_keys( $active_components ) );
 
    /** Display **************************************************************
     */
 
    // Get the total count of all plugins.
    $all_count = count( $all_components );
    $page      = bp_core_do_network_admin()  ? 'admin.php' : 'admin.php';
    $action    = !empty( $_GET['action'] ) ? $_GET['action'] : 'all';
 
    switch( $action ) {
        case 'all' :
            $current_components = $all_components;
            break;
        case 'active' :
            foreach ( array_keys( $active_components ) as $component ) {
                $current_components[$component] = $all_components[$component];
            }
            break;
        case 'inactive' :
            foreach ( $inactive_components as $component ) {
                $current_components[$component] = $all_components[$component];
            }
            break;
        case 'mustuse' :
            $current_components = $required_components;
            break;
    } ?>
 
    <h3 class="screen-reader-text"><?php
        /* translators: accessibility text */
        _e( 'Filter components list', 'buddyboss' );
    ?></h3>
 
    <ul class="subsubsub">
        <li><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bp-components', 'action' => 'all'      ), bp_get_admin_url( $page ) ) ); ?>" <?php if ( $action === 'all'      ) : ?>class="current"<?php endif; ?>><?php printf( _n( 'All <span class="count">(%s)</span>',      'All <span class="count">(%s)</span>',      $all_count, 'buddyboss' ), number_format_i18n( $all_count                    ) ); ?></a> | </li>
        <li><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bp-components', 'action' => 'active'   ), bp_get_admin_url( $page ) ) ); ?>" <?php if ( $action === 'active'   ) : ?>class="current"<?php endif; ?>><?php printf( _n(  'Active <span class="count">(%s)</span>',   'Active <span class="count">(%s)</span>',   count( $active_components   ), 'buddyboss' ), number_format_i18n( count( $active_components   ) ) ); ?></a> | </li>
        <li><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bp-components', 'action' => 'inactive' ), bp_get_admin_url( $page ) ) ); ?>" <?php if ( $action === 'inactive' ) : ?>class="current"<?php endif; ?>><?php printf( _n(  'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', count( $inactive_components ), 'buddyboss' ), number_format_i18n( count( $inactive_components ) ) ); ?></a> | </li>
        <li><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bp-components', 'action' => 'mustuse'  ), bp_get_admin_url( $page ) ) ); ?>" <?php if ( $action === 'mustuse'  ) : ?>class="current"<?php endif; ?>><?php printf( _n(  'Required <span class="count">(%s)</span>', 'Required <span class="count">(%s)</span>', count( $required_components ), 'buddyboss' ), number_format_i18n( count( $required_components ) ) ); ?></a></li>
    </ul>
 
    <h3 class="screen-reader-text"><?php
        /* translators: accessibility text */
        _e( 'Components list', 'buddyboss' );
    ?></h3>
 
    <div class="tablenav top">
        <div class="alignleft actions bulkactions">
            <label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
            <select name="action" id="bulk-action-selector-top">
                <option value="">Bulk Actions</option>
                <option value="active" class="hide-if-no-js">Activate</option>
                <option value="inactive">Deactivate</option>
            </select>
            <input type="submit" id="doaction" class="button action" name="bp-admin-component-submit" value="Apply">
        </div>
    </div>
    <table class="wp-list-table widefat plugins">
        <thead>
            <tr>
                <td id="cb" class="manage-column column-cb check-column"><input id="cb-select-all-1" type="checkbox" <?php checked( empty( $inactive_components ) ); ?>>
                    <label class="screen-reader-text" for="cb-select-all-1"><?php
                    /* translators: accessibility text */
                    _e( 'Enable or disable all optional components in bulk', 'buddyboss' );
                ?></label></td>
                <th scope="col" id="name" class="manage-column column-title column-primary"><?php _e( 'Component', 'buddyboss' ); ?></th>
                <th scope="col" id="description" class="manage-column column-description"><?php _e( 'Description', 'buddyboss' ); ?></th>
            </tr>
        </thead>
 
        <tbody id="the-list">
 
            <?php if ( !empty( $current_components ) ) : ?>
 
                <?php foreach ( $current_components as $name => $labels ) : ?>
 
                    <?php
                        if ( in_array( $name, array( 'blogs' ) ) ) :
                            $class = isset( $active_components[esc_attr( $name )] ) ? 'active hidden' : 'inactive hidden';
                        elseif ( !in_array( $name, array( 'core', 'members', 'xprofile' ) ) ) :
                            $class = isset( $active_components[esc_attr( $name )] ) ? 'active' : 'inactive';
                        else :
                            $class = 'active';
                        endif;
                    ?>
 
                    <tr id="<?php echo esc_attr( $name ); ?>" class="<?php echo esc_attr( $name ) . ' ' . esc_attr( $class ); ?>">
                        <th scope="row" class="check-column">
 
                            <?php if ( !in_array( $name, array( 'core', 'members', 'xprofile' ) ) ) : ?>
 
                                <input type="checkbox" id="<?php echo esc_attr( "bp_components[$name]" ); ?>" name="<?php echo esc_attr( "bp_components[$name]" ); ?>" value="1"<?php checked( isset( $active_components[esc_attr( $name )] ) ); ?> /><label for="<?php echo esc_attr( "bp_components[$name]" ); ?>" class="screen-reader-text"><?php
                                    /* translators: accessibility text */
                                    printf( __( 'Select %s', 'buddyboss' ), esc_html( $labels['title'] ) ); ?></label>
 
                            <?php endif; ?>
 
                        </th>
                        <td class="plugin-title column-primary">
                            <label for="<?php echo esc_attr( "bp_components[$name]" ); ?>">
                                <span aria-hidden="true"></span>
                                <strong><?php echo esc_html( $labels['title'] ); ?></strong>
                            </label>
                            <div class="row-actions visible">
                                <?php if ( in_array( $name, array( 'core', 'members', 'xprofile' ) ) ) : ?>
                                    <span class="required">
                                        <?php _e( 'Required', 'buddyboss' ); ?>
                                    </span>
                                <?php elseif ( ! in_array( $name, array( 'core', 'members', 'xprofile' ) ) ) : ?>
                                    <?php if ( isset( $active_components[esc_attr( $name )] ) ) : ?>
                                        <span class="deactivate">
                                            <a href="<?php echo wp_nonce_url( bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components', 'action' => $action, 'bp_component' => $name, 'do_action' => 'deactivate' ) , $page ) ), 'bp-admin-component-activation' ); ?>">
                                                <?php _e( 'Deactivate', 'buddyboss' ); ?>
                                            </a>
                                        </span>
                                    <?php else: ?>
                                        <span class="activate">
                                            <a href="<?php echo wp_nonce_url( bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components', 'action' => $action, 'bp_component' => $name, 'do_action' => 'activate' ) , $page ) ), 'bp-admin-component-activation' ); ?>">
                                                <?php _e( 'Activate', 'buddyboss' ); ?>
                                            </a>
                                        </span>
                                    <?php endif; ?>
                                <?php endif; ?>
                                <?php if ( isset( $active_components[esc_attr( $name )] ) && ! empty( $labels['settings'] ) ) : ?>
                                    <span><?php _e( '|', 'buddyboss' ); ?></span>
                                    <span class="settings">
                                        <a href="<?php echo esc_url( $labels['settings'] ); ?>">
                                            <?php
                                                if ( 'xprofile' === $name ) {
                                                    _e( 'Edit Fields', 'buddyboss' );
                                                } else {
                                                    _e( 'Settings', 'buddyboss' );
                                                }
                                            ?>
                                        </a>
                                    </span>
                                <?php endif; ?>
                            </div>
                        </td>
 
                        <td class="column-description desc">
                            <div class="plugin-description">
                                <p><?php echo $labels['description']; ?></p>
                            </div>
 
                        </td>
                    </tr>
 
                <?php endforeach ?>
 
            <?php else : ?>
 
                <tr class="no-items">
                    <td class="colspanchange" colspan="3"><?php _e( 'No components found.', 'buddyboss' ); ?></td>
                </tr>
 
            <?php endif; ?>
 
        </tbody>
 
        <tfoot>
            <tr>
                <td class="manage-column column-cb check-column"><input id="cb-select-all-2" type="checkbox" <?php checked( empty( $inactive_components ) ); ?>>
                    <label class="screen-reader-text" for="cb-select-all-2"><?php
                    /* translators: accessibility text */
                    _e( 'Enable or disable all optional components in bulk', 'buddyboss' );
                ?></label></td>
                <th class="manage-column column-title column-primary"><?php _e( 'Component', 'buddyboss' ); ?></th>
                <th class="manage-column column-description"><?php _e( 'Description', 'buddyboss' ); ?></th>
            </tr>
        </tfoot>
 
    </table>
 
    <input type="hidden" name="bp_components[members]" value="1" />
    <input type="hidden" name="bp_components[xprofile]" value="1" />
 
    <div class="tablenav bottom">
        <div class="alignleft actions bulkactions">
            <label for="bulk-action-selector-top" class="screen-reader-text"><?php _e( 'Select bulk action', 'buddyboss' ); ?></label>
            <select name="action2" id="bulk-action-selector-top">
                <option value=""><?php _e( 'Bulk Actions', 'buddyboss' ); ?></option>
                <option value="active" class="hide-if-no-js"><?php _e( 'Activate', 'buddyboss' ); ?></option>
                <option value="inactive"><?php _e( 'Deactivate', 'buddyboss' ); ?></option>
            </select>
            <input type="submit" id="doaction" class="button action" name="bp-admin-component-submit" value="Apply">
        </div>
    </div>
    <?php
}

Changelog

Changelog
Version Description
BuddyPress 1.6.0 Introduced.

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.