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