bp_core_admin_components_options

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

Description

bp_core_admin_components_options(); 

Usage

  1. if ( !function_exists( 'bp_core_admin_components_options' ) ) { 
  2. require_once '/bp-core/admin/bp-core-admin-components.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_core_admin_components_options(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-core/admin/bp-core-admin-components.php  
  1. function bp_core_admin_components_options() { 
  2.  
  3. // Declare local variables. 
  4. $deactivated_components = array(); 
  5.  
  6. /** 
  7. * Filters the array of available components. 
  8. * @since 1.5.0 
  9. * @param mixed $value Active components. 
  10. */ 
  11. $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) ); 
  12.  
  13. // The default components (if none are previously selected). 
  14. $default_components = array( 
  15. 'xprofile' => array( 
  16. 'title' => __( 'Extended Profiles', 'buddypress' ),  
  17. 'description' => __( 'Customize your community with fully editable profile fields that allow your users to describe themselves.', 'buddypress' ) 
  18. ),  
  19. 'settings' => array( 
  20. 'title' => __( 'Account Settings', 'buddypress' ),  
  21. 'description' => __( 'Allow your users to modify their account and notification settings directly from within their profiles.', 'buddypress' ) 
  22. ),  
  23. 'notifications' => array( 
  24. 'title' => __( 'Notifications', 'buddypress' ),  
  25. 'description' => __( 'Notify members of relevant activity with a toolbar bubble and/or via email, and allow them to customize their notification settings.', 'buddypress' ) 
  26. ),  
  27. ); 
  28.  
  29. $optional_components = bp_core_admin_get_components( 'optional' ); 
  30. $required_components = bp_core_admin_get_components( 'required' ); 
  31. $retired_components = bp_core_admin_get_components( 'retired' ); 
  32.  
  33. // Don't show Forums component in optional components if it's disabled. 
  34. if ( ! bp_is_active( 'forums' ) ) { 
  35. unset( $optional_components['forums'] ); 
  36.  
  37. // Merge optional and required together. 
  38. $all_components = $optional_components + $required_components; 
  39.  
  40. // If this is an upgrade from before BuddyPress 1.5, we'll have to convert 
  41. // deactivated components into activated ones. 
  42. if ( empty( $active_components ) ) { 
  43. $deactivated_components = bp_get_option( 'bp-deactivated-components' ); 
  44. if ( !empty( $deactivated_components ) ) { 
  45.  
  46. // Trim off namespace and filename. 
  47. $trimmed = array(); 
  48. foreach ( array_keys( (array) $deactivated_components ) as $component ) { 
  49. $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) ); 
  50.  
  51. // Loop through the optional components to create an active component array. 
  52. foreach ( array_keys( (array) $optional_components ) as $ocomponent ) { 
  53. if ( !in_array( $ocomponent, $trimmed ) ) { 
  54. $active_components[$ocomponent] = 1; 
  55.  
  56. // On new install, set active components to default. 
  57. if ( empty( $active_components ) ) { 
  58. $active_components = $default_components; 
  59.  
  60. // Core component is always active. 
  61. $active_components['core'] = $all_components['core']; 
  62. $inactive_components = array_diff( array_keys( $all_components ) , array_keys( $active_components ) ); 
  63.  
  64. /** Display ************************************************************** 
  65. */ 
  66.  
  67. // Get the total count of all plugins. 
  68. $all_count = count( $all_components ); 
  69. $page = bp_core_do_network_admin() ? 'settings.php' : 'options-general.php'; 
  70. $action = !empty( $_GET['action'] ) ? $_GET['action'] : 'all'; 
  71.  
  72. switch( $action ) { 
  73. case 'all' : 
  74. $current_components = $all_components; 
  75. break; 
  76. case 'active' : 
  77. foreach ( array_keys( $active_components ) as $component ) { 
  78. $current_components[$component] = $all_components[$component]; 
  79. break; 
  80. case 'inactive' : 
  81. foreach ( $inactive_components as $component ) { 
  82. $current_components[$component] = $all_components[$component]; 
  83. break; 
  84. case 'mustuse' : 
  85. $current_components = $required_components; 
  86. break; 
  87. case 'retired' : 
  88. $current_components = $retired_components; 
  89. break; 
  90. } ?> 
  91.  
  92. <h3 class="screen-reader-text"><?php 
  93. /** translators: accessibility text */ 
  94. _e( 'Filter components list', 'buddypress' ); 
  95. ?></h3> 
  96.  
  97. <ul class="subsubsub"> 
  98. <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( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $all_count, 'plugins', 'buddypress' ), number_format_i18n( $all_count ) ); ?></a> | </li> 
  99. <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 ), 'buddypress' ), number_format_i18n( count( $active_components ) ) ); ?></a> | </li> 
  100. <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 ), 'buddypress' ), number_format_i18n( count( $inactive_components ) ) ); ?></a> | </li> 
  101. <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( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', count( $required_components ), 'buddypress' ), number_format_i18n( count( $required_components ) ) ); ?></a> | </li> 
  102. <li><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bp-components', 'action' => 'retired' ), bp_get_admin_url( $page ) ) ); ?>" <?php if ( $action === 'retired' ) : ?>class="current"<?php endif; ?>><?php printf( _n( 'Retired <span class="count">(%s)</span>', 'Retired <span class="count">(%s)</span>', count( $retired_components ), 'buddypress' ), number_format_i18n( count( $retired_components ) ) ); ?></a></li> 
  103. </ul> 
  104.  
  105. <h3 class="screen-reader-text"><?php 
  106. /** translators: accessibility text */ 
  107. _e( 'Components list', 'buddypress' ); 
  108. ?></h3> 
  109.  
  110. <table class="wp-list-table widefat plugins"> 
  111. <thead> 
  112. <tr> 
  113. <td id="cb" class="manage-column column-cb check-column"><input id="cb-select-all-1" type="checkbox" disabled><label class="screen-reader-text" for="cb-select-all-1"><?php 
  114. /** translators: accessibility text */ 
  115. _e( 'Bulk selection is disabled', 'buddypress' ); 
  116. ?></label></td> 
  117. <th scope="col" id="name" class="manage-column column-title column-primary"><?php _e( 'Component', 'buddypress' ); ?></th> 
  118. <th scope="col" id="description" class="manage-column column-description"><?php _e( 'Description', 'buddypress' ); ?></th> 
  119. </tr> 
  120. </thead> 
  121.  
  122. <tbody id="the-list"> 
  123.  
  124. <?php if ( !empty( $current_components ) ) : ?> 
  125.  
  126. <?php foreach ( $current_components as $name => $labels ) : ?> 
  127.  
  128. <?php if ( !in_array( $name, array( 'core', 'members' ) ) ) : 
  129. $class = isset( $active_components[esc_attr( $name )] ) ? 'active' : 'inactive'; 
  130. else : 
  131. $class = 'active'; 
  132. endif; ?> 
  133.  
  134. <tr id="<?php echo esc_attr( $name ); ?>" class="<?php echo esc_attr( $name ) . ' ' . esc_attr( $class ); ?>"> 
  135. <th scope="row" class="check-column"> 
  136.  
  137. <?php if ( !in_array( $name, array( 'core', 'members' ) ) ) : ?> 
  138.  
  139. <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 
  140. /** translators: accessibility text */ 
  141. printf( __( 'Select %s', 'buddypress' ), esc_html( $labels['title'] ) ); ?></label> 
  142.  
  143. <?php else : ?> 
  144.  
  145. <input type="checkbox" id="<?php echo esc_attr( "bp_components[$name]" ); ?>" name="<?php echo esc_attr( "bp_components[$name]" ); ?>" value="1" checked="checked" disabled><label for="<?php echo esc_attr( "bp_components[$name]" ); ?>" class="screen-reader-text"><?php 
  146. /** translators: accessibility text */ 
  147. printf( __( '%s is a required component', 'buddypress' ), esc_html( $labels['title'] ) ); ?></label> 
  148.  
  149. <?php endif; ?> 
  150.  
  151. </th> 
  152. <td class="plugin-title column-primary"> 
  153. <span aria-hidden="true"></span> 
  154. <strong><?php echo esc_html( $labels['title'] ); ?></strong> 
  155. </td> 
  156.  
  157. <td class="column-description desc"> 
  158. <div class="plugin-description"> 
  159. <p><?php echo $labels['description']; ?></p> 
  160. </div> 
  161.  
  162. </td> 
  163. </tr> 
  164.  
  165. <?php endforeach ?> 
  166.  
  167. <?php else : ?> 
  168.  
  169. <tr class="no-items"> 
  170. <td class="colspanchange" colspan="3"><?php _e( 'No components found.', 'buddypress' ); ?></td> 
  171. </tr> 
  172.  
  173. <?php endif; ?> 
  174.  
  175. </tbody> 
  176.  
  177. <tfoot> 
  178. <tr> 
  179. <td class="manage-column column-cb check-column"><input id="cb-select-all-2" type="checkbox" disabled><label class="screen-reader-text" for="cb-select-all-2"><?php 
  180. /** translators: accessibility text */ 
  181. _e( 'Bulk selection is disabled', 'buddypress' ); 
  182. ?></label></td> 
  183. <th class="manage-column column-title column-primary"><?php _e( 'Component', 'buddypress' ); ?></th> 
  184. <th class="manage-column column-description"><?php _e( 'Description', 'buddypress' ); ?></th> 
  185. </tr> 
  186. </tfoot> 
  187.  
  188. </table> 
  189.  
  190. <input type="hidden" name="bp_components[members]" value="1" /> 
  191.  
  192. <?php