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