[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Options. 4 * 5 * @package BuddyPress 6 * @subpackage Options 7 * @since 1.6.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Get the default site options and their values. 15 * 16 * Default values should not be set by calls to `get_option()` or `get_site_option()` due to 17 * these causing load order problems with `bp_core_clear_root_options_cache()`; see #BP7227. 18 * 19 * @since 1.6.0 20 * 21 * @return array Filtered option names and values. 22 */ 23 function bp_get_default_options() { 24 25 // Default options. 26 $options = array ( 27 28 /* Components ********************************************************/ 29 30 'bp-deactivated-components' => array(), 31 32 /* XProfile **********************************************************/ 33 34 // Base profile groups name. 35 'bp-xprofile-base-group-name' => 'Base', 36 37 // Base fullname field name. 38 'bp-xprofile-fullname-field-name' => 'Name', 39 40 /* Blogs *************************************************************/ 41 42 // Used to decide if blogs need indexing. 43 'bp-blogs-first-install' => false, 44 45 /* Settings **********************************************************/ 46 47 // Disable the WP to BP profile sync. 48 'bp-disable-profile-sync' => false, 49 50 // Hide the Toolbar for logged out users. 51 'hide-loggedout-adminbar' => false, 52 53 // Avatar uploads. 54 'bp-disable-avatar-uploads' => false, 55 56 // Cover image uploads. 57 'bp-disable-cover-image-uploads' => false, 58 59 // Group Profile Photos. 60 'bp-disable-group-avatar-uploads' => false, 61 62 // Group Cover image uploads. 63 'bp-disable-group-cover-image-uploads' => false, 64 65 // Allow users to delete their own accounts. 66 'bp-disable-account-deletion' => false, 67 68 // Allow comments on post and comment activity items. 69 'bp-disable-blogforum-comments' => true, 70 71 // The ID for the current theme package. 72 '_bp_theme_package_id' => 'nouveau', 73 74 // Email unsubscribe salt. 75 'bp-emails-unsubscribe-salt' => '', 76 77 /* Groups ************************************************************/ 78 79 // @todo Move this into the groups component 80 // Restrict group creation to super admins. 81 'bp_restrict_group_creation' => false, 82 83 /* Akismet ***********************************************************/ 84 85 // Users from all sites can post. 86 '_bp_enable_akismet' => true, 87 88 /* Activity HeartBeat ************************************************/ 89 90 // HeartBeat is on to refresh activities. 91 '_bp_enable_heartbeat_refresh' => true, 92 93 /* Legacy *********************************************/ 94 95 // Do not register the bp-default themes directory. 96 '_bp_retain_bp_default' => false, 97 98 // Ignore deprecated code. 99 '_bp_ignore_deprecated_code' => true, 100 101 /* Widgets **************************************************/ 102 'widget_bp_core_login_widget' => false, 103 'widget_bp_core_members_widget' => false, 104 'widget_bp_core_whos_online_widget' => false, 105 'widget_bp_core_recently_active_widget' => false, 106 'widget_bp_groups_widget' => false, 107 'widget_bp_messages_sitewide_notices_widget' => false, 108 ); 109 110 /** 111 * Filters the default options to be set upon activation. 112 * 113 * @since 1.6.0 114 * 115 * @param array $options Array of default options to set. 116 */ 117 return apply_filters( 'bp_get_default_options', $options ); 118 } 119 120 /** 121 * Add default options when BuddyPress is first activated. 122 * 123 * Only called once when BuddyPress is activated. 124 * Non-destructive, so existing settings will not be overridden. 125 * 126 * @since 1.6.0 127 */ 128 function bp_add_options() { 129 130 // Get the default options and values. 131 $options = bp_get_default_options(); 132 133 // Add default options. 134 foreach ( $options as $key => $value ) { 135 bp_add_option( $key, $value ); 136 } 137 138 /** 139 * Fires after the addition of default options when BuddyPress is first activated. 140 * 141 * Allows previously activated plugins to append their own options. 142 * 143 * @since 1.6.0 144 */ 145 do_action( 'bp_add_options' ); 146 } 147 148 /** 149 * Delete default options. 150 * 151 * Hooked to bp_uninstall, it is only called once when BuddyPress is uninstalled. 152 * This is destructive, so existing settings will be destroyed. 153 * 154 * Currently unused. 155 * 156 * @since 1.6.0 157 */ 158 function bp_delete_options() { 159 160 // Get the default options and values. 161 $options = bp_get_default_options(); 162 163 // Add default options. 164 foreach ( array_keys( $options ) as $key ) { 165 delete_option( $key ); 166 } 167 168 /** 169 * Fires after the deletion of default options when BuddyPress is first deactivated. 170 * 171 * Allows previously activated plugins to append their own options. 172 * 173 * @since 1.6.0 174 */ 175 do_action( 'bp_delete_options' ); 176 } 177 178 /** 179 * Add filters to each BP option, allowing them to be overloaded from inside the $bp->options array. 180 * 181 * @since 1.6.0 182 */ 183 function bp_setup_option_filters() { 184 185 // Get the default options and values. 186 $options = bp_get_default_options(); 187 188 // Add filters to each BuddyPress option. 189 foreach ( array_keys( $options ) as $key ) { 190 add_filter( 'pre_option_' . $key, 'bp_pre_get_option' ); 191 } 192 193 /** 194 * Fires after the addition of filters to each BuddyPress option. 195 * 196 * Allows previously activated plugins to append their own options. 197 * 198 * @since 1.6.0 199 */ 200 do_action( 'bp_setup_option_filters' ); 201 } 202 203 /** 204 * Filter default options and allow them to be overloaded from inside the $bp->options array. 205 * 206 * @since 1.6.0 207 * 208 * @param bool $value Optional. Default value false. 209 * @return mixed False if not overloaded, mixed if set. 210 */ 211 function bp_pre_get_option( $value = false ) { 212 $bp = buddypress(); 213 214 // Remove the filter prefix. 215 $option = str_replace( 'pre_option_', '', current_filter() ); 216 217 // Check the options global for preset value. 218 if ( ! empty( $bp->options[ $option ] ) ) { 219 $value = $bp->options[ $option ]; 220 } 221 222 // Always return a value, even if false. 223 return $value; 224 } 225 226 /** 227 * Retrieve an option. 228 * 229 * This is a wrapper for {@link get_blog_option()}, which in turn stores settings data 230 * (such as bp-pages) on the appropriate blog, given your current setup. 231 * 232 * The 'bp_get_option' filter is primarily for backward-compatibility. 233 * 234 * @since 1.5.0 235 * 236 * @param string $option_name The option to be retrieved. 237 * @param string $default Optional. Default value to be returned if the option 238 * isn't set. See {@link get_blog_option()}. 239 * @return mixed The value for the option. 240 */ 241 function bp_get_option( $option_name, $default = '' ) { 242 $value = get_blog_option( bp_get_root_blog_id(), $option_name, $default ); 243 244 /** 245 * Filters the option value for the requested option. 246 * 247 * @since 1.5.0 248 * 249 * @param mixed $value The value for the option. 250 */ 251 return apply_filters( 'bp_get_option', $value ); 252 } 253 254 /** 255 * Add an option. 256 * 257 * This is a wrapper for {@link add_blog_option()}, which in turn stores 258 * settings data on the appropriate blog, given your current setup. 259 * 260 * @since 2.0.0 261 * 262 * @param string $option_name The option key to be set. 263 * @param mixed $value The value to be set. 264 * @return bool True on success, false on failure. 265 */ 266 function bp_add_option( $option_name, $value ) { 267 return add_blog_option( bp_get_root_blog_id(), $option_name, $value ); 268 } 269 270 /** 271 * Save an option. 272 * 273 * This is a wrapper for {@link update_blog_option()}, which in turn stores 274 * settings data (such as bp-pages) on the appropriate blog, given your current 275 * setup. 276 * 277 * @since 1.5.0 278 * 279 * @param string $option_name The option key to be set. 280 * @param mixed $value The value to be set. 281 * @return bool True on success, false on failure. 282 */ 283 function bp_update_option( $option_name, $value ) { 284 return update_blog_option( bp_get_root_blog_id(), $option_name, $value ); 285 } 286 287 /** 288 * Delete an option. 289 * 290 * This is a wrapper for {@link delete_blog_option()}, which in turn deletes 291 * settings data (such as bp-pages) on the appropriate blog, given your current 292 * setup. 293 * 294 * @since 1.5.0 295 * 296 * @param string $option_name The option key to be deleted. 297 * @return bool True on success, false on failure. 298 */ 299 function bp_delete_option( $option_name ) { 300 return delete_blog_option( bp_get_root_blog_id(), $option_name ); 301 } 302 303 /** 304 * Copy BP options from a single site to multisite config. 305 * 306 * Run when switching from single to multisite and we need to copy blog options 307 * to site options. 308 * 309 * This function is no longer used. 310 * 311 * @since 1.2.4 312 * @deprecated 1.6.0 313 * 314 * @param array $keys Array of site options. 315 * @return bool 316 */ 317 function bp_core_activate_site_options( $keys = array() ) { 318 319 if ( !empty( $keys ) && is_array( $keys ) ) { 320 $bp = buddypress(); 321 322 $errors = false; 323 324 foreach ( $keys as $key => $default ) { 325 if ( empty( $bp->site_options[ $key ] ) ) { 326 $bp->site_options[ $key ] = bp_get_option( $key, $default ); 327 328 if ( !bp_update_option( $key, $bp->site_options[ $key ] ) ) { 329 $errors = true; 330 } 331 } 332 } 333 334 if ( empty( $errors ) ) { 335 return true; 336 } 337 } 338 339 return false; 340 } 341 342 /** 343 * Fetch global BP options. 344 * 345 * BuddyPress uses common options to store configuration settings. Many of these 346 * settings are needed at run time. Instead of fetching them all and adding many 347 * initial queries to each page load, let's fetch them all in one go. 348 * 349 * @since 1.5.0 350 * 351 * @todo Use settings API and audit these methods. 352 * 353 * @return array $root_blog_options_meta List of options. 354 */ 355 function bp_core_get_root_options() { 356 global $wpdb; 357 358 // Get all the BuddyPress settings, and a few useful WP ones too. 359 $root_blog_options = bp_get_default_options(); 360 $root_blog_options['registration'] = '0'; 361 $root_blog_options['avatar_default'] = 'mysteryman'; 362 $root_blog_option_keys = array_keys( $root_blog_options ); 363 364 // Do some magic to get all the root blog options in 1 swoop 365 // Check cache first - We cache here instead of using the standard WP 366 // settings cache because the current blog may not be the root blog, 367 // and it's not practical to access the cache across blogs. 368 $root_blog_options_meta = wp_cache_get( 'root_blog_options', 'bp' ); 369 370 if ( false === $root_blog_options_meta ) { 371 $blog_options_keys = "'" . join( "', '", (array) $root_blog_option_keys ) . "'"; 372 $blog_options_table = bp_is_multiblog_mode() ? $wpdb->options : $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'options'; 373 $blog_options_query = "SELECT option_name AS name, option_value AS value FROM {$blog_options_table} WHERE option_name IN ( {$blog_options_keys} )"; 374 $root_blog_options_meta = $wpdb->get_results( $blog_options_query ); 375 376 // On Multisite installations, some options must always be fetched from sitemeta. 377 if ( is_multisite() ) { 378 379 /** 380 * Filters multisite options retrieved from sitemeta. 381 * 382 * @since 1.5.0 383 * 384 * @param array $value Array of multisite options from sitemeta table. 385 */ 386 $network_options = apply_filters( 'bp_core_network_options', array( 387 'tags_blog_id' => '0', 388 'sitewide_tags_blog' => '', 389 'registration' => '0', 390 'fileupload_maxk' => '1500' 391 ) ); 392 393 $current_site = get_current_site(); 394 $network_option_keys = array_keys( $network_options ); 395 $sitemeta_options_keys = "'" . join( "', '", (array) $network_option_keys ) . "'"; 396 $sitemeta_options_query = $wpdb->prepare( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ( {$sitemeta_options_keys} ) AND site_id = %d", $current_site->id ); 397 $network_options_meta = $wpdb->get_results( $sitemeta_options_query ); 398 399 // Sitemeta comes second in the merge, so that network 'registration' value wins. 400 $root_blog_options_meta = array_merge( $root_blog_options_meta, $network_options_meta ); 401 } 402 403 // Loop through our results and make them usable. 404 foreach ( $root_blog_options_meta as $root_blog_option ) { 405 $root_blog_options[$root_blog_option->name] = $root_blog_option->value; 406 } 407 408 // Copy the options no the return val. 409 $root_blog_options_meta = $root_blog_options; 410 411 // Clean up our temporary copy. 412 unset( $root_blog_options ); 413 414 wp_cache_set( 'root_blog_options', $root_blog_options_meta, 'bp' ); 415 } 416 417 /** 418 * Filters the global BP options. 419 * 420 * @since 1.5.0 421 * 422 * @param array $root_blog_options_meta Array of global BP options. 423 */ 424 return apply_filters( 'bp_core_get_root_options', $root_blog_options_meta ); 425 } 426 427 /** 428 * Get a root option. 429 * 430 * "Root options" are those that apply across an entire installation, and are fetched only a single 431 * time during a pageload and stored in `buddypress()->site_options` to prevent future lookups. 432 * See {@see bp_core_get_root_options()}. 433 * 434 * @since 2.3.0 435 * 436 * @param string $option Name of the option key. 437 * @return mixed Value, if found. 438 */ 439 function bp_core_get_root_option( $option ) { 440 $bp = buddypress(); 441 442 if ( ! isset( $bp->site_options ) ) { 443 $bp->site_options = bp_core_get_root_options(); 444 } 445 446 $value = ''; 447 if ( isset( $bp->site_options[ $option ] ) ) { 448 $value = $bp->site_options[ $option ]; 449 } 450 451 return $value; 452 } 453 454 /** Active? *******************************************************************/ 455 456 /** 457 * Is profile syncing disabled? 458 * 459 * @since 1.6.0 460 * 461 * @param bool $default Optional. Fallback value if not found in the database. 462 * Default: true. 463 * @return bool True if profile sync is enabled, otherwise false. 464 */ 465 function bp_disable_profile_sync( $default = false ) { 466 467 /** 468 * Filters whether or not profile syncing is disabled. 469 * 470 * @since 1.6.0 471 * 472 * @param bool $value Whether or not syncing is disabled. 473 */ 474 return (bool) apply_filters( 'bp_disable_profile_sync', (bool) bp_get_option( 'bp-disable-profile-sync', $default ) ); 475 } 476 477 /** 478 * Is the Toolbar hidden for logged out users? 479 * 480 * @since 1.6.0 481 * 482 * @param bool $default Optional. Fallback value if not found in the database. 483 * Default: true. 484 * @return bool True if the admin bar should be hidden for logged-out users, 485 * otherwise false. 486 */ 487 function bp_hide_loggedout_adminbar( $default = true ) { 488 489 /** 490 * Filters whether or not the toolbar is hidden for logged out users. 491 * 492 * @since 1.6.0 493 * 494 * @param bool $value Whether or not the toolbar is hidden. 495 */ 496 return (bool) apply_filters( 'bp_hide_loggedout_adminbar', (bool) bp_get_option( 'hide-loggedout-adminbar', $default ) ); 497 } 498 499 /** 500 * Are members able to upload their own avatars? 501 * 502 * @since 1.6.0 503 * 504 * @param bool $default Optional. Fallback value if not found in the database. 505 * Default: true. 506 * @return bool True if avatar uploads are disabled, otherwise false. 507 */ 508 function bp_disable_avatar_uploads( $default = true ) { 509 510 /** 511 * Filters whether or not members are able to upload their own avatars. 512 * 513 * @since 1.6.0 514 * 515 * @param bool $value Whether or not members are able to upload their own avatars. 516 */ 517 return (bool) apply_filters( 'bp_disable_avatar_uploads', (bool) bp_get_option( 'bp-disable-avatar-uploads', $default ) ); 518 } 519 520 /** 521 * Are members able to upload their own cover images? 522 * 523 * @since 2.4.0 524 * 525 * @param bool $default Optional. Fallback value if not found in the database. 526 * Default: false. 527 * @return bool True if cover image uploads are disabled, otherwise false. 528 */ 529 function bp_disable_cover_image_uploads( $default = false ) { 530 531 /** 532 * Filters whether or not members are able to upload their own cover images. 533 * 534 * @since 2.4.0 535 * 536 * @param bool $value Whether or not members are able to upload their own cover images. 537 */ 538 return (bool) apply_filters( 'bp_disable_cover_image_uploads', (bool) bp_get_option( 'bp-disable-cover-image-uploads', $default ) ); 539 } 540 541 /** 542 * Are group avatars disabled? 543 * 544 * For backward compatibility, this option falls back on the value of 'bp-disable-avatar-uploads' when no value is 545 * found in the database. 546 * 547 * @since 2.3.0 548 * 549 * @param bool|null $default Optional. Fallback value if not found in the database. 550 * Defaults to the value of `bp_disable_avatar_uploads()`. 551 * @return bool True if group avatar uploads are disabled, otherwise false. 552 */ 553 function bp_disable_group_avatar_uploads( $default = null ) { 554 $disabled = bp_get_option( 'bp-disable-group-avatar-uploads', '' ); 555 556 if ( '' === $disabled ) { 557 if ( is_null( $default ) ) { 558 $disabled = bp_disable_avatar_uploads(); 559 } else { 560 $disabled = $default; 561 } 562 } 563 564 /** 565 * Filters whether or not members are able to upload group avatars. 566 * 567 * @since 2.3.0 568 * 569 * @param bool $disabled Whether or not members are able to upload their groups avatars. 570 * @param bool $default Default value passed to the function. 571 */ 572 return (bool) apply_filters( 'bp_disable_group_avatar_uploads', $disabled, $default ); 573 } 574 575 /** 576 * Are group cover images disabled? 577 * 578 * @since 2.4.0 579 * 580 * @param bool $default Optional. Fallback value if not found in the database. 581 * Default: false. 582 * @return bool True if group cover image uploads are disabled, otherwise false. 583 */ 584 function bp_disable_group_cover_image_uploads( $default = false ) { 585 586 /** 587 * Filters whether or not members are able to upload group cover images. 588 * 589 * @since 2.4.0 590 * 591 * @param bool $value Whether or not members are able to upload thier groups cover images. 592 */ 593 return (bool) apply_filters( 'bp_disable_group_cover_image_uploads', (bool) bp_get_option( 'bp-disable-group-cover-image-uploads', $default ) ); 594 } 595 596 /** 597 * Are members able to delete their own accounts? 598 * 599 * @since 1.6.0 600 * 601 * @param bool $default Optional. Fallback value if not found in the database. 602 * Default: true. 603 * @return bool True if users are able to delete their own accounts, otherwise 604 * false. 605 */ 606 function bp_disable_account_deletion( $default = false ) { 607 608 /** 609 * Filters whether or not members are able to delete their own accounts. 610 * 611 * @since 1.6.0 612 * 613 * @param bool $value Whether or not members are able to delete their own accounts. 614 */ 615 return apply_filters( 'bp_disable_account_deletion', (bool) bp_get_option( 'bp-disable-account-deletion', $default ) ); 616 } 617 618 /** 619 * Are post/comment activity stream comments disabled? 620 * 621 * @since 1.6.0 622 * 623 * @todo split and move into blog and forum components. 624 * 625 * @param bool $default Optional. Fallback value if not found in the database. 626 * Default: false. 627 * @return bool True if activity comments are disabled for blog and forum 628 * items, otherwise false. 629 */ 630 function bp_disable_blogforum_comments( $default = false ) { 631 632 /** 633 * Filters whether or not blog and forum activity stream comments are disabled. 634 * 635 * @since 1.6.0 636 * 637 * @param bool $value Whether or not blog and forum activity stream comments are disabled. 638 */ 639 return (bool) apply_filters( 'bp_disable_blogforum_comments', (bool) bp_get_option( 'bp-disable-blogforum-comments', $default ) ); 640 } 641 642 /** 643 * Is group creation turned off? 644 * 645 * @since 1.6.0 646 * 647 * @todo Move into groups component. 648 * 649 * @param bool $default Optional. Fallback value if not found in the database. 650 * Default: true. 651 * @return bool True if group creation is restricted, otherwise false. 652 */ 653 function bp_restrict_group_creation( $default = true ) { 654 655 /** 656 * Filters whether or not group creation is turned off. 657 * 658 * @since 1.6.0 659 * 660 * @param bool $value Whether or not group creation is turned off. 661 */ 662 return (bool) apply_filters( 'bp_restrict_group_creation', (bool) bp_get_option( 'bp_restrict_group_creation', $default ) ); 663 } 664 665 /** 666 * Check whether Akismet is enabled. 667 * 668 * @since 1.6.0 669 * 670 * @param bool $default Optional. Fallback value if not found in the database. 671 * Default: true. 672 * @return bool True if Akismet is enabled, otherwise false. 673 */ 674 function bp_is_akismet_active( $default = true ) { 675 676 /** 677 * Filters whether or not Akismet is enabled. 678 * 679 * @since 1.6.0 680 * 681 * @param bool $value Whether or not Akismet is enabled. 682 */ 683 return (bool) apply_filters( 'bp_is_akismet_active', (bool) bp_get_option( '_bp_enable_akismet', $default ) ); 684 } 685 686 /** 687 * Check whether Activity Heartbeat refresh is enabled. 688 * 689 * @since 2.0.0 690 * 691 * @param bool $default Optional. Fallback value if not found in the database. 692 * Default: true. 693 * @return bool True if Heartbeat refresh is enabled, otherwise false. 694 */ 695 function bp_is_activity_heartbeat_active( $default = true ) { 696 697 /** 698 * Filters whether or not Activity Heartbeat refresh is enabled. 699 * 700 * @since 2.0.0 701 * 702 * @param bool $value Whether or not Activity Heartbeat refresh is enabled. 703 */ 704 return (bool) apply_filters( 'bp_is_activity_heartbeat_active', (bool) bp_get_option( '_bp_enable_heartbeat_refresh', $default ) ); 705 } 706 707 /** 708 * Get the current theme package ID. 709 * 710 * @since 1.7.0 711 * 712 * @param string $default Optional. Fallback value if not found in the database. 713 * Default: 'legacy'. 714 * @return string ID of the theme package. 715 */ 716 function bp_get_theme_package_id( $default = 'legacy' ) { 717 718 /** 719 * Filters the current theme package ID. 720 * 721 * @since 1.7.0 722 * 723 * @param string $value The current theme package ID. 724 */ 725 return apply_filters( 'bp_get_theme_package_id', bp_get_option( '_bp_theme_package_id', $default ) ); 726 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |