Changeset 6544 for trunk/src/includes/core/options.php
- Timestamp:
- 06/14/2017 06:45:49 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/src/includes/core/options.php (modified) (46 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/core/options.php
r6514 r6544 23 23 24 24 // Filter & return 25 return apply_filters( 'bbp_get_default_options', array(25 return (array) apply_filters( 'bbp_get_default_options', array( 26 26 27 27 /** DB Version ********************************************************/ … … 84 84 85 85 '_bbp_user_slug' => 'users', // User profile slug 86 '_bbp_user_engs_slug' => 'engagements', // User engagements slug 86 87 '_bbp_user_favs_slug' => 'favorites', // User favorites slug 87 88 '_bbp_user_subs_slug' => 'subscriptions', // User subscriptions slug … … 112 113 113 114 '_bbp_enable_akismet' => 1, // Users from all sites can post 114 115 115 116 /** Converter *********************************************************/ 116 117 … … 193 194 // Add filters to each bbPress option 194 195 foreach ( array_keys( bbp_get_default_options() ) as $key ) { 195 add_filter( 'pre_option_' . $key, 'bbp_pre_get_option' ); 196 add_filter( 'pre_option_' . $key, 'bbp_filter_pre_get_option', 10, 2 ); 197 add_filter( 'default_option_' . $key, 'bbp_filter_default_option', 10, 3 ); 196 198 } 197 199 … … 201 203 202 204 /** 203 * Filter default options and allow them to be overloaded from inside the 204 * $bbp->options array. 205 * Filter pre options and maybe overloaded from the $bbp->options array. 206 * 207 * This function should not be called directly. 205 208 * 206 209 * @since 2.0.0 bbPress (r3451) 207 * 208 * @param bool $value Optional. Default value false 210 * @access private 211 * 212 * @param bool $value Default value false 213 * @param string $option Name of the option 214 * 209 215 * @return mixed false if not overloaded, mixed if set 210 216 */ 211 function bbp_pre_get_option( $value = '' ) { 212 213 // Remove the filter prefix 214 $option = str_replace( 'pre_option_', '', current_filter() ); 217 function bbp_filter_pre_get_option( $value = false, $option = '' ) { 215 218 216 219 // Check the options global for preset value … … 223 226 } 224 227 228 /** 229 * Filter default_options set them from inside the $bbp->options array. 230 * 231 * This function should not be called directly. 232 * 233 * @since 2.6.0 bbPress (r3451) 234 * @access private 235 * 236 * @param bool $value Optional. Default value false 237 * @return mixed false if not overloaded, mixed if set 238 */ 239 function bbp_filter_default_option( $default = false, $option = '', $passed_default = false ) { 240 $options = bbp_get_default_options(); 241 242 // Maybe use the default value 243 if ( isset( $options[ $option ] ) ) { 244 245 // Try to use the passed default and fallback to assumed default 246 $default = ( true === $passed_default ) 247 ? $default 248 : $options[ $option ]; 249 } 250 251 // Always return a value, even if false 252 return $default; 253 } 254 255 /** 256 * Loads & caches bbPress options if a persistent cache is not being used. 257 * 258 * @since 2.6.0 259 */ 260 function bbp_pre_load_options() { 261 262 // Bail if using object cache or installing 263 if ( wp_using_ext_object_cache() || wp_installing() ) { 264 return; 265 } 266 267 // Bail if strategy is overloaded to false|null 268 $strategy = apply_filters( 'bbp_pre_load_options', 'notoptions' ); 269 if ( empty( $strategy ) ) { 270 return; 271 } 272 273 // Get variables 274 $bbp = bbpress(); 275 $bbp_options = bbp_get_default_options(); 276 $all_options = wp_load_alloptions(); 277 $not_options = (array) wp_cache_get( 'notoptions', 'options' ); 278 279 // Loop through all bbPress options to maybe cache their non-existence 280 foreach ( $bbp_options as $option => $value ) { 281 282 // Skip if already saved to database 283 if ( isset( $all_options[ $option ] ) ) { 284 continue; 285 286 // Skip if overloaded 287 } elseif ( isset( $bbp->options[ $option ] ) ) { 288 continue; 289 290 // Skip if already in cache 291 } elseif ( wp_cache_get( $option, 'options' ) !== false ) { 292 continue; 293 294 // Needs caching to avoid database hit 295 } else { 296 297 // Store internally, for easier identification later 298 $bbp->not_options[ $option ] = $value; 299 300 // Cache to notoptions 301 if ( 'notoptions' === $strategy ) { 302 $not_options[ $option ] = true; 303 wp_cache_set( 'notoptions', $not_options, 'options' ); 304 305 // Cache to option 306 } elseif ( 'option' === $strategy ) { 307 wp_cache_set( $option, $value, 'options' ); 308 } 309 } 310 } 311 } 312 225 313 /** Active? *******************************************************************/ 226 314 … … 230 318 * @since 2.0.0 bbPress (r2658) 231 319 * 232 * @param $default boolOptional.Default value true320 * @param bool $default Optional.Default value true 233 321 * @uses get_option() To get the favorites option 234 322 * @return bool Is favorites enabled or not … … 245 333 * @since 2.0.0 bbPress (r2658) 246 334 * 247 * @param $default boolOptional.Default value true335 * @param bool $default Optional.Default value true 248 336 * @uses get_option() To get the subscriptions option 249 337 * @return bool Is subscription enabled or not … … 260 348 * @since 2.6.0 bbPress (r6320) 261 349 * 262 * @param $default boolOptional.Default value true350 * @param bool $default Optional.Default value true 263 351 * @uses get_option() To get the engagements option 264 352 * @return bool Is engagements enabled or not … … 275 363 * @since 2.6.0 bbPress (r6441) 276 364 * 277 * @param $default boolOptional. Default value false365 * @param bool $default Optional. Default value false 278 366 * @uses get_option() To get the global content edit option 279 367 * @return bool Is content editing allowed? … … 290 378 * @since 2.6.0 bbPress (r6441) 291 379 * 292 * @param $default boolOptional. Default value false380 * @param bool $default Optional. Default value false 293 381 * @uses get_option() To get the content throttle option 294 382 * @return bool Is content throttling allowed? … … 305 393 * @since 2.2.0 bbPress (r4097) 306 394 * 307 * @param $default boolOptional. Default value true395 * @param bool $default Optional. Default value true 308 396 * @uses get_option() To get the allow tags 309 397 * @return bool Are tags allowed? … … 336 424 * @since 2.4.0 bbPress (r4970) 337 425 * 338 * @param $default boolOptional. Default value true426 * @param bool $default Optional. Default value true 339 427 * @uses get_option() To get the forum-wide search setting 340 428 * @return bool Is forum-wide searching allowed? … … 351 439 * @since 2.4.0 bbPress (r4964) 352 440 * 353 * @param $default boolOptional. Default value false441 * @param bool $default Optional. Default value false 354 442 * @uses get_option() To get the threaded replies setting 355 443 * @return bool Are threaded replies allowed? … … 383 471 * @since 2.0.0 bbPress (r3412) 384 472 * 385 * @param $default boolOptional. Default value true473 * @param bool $default Optional. Default value true 386 474 * @uses get_option() To get the allow revisions 387 475 * @return bool Are revisions allowed? … … 398 486 * @since 2.0.0 bbPress (r2659) 399 487 * 400 * @param $default boolOptional. Default value488 * @param bool $default Optional. Default value 401 489 * @uses get_option() To get the allow anonymous option 402 490 * @return bool Is anonymous posting allowed? … … 413 501 * @since 2.0.0 bbPress (r3378) 414 502 * 415 * @param $default boolOptional. Default value false503 * @param bool $default Optional. Default value false 416 504 * @uses get_option() To get the global access option 417 505 * @return bool Is global access allowed? … … 428 516 * @since 2.2.0 bbPress (r4294) 429 517 * 430 * @param $default stringOptional. Default value empty518 * @param string $default Optional. Default value empty 431 519 * @uses get_option() To get the default forums role option 432 520 * @return string The default forums user role … … 443 531 * @since 2.0.0 bbPress (r3386) 444 532 * 445 * @param $default boolOptional. Default value true533 * @param bool $default Optional. Default value true 446 534 * @uses get_option() To get the WP editor option 447 535 * @return bool Use WP editor? … … 458 546 * @since 2.1.0 bbPress (r3752) 459 547 * 460 * @param $default boolOptional. Default value true548 * @param bool $default Optional. Default value true 461 549 * @uses get_option() To get the oEmbed option 462 550 * @return bool Use oEmbed? … … 473 561 * @since 2.1.0 bbPress (r3829) 474 562 * 475 * @param $default stringOptional. Default value 'default'563 * @param string $default Optional. Default value 'default' 476 564 * @uses get_option() To get the theme-package option 477 565 * @return string ID of the theme-package … … 488 576 * @since 2.0.0 bbPress (r3246) 489 577 * 490 * @param $default boolOptional. Default value 80578 * @param bool $default Optional. Default value 80 491 579 */ 492 580 function bbp_title_max_length( $default = 80 ) { … … 498 586 * @since 2.0.0 bbPress (r3246) 499 587 * 500 * @param $default boolOptional. Default value 80588 * @param bool $default Optional. Default value 80 501 589 * @uses get_option() To get the maximum title length 502 590 * @return int Is anonymous posting allowed? … … 513 601 * @since 2.1.0 bbPress (r3575) 514 602 * 515 * @param $default int Optional. Default value603 * @param int $default Optional. Default value 516 604 */ 517 605 function bbp_group_forums_root_id( $default = 0 ) { … … 523 611 * @since 2.1.0 bbPress (r3575) 524 612 * 525 * @param $default boolOptional. Default value 0613 * @param bool $default Optional. Default value 0 526 614 * @uses get_option() To get the root group forum ID 527 615 * @return int The post ID for the root forum … … 538 626 * @since 2.1.0 bbPress (r3575) 539 627 * 540 * @param $default boolOptional. Default value true628 * @param bool $default Optional. Default value true 541 629 * @uses get_option() To get the group forums option 542 630 * @return bool Is group forums enabled or not … … 553 641 * @since 2.1.0 bbPress (r3575) 554 642 * 555 * @param $default boolOptional. Default value true643 * @param bool $default Optional. Default value true 556 644 * @uses get_option() To get the Akismet option 557 645 * @return bool Is Akismet enabled or not … … 573 661 * @since 2.4.0 bbPress (r4932) 574 662 * 575 * @param $default boolOptional. Default value false663 * @param bool $default Optional. Default value false 576 664 * @uses get_option() To get the admin integration setting 577 665 * @return bool To deeply integrate settings, or not … … 605 693 * @since 2.1.0 bbPress (r3759) 606 694 * 695 * @param string $default Optional. Default value 'forums' 696 * @uses get_option() To get the slug 607 697 * @return string 608 698 */ … … 618 708 * @since 2.1.0 bbPress (r3759) 619 709 * 710 * @param bool $default Optional. Default value true 711 * @uses get_option() To get the setting 620 712 * @return bool 621 713 */ … … 631 723 * @since 2.4.0 bbPress (r4932) 632 724 * 725 * @param string $default Optional. Default value 'forums' 726 * @uses get_option() To get the setting 633 727 * @return string 634 728 */ … … 644 738 * @since 2.1.0 bbPress (r3759) 645 739 * 740 * @param string $default Optional. Default value 'forums' 741 * @uses get_option() To get the slug 646 742 * @return string 647 743 */ 648 744 function bbp_maybe_get_root_slug() { 649 $retval = ''; 650 651 if ( bbp_get_root_slug() && bbp_include_root_slug() ) { 652 $retval = trailingslashit( bbp_get_root_slug() ); 653 } 745 $slug = bbp_get_root_slug(); 746 $retval = ( ! empty( $slug ) && bbp_include_root_slug() ) 747 ? trailingslashit( $slug ) 748 : ''; 654 749 655 750 // Filter & return … … 662 757 * @since 2.1.0 bbPress (r3759) 663 758 * 759 * @param string $default Optional. Default value 'forum' 760 * @uses get_option() To get the slug 664 761 * @return string 665 762 */ … … 675 772 * @since 2.1.0 bbPress (r3759) 676 773 * 774 * @param string $default Optional. Default value 'topics' 775 * @uses get_option() To get the slug 677 776 * @return string 678 777 */ … … 688 787 * @since 2.4.0 bbPress (r4925) 689 788 * 789 * @param string $default Optional. Default value 'replies' 790 * @uses get_option() To get the slug 690 791 * @return string 691 792 */ … … 701 802 * @since 2.1.0 bbPress (r3759) 702 803 * 804 * @param string $default Optional. Default value 'topic' 805 * @uses get_option() To get the slug 703 806 * @return string 704 807 */ … … 714 817 * @since 2.1.0 bbPress (r3759) 715 818 * 819 * @param string $default Optional. Default value 'topic-tag' 820 * @uses get_option() To get the slug 716 821 * @return string 717 822 */ … … 727 832 * @since 2.1.0 bbPress (r3759) 728 833 * 834 * @param string $default Optional. Default value 'reply' 835 * @uses get_option() To get the slug 729 836 * @return string 730 837 */ … … 740 847 * @since 2.1.0 bbPress (r3759) 741 848 * 849 * @param string $default Optional. Default value 'users' 850 * @uses get_option() To get the slug 742 851 * @return string 743 852 */ … … 753 862 * @since 2.2.0 bbPress (r4187) 754 863 * 864 * @param string $default Optional. Default value 'favorites' 865 * @uses get_option() To get the slug 755 866 * @return string 756 867 */ … … 766 877 * @since 2.2.0 bbPress (r4187) 767 878 * 879 * @param string $default Optional. Default value 'subscriptions' 880 * @uses get_option() To get the slug 768 881 * @return string 769 882 */ … … 779 892 * @since 2.6.0 bbPress (r6320) 780 893 * 894 * @param string $default Optional. Default value 'engagements' 895 * @uses get_option() To get the slug 781 896 * @return string 782 897 */ … … 784 899 785 900 // Filter & return 786 return apply_filters( 'bbp_get_user_engagements_slug', get_option( '_bbp_user_eng agements_slug', $default ) );901 return apply_filters( 'bbp_get_user_engagements_slug', get_option( '_bbp_user_engs_slug', $default ) ); 787 902 } 788 903 … … 792 907 * @since 2.1.0 bbPress (r3759) 793 908 * 909 * @param string $default Optional. Default value 'view' 910 * @uses get_option() To get the slug 794 911 * @return string 795 912 */ … … 805 922 * @since 2.3.0 bbPress (r4579) 806 923 * 924 * @param string $default Optional. Default value 'search' 925 * @uses get_option() To get the slug 807 926 * @return string 808 927 */ … … 820 939 * @since 2.1.0 bbPress (r3790) 821 940 * 822 * @param $default stringOptional. Default empty string941 * @param string $default Optional. Default empty string 823 942 * @uses get_option() To get the old bb-config.php location 824 943 * @return string The location of the bb-config.php file, if any
Note: See TracChangeset
for help on using the changeset viewer.