[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Admin Settings. 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 * Main settings section description for the settings page. 15 * 16 * @since 1.6.0 17 */ 18 function bp_admin_setting_callback_main_section() { } 19 20 /** 21 * Admin bar for logged out users setting field. 22 * 23 * @since 1.6.0 24 * 25 */ 26 function bp_admin_setting_callback_admin_bar() { 27 ?> 28 29 <input id="hide-loggedout-adminbar" name="hide-loggedout-adminbar" type="checkbox" value="1" <?php checked( !bp_hide_loggedout_adminbar( false ) ); ?> /> 30 <label for="hide-loggedout-adminbar"><?php _e( 'Show the Toolbar for logged out users', 'buddypress' ); ?></label> 31 32 <?php 33 } 34 35 /** 36 * Allow members to delete their accounts setting field. 37 * 38 * @since 1.6.0 39 * 40 */ 41 function bp_admin_setting_callback_account_deletion() { 42 ?> 43 44 <input id="bp-disable-account-deletion" name="bp-disable-account-deletion" type="checkbox" value="1" <?php checked( !bp_disable_account_deletion( false ) ); ?> /> 45 <label for="bp-disable-account-deletion"><?php _e( 'Allow registered members to delete their own accounts', 'buddypress' ); ?></label> 46 47 <?php 48 } 49 50 /** 51 * Form element to change the active template pack. 52 */ 53 function bp_admin_setting_callback_theme_package_id() { 54 $options = ''; 55 56 /* 57 * Note: This should never be empty. /bp-templates/ is the 58 * canonical backup if no other packages exist. If there's an error here, 59 * something else is wrong. 60 * 61 * See BuddyPress::register_theme_packages() 62 */ 63 foreach ( (array) buddypress()->theme_compat->packages as $id => $theme ) { 64 $options .= sprintf( 65 '<option value="%1$s" %2$s>%3$s</option>', 66 esc_attr( $id ), 67 selected( $theme->id, bp_get_theme_package_id(), false ), 68 esc_html( $theme->name ) 69 ); 70 } 71 72 if ( $options ) : ?> 73 <select name="_bp_theme_package_id" id="_bp_theme_package_id" aria-describedby="_bp_theme_package_description"><?php echo $options; ?></select> 74 <p id="_bp_theme_package_description" class="description"><?php esc_html_e( 'The selected Template Pack will serve all BuddyPress templates.', 'buddypress' ); ?></p> 75 76 <?php else : ?> 77 <p><?php esc_html_e( 'No template packages available.', 'buddypress' ); ?></p> 78 79 <?php endif; 80 } 81 82 /** Activity *******************************************************************/ 83 84 /** 85 * Groups settings section description for the settings page. 86 * 87 * @since 1.6.0 88 */ 89 function bp_admin_setting_callback_activity_section() { } 90 91 /** 92 * Allow Akismet setting field. 93 * 94 * @since 1.6.0 95 * 96 */ 97 function bp_admin_setting_callback_activity_akismet() { 98 ?> 99 100 <input id="_bp_enable_akismet" name="_bp_enable_akismet" type="checkbox" value="1" <?php checked( bp_is_akismet_active( true ) ); ?> /> 101 <label for="_bp_enable_akismet"><?php _e( 'Allow Akismet to scan for activity stream spam', 'buddypress' ); ?></label> 102 103 <?php 104 } 105 106 /** 107 * Allow activity comments on posts and comments. 108 * 109 * @since 1.6.0 110 */ 111 function bp_admin_setting_callback_blogforum_comments() { 112 ?> 113 114 <input id="bp-disable-blogforum-comments" name="bp-disable-blogforum-comments" type="checkbox" value="1" <?php checked( !bp_disable_blogforum_comments( false ) ); ?> /> 115 <label for="bp-disable-blogforum-comments"><?php _e( 'Allow activity stream commenting on posts and comments', 'buddypress' ); ?></label> 116 117 <?php 118 } 119 120 /** 121 * Allow Heartbeat to refresh activity stream. 122 * 123 * @since 2.0.0 124 */ 125 function bp_admin_setting_callback_heartbeat() { 126 ?> 127 128 <input id="_bp_enable_heartbeat_refresh" name="_bp_enable_heartbeat_refresh" type="checkbox" value="1" <?php checked( bp_is_activity_heartbeat_active( true ) ); ?> /> 129 <label for="_bp_enable_heartbeat_refresh"><?php _e( 'Automatically check for new items while viewing the activity stream', 'buddypress' ); ?></label> 130 131 <?php 132 } 133 134 /** 135 * Sanitization for bp-disable-blogforum-comments setting. 136 * 137 * In the UI, a checkbox asks whether you'd like to *enable* post/comment activity comments. For 138 * legacy reasons, the option that we store is 1 if these comments are *disabled*. So we use this 139 * function to flip the boolean before saving the intval. 140 * 141 * @since 1.6.0 142 * 143 * @param bool $value Whether or not to sanitize. 144 * @return bool 145 */ 146 function bp_admin_sanitize_callback_blogforum_comments( $value = false ) { 147 return $value ? 0 : 1; 148 } 149 150 /** Members *******************************************************************/ 151 152 /** 153 * Profile settings section description for the settings page. 154 * 155 * @since 1.6.0 156 */ 157 function bp_admin_setting_callback_members_section() { } 158 159 /** 160 * Allow members to upload avatars field. 161 * 162 * @since 1.6.0 163 * @since 6.0.0 Setting has been moved into the Members section. 164 */ 165 function bp_admin_setting_callback_avatar_uploads() { 166 ?> 167 <input id="bp-disable-avatar-uploads" name="bp-disable-avatar-uploads" type="checkbox" value="1" <?php checked( !bp_disable_avatar_uploads( false ) ); ?> /> 168 <label for="bp-disable-avatar-uploads"><?php _e( 'Allow registered members to upload avatars', 'buddypress' ); ?></label> 169 <?php 170 } 171 172 /** 173 * Allow members to upload cover images field. 174 * 175 * @since 2.4.0 176 * @since 6.0.0 Setting has been moved into the Members section. 177 */ 178 function bp_admin_setting_callback_cover_image_uploads() { 179 ?> 180 <input id="bp-disable-cover-image-uploads" name="bp-disable-cover-image-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_cover_image_uploads() ); ?> /> 181 <label for="bp-disable-cover-image-uploads"><?php _e( 'Allow registered members to upload cover images', 'buddypress' ); ?></label> 182 <?php 183 } 184 185 /** 186 * Allow members to invite non-members to the network. 187 * 188 * @since 8.0.0 189 */ 190 function bp_admin_setting_callback_members_invitations() { 191 ?> 192 <input id="bp-enable-members-invitations" name="bp-enable-members-invitations" type="checkbox" value="1" <?php checked( bp_get_members_invitations_allowed() ); ?> /> 193 <label for="bp-enable-members-invitations"><?php _e( 'Allow registered members to invite people to join this network', 'buddypress' ); ?></label> 194 <?php if ( ! bp_get_signup_allowed() ) : ?> 195 <p class="description"><?php esc_html_e( 'Public registration is currently disabled. However, invitees will still be able to register if network invitations are enabled.', 'buddypress' ); ?></p> 196 <?php endif; ?> 197 <?php 198 /** 199 * Fires after the output of the invitations settings section. 200 * 201 * @since 8.0.0 202 */ 203 do_action( 'bp_admin_settings_after_members_invitations' ); 204 } 205 206 /** 207 * Allow new users to request membership to the network. 208 * 209 * @since 10.0.0 210 */ 211 function bp_admin_setting_callback_membership_requests() { 212 ?> 213 <input id="bp-enable-membership-requests" name="bp-enable-membership-requests" type="checkbox" value="1" <?php checked( bp_get_membership_requests_required( 'raw' ) ); ?> <?php disabled( bp_get_signup_allowed() ); ?> /> 214 <label for="bp-enable-membership-requests"><?php esc_html_e( 'Allow visitors to request site membership. If enabled, an administrator must approve each new site membership request.', 'buddypress' ); ?></label> 215 <?php if ( bp_get_signup_allowed() ) : ?> 216 <?php if ( is_multisite() ) : ?> 217 <p class="description"><?php esc_html_e( 'With a WP multisite setup, to require membership requests for new signups, choose one of the following two options from the Network Settings > Registration Settings pane:', 'buddypress' ); ?><p> 218 <ul> 219 <li><p class="description"><?php esc_html_e( 'To allow the submission of membership requests but not allow site creation requests, select "Registration is disabled".', 'buddypress' ) ?></p></li> 220 <li><p class="description"><?php esc_html_e( 'To allow the submission of membership requests and to allow new sites to be created by your users, choose "Logged in users may register new sites".', 'buddypress' ) ?></p></li> 221 </ul> 222 <p class="description"><?php esc_html_e( 'The other two options, "User accounts may be registered" and "Both sites and user accounts can be registered," are open in nature and membership requests will not be enabled if one of those options is selected.', 'buddypress' ); ?><p> 223 <?php else : ?> 224 <p class="description"><?php esc_html_e( 'Public registration is currently enabled. If you wish to require approval for new memberships, disable public registration and enable the membership requests feature.', 'buddypress' ); ?></p> 225 <?php endif; ?> 226 <?php endif; ?> 227 <?php 228 /** 229 * Fires after the output of the membership requests settings section. 230 * 231 * @since 10.0.0 232 */ 233 do_action( 'bp_admin_settings_after_membership_requests' ); 234 } 235 236 /** XProfile ******************************************************************/ 237 238 /** 239 * Profile settings section description for the settings page. 240 * 241 * @since 1.6.0 242 */ 243 function bp_admin_setting_callback_xprofile_section() { } 244 245 /** 246 * Enable BP->WP profile syncing field. 247 * 248 * @since 1.6.0 249 * 250 */ 251 function bp_admin_setting_callback_profile_sync() { 252 ?> 253 254 <input id="bp-disable-profile-sync" name="bp-disable-profile-sync" type="checkbox" value="1" <?php checked( !bp_disable_profile_sync( false ) ); ?> /> 255 <label for="bp-disable-profile-sync"><?php _e( 'Enable BuddyPress to WordPress profile syncing', 'buddypress' ); ?></label> 256 257 <?php 258 } 259 260 /** Groups Section ************************************************************/ 261 262 /** 263 * Groups settings section description for the settings page. 264 * 265 * @since 1.6.0 266 */ 267 function bp_admin_setting_callback_groups_section() { } 268 269 /** 270 * Allow all users to create groups field. 271 * 272 * @since 1.6.0 273 * 274 */ 275 function bp_admin_setting_callback_group_creation() { 276 ?> 277 278 <input id="bp_restrict_group_creation" name="bp_restrict_group_creation" type="checkbox" aria-describedby="bp_group_creation_description" value="1" <?php checked( !bp_restrict_group_creation( false ) ); ?> /> 279 <label for="bp_restrict_group_creation"><?php _e( 'Enable group creation for all users', 'buddypress' ); ?></label> 280 <p class="description" id="bp_group_creation_description"><?php _e( 'Administrators can always create groups, regardless of this setting.', 'buddypress' ); ?></p> 281 282 <?php 283 } 284 285 /** 286 * 'Enable group avatars' field markup. 287 * 288 * @since 2.3.0 289 */ 290 function bp_admin_setting_callback_group_avatar_uploads() { 291 ?> 292 <input id="bp-disable-group-avatar-uploads" name="bp-disable-group-avatar-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_group_avatar_uploads() ); ?> /> 293 <label for="bp-disable-group-avatar-uploads"><?php _e( 'Allow customizable avatars for groups', 'buddypress' ); ?></label> 294 <?php 295 } 296 297 /** 298 * 'Enable group cover images' field markup. 299 * 300 * @since 2.4.0 301 */ 302 function bp_admin_setting_callback_group_cover_image_uploads() { 303 ?> 304 <input id="bp-disable-group-cover-image-uploads" name="bp-disable-group-cover-image-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_group_cover_image_uploads() ); ?> /> 305 <label for="bp-disable-group-cover-image-uploads"><?php _e( 'Allow customizable cover images for groups', 'buddypress' ); ?></label> 306 <?php 307 } 308 309 /** Settings Page *************************************************************/ 310 311 /** 312 * The main settings page 313 * 314 * @since 1.6.0 315 * 316 */ 317 function bp_core_admin_settings() { 318 319 // We're saving our own options, until the WP Settings API is updated to work with Multisite. 320 $form_action = add_query_arg( 'page', 'bp-settings', bp_get_admin_url( 'admin.php' ) ); 321 bp_core_admin_tabbed_screen_header( __( 'BuddyPress Settings', 'buddypress' ), __( 'Options', 'buddypress' ) ); 322 ?> 323 324 <div class="buddypress-body"> 325 <form action="<?php echo esc_url( $form_action ) ?>" method="post"> 326 327 <?php settings_fields( 'buddypress' ); ?> 328 329 <?php do_settings_sections( 'buddypress' ); ?> 330 331 <p class="submit"> 332 <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Settings', 'buddypress' ); ?>" /> 333 </p> 334 </form> 335 </div> 336 337 <?php 338 } 339 340 /** 341 * Save our settings. 342 * 343 * @since 1.6.0 344 */ 345 function bp_core_admin_settings_save() { 346 global $wp_settings_fields; 347 348 if ( isset( $_GET['page'] ) && 'bp-settings' == $_GET['page'] && !empty( $_POST['submit'] ) ) { 349 check_admin_referer( 'buddypress-options' ); 350 351 // Because many settings are saved with checkboxes, and thus will have no values 352 // in the $_POST array when unchecked, we loop through the registered settings. 353 if ( isset( $wp_settings_fields['buddypress'] ) ) { 354 foreach( (array) $wp_settings_fields['buddypress'] as $section => $settings ) { 355 foreach( $settings as $setting_name => $setting ) { 356 $value = isset( $_POST[$setting_name] ) ? $_POST[$setting_name] : ''; 357 358 bp_update_option( $setting_name, $value ); 359 } 360 } 361 } 362 363 // Some legacy options are not registered with the Settings API, or are reversed in the UI. 364 $legacy_options = array( 365 'bp-disable-account-deletion', 366 'bp-disable-avatar-uploads', 367 'bp-disable-cover-image-uploads', 368 'bp-disable-group-avatar-uploads', 369 'bp-disable-group-cover-image-uploads', 370 'bp_disable_blogforum_comments', 371 'bp-disable-profile-sync', 372 'bp_restrict_group_creation', 373 'hide-loggedout-adminbar', 374 ); 375 376 foreach( $legacy_options as $legacy_option ) { 377 // Note: Each of these options is represented by its opposite in the UI 378 // Ie, the Profile Syncing option reads "Enable Sync", so when it's checked, 379 // the corresponding option should be unset. 380 $value = isset( $_POST[$legacy_option] ) ? '' : 1; 381 bp_update_option( $legacy_option, $value ); 382 } 383 384 bp_core_redirect( add_query_arg( array( 'page' => 'bp-settings', 'updated' => 'true' ), bp_get_admin_url( 'admin.php' ) ) ); 385 } 386 } 387 add_action( 'bp_admin_init', 'bp_core_admin_settings_save', 100 ); 388 389 /** 390 * Output settings API option. 391 * 392 * @since 1.6.0 393 * 394 * @param string $option Form option to echo. 395 * @param string $default Form option default. 396 * @param bool $slug Form option slug. 397 */ 398 function bp_form_option( $option, $default = '' , $slug = false ) { 399 echo bp_get_form_option( $option, $default, $slug ); 400 } 401 /** 402 * Return settings API option 403 * 404 * @since 1.6.0 405 * 406 * 407 * @param string $option Form option to return. 408 * @param string $default Form option default. 409 * @param bool $slug Form option slug. 410 * @return string 411 */ 412 function bp_get_form_option( $option, $default = '', $slug = false ) { 413 414 // Get the option and sanitize it. 415 $value = bp_get_option( $option, $default ); 416 417 // Slug? 418 if ( true === $slug ) { 419 420 /** 421 * Filters the slug value in the form field. 422 * 423 * @since 1.6.0 424 * 425 * @param string $value Value being returned for the requested option. 426 */ 427 $value = esc_attr( apply_filters( 'editable_slug', $value ) ); 428 } else { // Not a slug. 429 $value = esc_attr( $value ); 430 } 431 432 // Fallback to default. 433 if ( empty( $value ) ) 434 $value = $default; 435 436 /** 437 * Filters the settings API option. 438 * 439 * @since 1.6.0 440 * 441 * @param string $value Value being returned for the requested option. 442 * @param string $option Option whose value is being requested. 443 */ 444 return apply_filters( 'bp_get_form_option', $value, $option ); 445 }
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 |