[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Admin Component Functions. 4 * 5 * @package BuddyPress 6 * @subpackage CoreAdministration 7 * @since 2.3.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Renders the Component Setup admin panel. 15 * 16 * @since 1.6.0 17 * 18 */ 19 function bp_core_admin_components_settings() { 20 bp_core_admin_tabbed_screen_header( __( 'BuddyPress Settings', 'buddypress' ), __( 'Components', 'buddypress' ) ); 21 ?> 22 23 <div class="buddypress-body"> 24 25 <form action="" method="post" id="bp-admin-component-form"> 26 27 <?php bp_core_admin_components_options(); ?> 28 29 <p class="submit clear"> 30 <input class="button-primary" type="submit" name="bp-admin-component-submit" id="bp-admin-component-submit" value="<?php esc_attr_e( 'Save Settings', 'buddypress' ) ?>"/> 31 </p> 32 33 <?php wp_nonce_field( 'bp-admin-component-setup' ); ?> 34 35 </form> 36 </div> 37 38 <?php 39 } 40 41 /** 42 * Creates reusable markup for component setup on the Components and Pages dashboard panel. 43 * 44 * @since 1.6.0 45 * 46 * @todo Use settings API 47 */ 48 function bp_core_admin_components_options() { 49 50 // Declare local variables. 51 $deactivated_components = array(); 52 53 /** 54 * Filters the array of available components. 55 * 56 * @since 1.5.0 57 * 58 * @param mixed $value Active components. 59 */ 60 $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) ); 61 62 // The default components (if none are previously selected). 63 $default_components = array( 64 'xprofile' => array( 65 'title' => __( 'Extended Profiles', 'buddypress' ), 66 'description' => __( 'Customize your community with fully editable profile fields that allow your users to describe themselves.', 'buddypress' ) 67 ), 68 'settings' => array( 69 'title' => __( 'Account Settings', 'buddypress' ), 70 'description' => __( 'Allow your users to modify their account and notification settings directly from within their profiles.', 'buddypress' ) 71 ), 72 'notifications' => array( 73 'title' => __( 'Notifications', 'buddypress' ), 74 'description' => __( 'Notify members of relevant activity with a toolbar bubble and/or via email, and allow them to customize their notification settings.', 'buddypress' ) 75 ), 76 ); 77 78 $optional_components = bp_core_admin_get_components( 'optional' ); 79 $required_components = bp_core_admin_get_components( 'required' ); 80 $retired_components = bp_core_admin_get_components( 'retired' ); 81 82 // Merge optional and required together. 83 $all_components = $optional_components + $required_components; 84 85 // If this is an upgrade from before BuddyPress 1.5, we'll have to convert 86 // deactivated components into activated ones. 87 if ( empty( $active_components ) ) { 88 $deactivated_components = bp_get_option( 'bp-deactivated-components' ); 89 if ( !empty( $deactivated_components ) ) { 90 91 // Trim off namespace and filename. 92 $trimmed = array(); 93 foreach ( array_keys( (array) $deactivated_components ) as $component ) { 94 $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) ); 95 } 96 97 // Loop through the optional components to create an active component array. 98 foreach ( array_keys( (array) $optional_components ) as $ocomponent ) { 99 if ( !in_array( $ocomponent, $trimmed ) ) { 100 $active_components[$ocomponent] = 1; 101 } 102 } 103 } 104 } 105 106 // On new install, set active components to default. 107 if ( empty( $active_components ) ) { 108 $active_components = $default_components; 109 } 110 111 // Core component is always active. 112 $active_components['core'] = $all_components['core']; 113 $inactive_components = array_diff( array_keys( $all_components ) , array_keys( $active_components ) ); 114 115 /** Display ************************************************************** 116 */ 117 118 // Get the total count of all plugins. 119 $all_count = count( $all_components ); 120 $page = bp_core_do_network_admin() ? 'settings.php' : 'options-general.php'; 121 $action = !empty( $_GET['action'] ) ? $_GET['action'] : 'all'; 122 123 switch( $action ) { 124 case 'all' : 125 $current_components = $all_components; 126 break; 127 case 'active' : 128 foreach ( array_keys( $active_components ) as $component ) { 129 $current_components[$component] = $all_components[$component]; 130 } 131 break; 132 case 'inactive' : 133 foreach ( $inactive_components as $component ) { 134 $current_components[$component] = $all_components[$component]; 135 } 136 break; 137 case 'mustuse' : 138 $current_components = $required_components; 139 break; 140 case 'retired' : 141 $current_components = $retired_components; 142 break; 143 } 144 145 $component_views = array( 146 array( 147 'action' => 'all', 148 'view' => sprintf( 149 /* translators: %s: the number of installed components */ 150 _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $all_count, 'plugins', 'buddypress' ), 151 number_format_i18n( $all_count ) 152 ), 153 ), 154 array( 155 'action' => 'active', 156 'view' => sprintf( 157 /* translators: %s: the number of active components */ 158 _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', count( $active_components ), 'buddypress' ), 159 number_format_i18n( count( $active_components ) ) 160 ), 161 ), 162 array( 163 'action' => 'inactive', 164 'view' => sprintf( 165 /* translators: %s: the number of inactive components */ 166 _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', count( $inactive_components ), 'buddypress' ), 167 number_format_i18n( count( $inactive_components ) ) 168 ), 169 ), 170 array( 171 'action' => 'mustuse', 172 'view' => sprintf( 173 /* translators: %s: the number of must-Use components */ 174 _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', count( $required_components ), 'buddypress' ), 175 number_format_i18n( count( $required_components ) ) 176 ), 177 ), 178 array( 179 'action' => 'retired', 180 'view' => sprintf( 181 /* translators: %s: the number of retired components */ 182 _n( 'Retired <span class="count">(%s)</span>', 'Retired <span class="count">(%s)</span>', count( $retired_components ), 'buddypress' ), 183 number_format_i18n( count( $retired_components ) ) 184 ), 185 ), 186 ); 187 ?> 188 189 <h3 class="screen-reader-text"><?php 190 /* translators: accessibility text */ 191 esc_html_e( 'Filter components list', 'buddypress' ); 192 ?></h3> 193 194 <ul class="subsubsub"> 195 <?php foreach ( $component_views as $component_view ) : ?> 196 <li> 197 <a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bp-components', 'action' => $component_view['action'] ), bp_get_admin_url( $page ) ) ); ?>" <?php if ( $action === $component_view['action'] ) : ?>class="current"<?php endif; ?>> 198 <?php echo wp_kses( $component_view['view'], array( 'span' => array( 'class' => true ) ) ); ?> 199 </a><?php echo 'retired' !== $component_view['action'] ? ' |' : ''; ?> 200 </li> 201 <?php endforeach ;?> 202 </ul> 203 204 <h3 class="screen-reader-text"><?php 205 /* translators: accessibility text */ 206 esc_html_e( 'Components list', 'buddypress' ); 207 ?></h3> 208 209 <table class="wp-list-table widefat plugins"> 210 <thead> 211 <tr> 212 <td id="cb" class="manage-column column-cb check-column"><input id="cb-select-all-1" type="checkbox" <?php checked( empty( $inactive_components ) ); ?>> 213 <label class="screen-reader-text" for="cb-select-all-1"><?php 214 /* translators: accessibility text */ 215 _e( 'Enable or disable all optional components in bulk', 'buddypress' ); 216 ?></label></td> 217 <th scope="col" id="name" class="manage-column column-title column-primary"><?php _e( 'Component', 'buddypress' ); ?></th> 218 <th scope="col" id="description" class="manage-column column-description"><?php _e( 'Description', 'buddypress' ); ?></th> 219 </tr> 220 </thead> 221 222 <tbody id="the-list"> 223 224 <?php if ( !empty( $current_components ) ) : ?> 225 226 <?php foreach ( $current_components as $name => $labels ) : ?> 227 228 <?php if ( !in_array( $name, array( 'core', 'members' ) ) ) : 229 $class = isset( $active_components[esc_attr( $name )] ) ? 'active' : 'inactive'; 230 else : 231 $class = 'active'; 232 endif; ?> 233 234 <tr id="<?php echo esc_attr( $name ); ?>" class="<?php echo esc_attr( $name ) . ' ' . esc_attr( $class ); ?>"> 235 <th scope="row" class="check-column"> 236 237 <?php if ( !in_array( $name, array( 'core', 'members' ) ) ) : ?> 238 239 <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 240 /* translators: accessibility text */ 241 printf( __( 'Select %s', 'buddypress' ), esc_html( $labels['title'] ) ); ?></label> 242 243 <?php endif; ?> 244 245 </th> 246 <td class="plugin-title column-primary"> 247 <label for="<?php echo esc_attr( "bp_components[$name]" ); ?>"> 248 <span aria-hidden="true"></span> 249 <strong><?php echo esc_html( $labels['title'] ); ?></strong> 250 </label> 251 </td> 252 253 <td class="column-description desc"> 254 <div class="plugin-description"> 255 <p><?php echo $labels['description']; ?></p> 256 </div> 257 258 </td> 259 </tr> 260 261 <?php endforeach ?> 262 263 <?php else : ?> 264 265 <tr class="no-items"> 266 <td class="colspanchange" colspan="3"><?php _e( 'No components found.', 'buddypress' ); ?></td> 267 </tr> 268 269 <?php endif; ?> 270 271 </tbody> 272 273 <tfoot> 274 <tr> 275 <td class="manage-column column-cb check-column"><input id="cb-select-all-2" type="checkbox" <?php checked( empty( $inactive_components ) ); ?>> 276 <label class="screen-reader-text" for="cb-select-all-2"><?php 277 /* translators: accessibility text */ 278 _e( 'Enable or disable all optional components in bulk', 'buddypress' ); 279 ?></label></td> 280 <th class="manage-column column-title column-primary"><?php _e( 'Component', 'buddypress' ); ?></th> 281 <th class="manage-column column-description"><?php _e( 'Description', 'buddypress' ); ?></th> 282 </tr> 283 </tfoot> 284 285 </table> 286 287 <input type="hidden" name="bp_components[members]" value="1" /> 288 289 <?php 290 } 291 292 /** 293 * Handle saving the Component settings. 294 * 295 * @since 1.6.0 296 * 297 * @todo Use settings API when it supports saving network settings 298 */ 299 function bp_core_admin_components_settings_handler() { 300 301 // Bail if not saving settings. 302 if ( ! isset( $_POST['bp-admin-component-submit'] ) ) 303 return; 304 305 // Bail if nonce fails. 306 if ( ! check_admin_referer( 'bp-admin-component-setup' ) ) 307 return; 308 309 // Settings form submitted, now save the settings. First, set active components. 310 if ( isset( $_POST['bp_components'] ) ) { 311 312 // Load up BuddyPress. 313 $bp = buddypress(); 314 315 // Save settings and upgrade schema. 316 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 317 require_once( $bp->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' ); 318 319 $submitted = stripslashes_deep( $_POST['bp_components'] ); 320 $bp->active_components = bp_core_admin_get_active_components_from_submitted_settings( $submitted ); 321 322 bp_core_install( $bp->active_components ); 323 bp_core_add_page_mappings( $bp->active_components ); 324 bp_update_option( 'bp-active-components', $bp->active_components ); 325 } 326 327 // Where are we redirecting to? 328 $base_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components', 'updated' => 'true' ), 'admin.php' ) ); 329 330 // Redirect. 331 wp_redirect( $base_url ); 332 die(); 333 } 334 add_action( 'bp_admin_init', 'bp_core_admin_components_settings_handler' ); 335 336 /** 337 * Calculates the components that should be active after save, based on submitted settings. 338 * 339 * The way that active components must be set after saving your settings must 340 * be calculated differently depending on which of the Components subtabs you 341 * are coming from: 342 * - When coming from All or Active, the submitted checkboxes accurately 343 * reflect the desired active components, so we simply pass them through 344 * - When coming from Inactive, components can only be activated - already 345 * active components will not be passed in the $_POST global. Thus, we must 346 * parse the newly activated components with the already active components 347 * saved in the $bp global 348 * - When activating a Retired component, the situation is similar to Inactive. 349 * - When deactivating a Retired component, no value is passed in the $_POST 350 * global (because the component settings are checkboxes). So, in order to 351 * determine whether a retired component is being deactivated, we retrieve a 352 * list of retired components, and check each one to ensure that its checkbox 353 * is not present, before merging the submitted components with the active 354 * ones. 355 * 356 * @since 1.7.0 357 * 358 * @param array $submitted This is the array of component settings coming from the POST 359 * global. You should stripslashes_deep() before passing to this function. 360 * @return array The calculated list of component settings 361 */ 362 function bp_core_admin_get_active_components_from_submitted_settings( $submitted ) { 363 $current_action = 'all'; 364 365 if ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'active', 'inactive', 'retired' ) ) ) { 366 $current_action = $_GET['action']; 367 } 368 369 $current_components = buddypress()->active_components; 370 371 switch ( $current_action ) { 372 case 'retired' : 373 $retired_components = bp_core_admin_get_components( 'retired' ); 374 foreach ( array_keys( $retired_components ) as $retired_component ) { 375 if ( ! isset( $submitted[ $retired_component ] ) ) { 376 unset( $current_components[ $retired_component ] ); 377 } 378 } // Fall through. 379 380 381 case 'inactive' : 382 $components = array_merge( $submitted, $current_components ); 383 break; 384 385 case 'all' : 386 case 'active' : 387 default : 388 $components = $submitted; 389 break; 390 } 391 392 return $components; 393 } 394 395 /** 396 * Return a list of component information. 397 * 398 * We use this information both to build the markup for the admin screens, as 399 * well as to do some processing on settings data submitted from those screens. 400 * 401 * @since 1.7.0 402 * 403 * @param string $type Optional; component type to fetch. Default value is 'all', or 'optional', 'retired', 'required'. 404 * @return array Requested components' data. 405 */ 406 function bp_core_admin_get_components( $type = 'all' ) { 407 $components = bp_core_get_components( $type ); 408 409 /** 410 * Filters the list of component information. 411 * 412 * @since 2.0.0 413 * 414 * @param array $components Array of component information. 415 * @param string $type Type of component list requested. 416 * Possible values include 'all', 'optional', 417 * 'retired', 'required'. 418 */ 419 return apply_filters( 'bp_core_admin_get_components', $components, $type ); 420 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |