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
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
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.