| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* bbPress Options |
| 5 |
* |
| 6 |
* @package bbPress |
| 7 |
* @subpackage Options |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly |
| 11 |
if ( !defined( 'ABSPATH' ) ) exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Get the default site options and their values. |
| 15 |
* |
| 16 |
* These option |
| 17 |
* |
| 18 |
* @since bbPress (r3421) |
| 19 |
* @return array Filtered option names and values |
| 20 |
*/ |
| 21 |
function bbp_get_default_options() { |
| 22 |
|
| 23 |
// Default options |
| 24 |
return apply_filters( 'bbp_get_default_options', array( |
| 25 |
|
| 26 |
/** DB Version ********************************************************/ |
| 27 |
|
| 28 |
'_bbp_db_version' => bbpress()->db_version, |
| 29 |
|
| 30 |
/** Settings **********************************************************/ |
| 31 |
|
| 32 |
'_bbp_edit_lock' => 5, // Lock post editing after 5 minutes |
| 33 |
'_bbp_throttle_time' => 10, // Throttle post time to 10 seconds |
| 34 |
'_bbp_enable_favorites' => 1, // Favorites |
| 35 |
'_bbp_enable_subscriptions' => 1, // Subscriptions |
| 36 |
'_bbp_allow_anonymous' => 0, // Allow anonymous posting |
| 37 |
'_bbp_allow_global_access' => 0, // Users from all sites can post |
| 38 |
'_bbp_use_wp_editor' => 1, // Use the WordPress editor if available |
| 39 |
'_bbp_use_autoembed' => 0, // Allow oEmbed in topics and replies |
| 40 |
'_bbp_theme_package_id' => 'default', // The ID for the current theme packag. |
| 41 |
|
| 42 |
/** Per Page **********************************************************/ |
| 43 |
|
| 44 |
'_bbp_topics_per_page' => 15, // Topics per page |
| 45 |
'_bbp_replies_per_page' => 15, // Replies per page |
| 46 |
'_bbp_forums_per_page' => 50, // Forums per page |
| 47 |
'_bbp_topics_per_rss_page' => 25, // Topics per RSS page |
| 48 |
'_bbp_replies_per_rss_page' => 25, // Replies per RSS page |
| 49 |
|
| 50 |
/** Page For **********************************************************/ |
| 51 |
|
| 52 |
'_bbp_page_for_forums' => 0, // Page for forums |
| 53 |
'_bbp_page_for_topics' => 0, // Page for forums |
| 54 |
'_bbp_page_for_login' => 0, // Page for login |
| 55 |
'_bbp_page_for_register' => 0, // Page for register |
| 56 |
'_bbp_page_for_lost_pass' => 0, // Page for lost-pass |
| 57 |
|
| 58 |
/** Archive Slugs *****************************************************/ |
| 59 |
|
| 60 |
'_bbp_root_slug' => 'forums', // Forum archive slug |
| 61 |
'_bbp_topic_archive_slug' => 'topics', // Topic archive slug |
| 62 |
|
| 63 |
/** Single Slugs ******************************************************/ |
| 64 |
|
| 65 |
'_bbp_include_root' => 1, // Include forum-archive before single slugs |
| 66 |
'_bbp_forum_slug' => 'forum', // Forum slug |
| 67 |
'_bbp_topic_slug' => 'topic', // Topic slug |
| 68 |
'_bbp_reply_slug' => 'reply', // Reply slug |
| 69 |
'_bbp_topic_tag_slug' => 'topic-tag', // Topic tag slug |
| 70 |
|
| 71 |
/** Other Slugs *******************************************************/ |
| 72 |
|
| 73 |
'_bbp_user_slug' => 'users', // User profile slug |
| 74 |
'_bbp_view_slug' => 'view', // View slug |
| 75 |
|
| 76 |
/** Topics ************************************************************/ |
| 77 |
|
| 78 |
'_bbp_title_max_length' => 80, // Title Max Length |
| 79 |
'_bbp_super_sticky_topics' => '', // Super stickies |
| 80 |
|
| 81 |
/** Forums ************************************************************/ |
| 82 |
|
| 83 |
'_bbp_private_forums' => '', // Private forums |
| 84 |
'_bbp_hidden_forums' => '', // Hidden forums |
| 85 |
|
| 86 |
/** BuddyPress ********************************************************/ |
| 87 |
|
| 88 |
'_bbp_enable_group_forums' => 1, // Enable BuddyPress Group Extension |
| 89 |
'_bbp_group_forums_root_id' => 0, // Group Forums parent forum id |
| 90 |
|
| 91 |
/** Akismet ***********************************************************/ |
| 92 |
|
| 93 |
'_bbp_enable_akismet' => 1 // Users from all sites can post |
| 94 |
|
| 95 |
) ); |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Add default options |
| 100 |
* |
| 101 |
* Hooked to bbp_activate, it is only called once when bbPress is activated. |
| 102 |
* This is non-destructive, so existing settings will not be overridden. |
| 103 |
* |
| 104 |
* @since bbPress (r3421) |
| 105 |
* @uses bbp_get_default_options() To get default options |
| 106 |
* @uses add_option() Adds default options |
| 107 |
* @uses do_action() Calls 'bbp_add_options' |
| 108 |
*/ |
| 109 |
function bbp_add_options() { |
| 110 |
|
| 111 |
// Add default options |
| 112 |
foreach ( bbp_get_default_options() as $key => $value ) |
| 113 |
add_option( $key, $value ); |
| 114 |
|
| 115 |
// Allow previously activated plugins to append their own options. |
| 116 |
do_action( 'bbp_add_options' ); |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Delete default options |
| 121 |
* |
| 122 |
* Hooked to bbp_uninstall, it is only called once when bbPress is uninstalled. |
| 123 |
* This is destructive, so existing settings will be destroyed. |
| 124 |
* |
| 125 |
* @since bbPress (r3421) |
| 126 |
* @uses bbp_get_default_options() To get default options |
| 127 |
* @uses delete_option() Removes default options |
| 128 |
* @uses do_action() Calls 'bbp_delete_options' |
| 129 |
*/ |
| 130 |
function bbp_delete_options() { |
| 131 |
|
| 132 |
// Add default options |
| 133 |
foreach ( bbp_get_default_options() as $key => $value ) |
| 134 |
delete_option( $key ); |
| 135 |
|
| 136 |
// Allow previously activated plugins to append their own options. |
| 137 |
do_action( 'bbp_delete_options' ); |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Add filters to each bbPress option and allow them to be overloaded from |
| 142 |
* inside the $bbp->options array. |
| 143 |
* |
| 144 |
* @since bbPress (r3451) |
| 145 |
* @uses bbp_get_default_options() To get default options |
| 146 |
* @uses add_filter() To add filters to 'pre_option_{$key}' |
| 147 |
* @uses do_action() Calls 'bbp_add_option_filters' |
| 148 |
*/ |
| 149 |
function bbp_setup_option_filters() { |
| 150 |
|
| 151 |
// Add filters to each bbPress option |
| 152 |
foreach ( bbp_get_default_options() as $key => $value ) |
| 153 |
add_filter( 'pre_option_' . $key, 'bbp_pre_get_option' ); |
| 154 |
|
| 155 |
// Allow previously activated plugins to append their own options. |
| 156 |
do_action( 'bbp_setup_option_filters' ); |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Filter default options and allow them to be overloaded from inside the |
| 161 |
* $bbp->options array. |
| 162 |
* |
| 163 |
* @since bbPress (r3451) |
| 164 |
* @param bool $value Optional. Default value false |
| 165 |
* @return mixed false if not overloaded, mixed if set |
| 166 |
*/ |
| 167 |
function bbp_pre_get_option( $value = '' ) { |
| 168 |
$bbp = bbpress(); |
| 169 |
|
| 170 |
// Remove the filter prefix |
| 171 |
$option = str_replace( 'pre_option_', '', current_filter() ); |
| 172 |
|
| 173 |
// Check the options global for preset value |
| 174 |
if ( isset( $bbp->options[$option] ) ) |
| 175 |
$value = $bbp->options[$option]; |
| 176 |
|
| 177 |
// Always return a value, even if false |
| 178 |
return $value; |
| 179 |
} |
| 180 |
|
| 181 |
/** Active? *******************************************************************/ |
| 182 |
|
| 183 |
/** |
| 184 |
* Checks if favorites feature is enabled. |
| 185 |
* |
| 186 |
* @since bbPress (r2658) |
| 187 |
* @param $default bool Optional.Default value true |
| 188 |
* @uses get_option() To get the favorites option |
| 189 |
* @return bool Is favorites enabled or not |
| 190 |
*/ |
| 191 |
function bbp_is_favorites_active( $default = 1 ) { |
| 192 |
return (bool) apply_filters( 'bbp_is_favorites_active', (bool) get_option( '_bbp_enable_favorites', $default ) ); |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Checks if subscription feature is enabled. |
| 197 |
* |
| 198 |
* @since bbPress (r2658) |
| 199 |
* @param $default bool Optional.Default value true |
| 200 |
* @uses get_option() To get the subscriptions option |
| 201 |
* @return bool Is subscription enabled or not |
| 202 |
*/ |
| 203 |
function bbp_is_subscriptions_active( $default = 1 ) { |
| 204 |
return (bool) apply_filters( 'bbp_is_subscriptions_active', (bool) get_option( '_bbp_enable_subscriptions', $default ) ); |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* Are topic and reply revisions allowed |
| 209 |
* |
| 210 |
* @since bbPress (r3412) |
| 211 |
* @param $default bool Optional. Default value true |
| 212 |
* @uses get_option() To get the allow revisions |
| 213 |
* @return bool Are revisions allowed? |
| 214 |
*/ |
| 215 |
function bbp_allow_revisions( $default = 1 ) { |
| 216 |
return (bool) apply_filters( 'bbp_allow_revisions', (bool) get_option( '_bbp_allow_revisions', $default ) ); |
| 217 |
} |
| 218 |
|
| 219 |
/** |
| 220 |
* Is the anonymous posting allowed? |
| 221 |
* |
| 222 |
* @since bbPress (r2659) |
| 223 |
* @param $default bool Optional. Default value |
| 224 |
* @uses get_option() To get the allow anonymous option |
| 225 |
* @return bool Is anonymous posting allowed? |
| 226 |
*/ |
| 227 |
function bbp_allow_anonymous( $default = 0 ) { |
| 228 |
return apply_filters( 'bbp_allow_anonymous', (bool) get_option( '_bbp_allow_anonymous', $default ) ); |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* Is this forum available to all users on all sites in this installation? |
| 233 |
* |
| 234 |
* @since bbPress (r3378) |
| 235 |
* @param $default bool Optional. Default value false |
| 236 |
* @uses get_option() To get the global access option |
| 237 |
* @return bool Is global access allowed? |
| 238 |
*/ |
| 239 |
function bbp_allow_global_access( $default = 0 ) { |
| 240 |
return (bool) apply_filters( 'bbp_allow_global_access', (bool) get_option( '_bbp_allow_global_access', $default ) ); |
| 241 |
} |
| 242 |
|
| 243 |
/** |
| 244 |
* Use the WordPress editor if available |
| 245 |
* |
| 246 |
* @since bbPress (r3386) |
| 247 |
* @param $default bool Optional. Default value true |
| 248 |
* @uses get_option() To get the WP editor option |
| 249 |
* @return bool Use WP editor? |
| 250 |
*/ |
| 251 |
function bbp_use_wp_editor( $default = 1 ) { |
| 252 |
return (bool) apply_filters( 'bbp_use_wp_editor', (bool) get_option( '_bbp_use_wp_editor', $default ) ); |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* Use WordPress's oEmbed API |
| 257 |
* |
| 258 |
* @since bbPress (r3752) |
| 259 |
* @param $default bool Optional. Default value true |
| 260 |
* @uses get_option() To get the oEmbed option |
| 261 |
* @return bool Use oEmbed? |
| 262 |
*/ |
| 263 |
function bbp_use_autoembed( $default = 1 ) { |
| 264 |
return (bool) apply_filters( 'bbp_use_autoembed', (bool) get_option( '_bbp_use_autoembed', $default ) ); |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* Get the current theme package ID |
| 269 |
* |
| 270 |
* @since bbPress (r3829) |
| 271 |
* @param $default string Optional. Default value 'default' |
| 272 |
* @uses get_option() To get the subtheme option |
| 273 |
* @return string ID of the subtheme |
| 274 |
*/ |
| 275 |
function bbp_get_theme_package_id( $default = 'default' ) { |
| 276 |
return apply_filters( 'bbp_get_theme_package_id', get_option( '_bbp_theme_package_id', $default ) ); |
| 277 |
} |
| 278 |
|
| 279 |
/** |
| 280 |
* Output the maximum length of a title |
| 281 |
* |
| 282 |
* @since bbPress (r3246) |
| 283 |
* @param $default bool Optional. Default value 80 |
| 284 |
*/ |
| 285 |
function bbp_title_max_length( $default = 80 ) { |
| 286 |
echo bbp_get_title_max_length( $default ); |
| 287 |
} |
| 288 |
/** |
| 289 |
* Return the maximum length of a title |
| 290 |
* |
| 291 |
* @since bbPress (r3246) |
| 292 |
* @param $default bool Optional. Default value 80 |
| 293 |
* @uses get_option() To get the maximum title length |
| 294 |
* @return int Is anonymous posting allowed? |
| 295 |
*/ |
| 296 |
function bbp_get_title_max_length( $default = 80 ) { |
| 297 |
return (int) apply_filters( 'bbp_get_title_max_length', (int) get_option( '_bbp_title_max_length', $default ) ); |
| 298 |
} |
| 299 |
|
| 300 |
/** |
| 301 |
* Output the grop forums root parent forum id |
| 302 |
* |
| 303 |
* @since bbPress (r3575) |
| 304 |
* @param $default int Optional. Default value |
| 305 |
*/ |
| 306 |
function bbp_group_forums_root_id( $default = 0 ) { |
| 307 |
echo bbp_get_group_forums_root_id( $default ); |
| 308 |
} |
| 309 |
/** |
| 310 |
* Return the grop forums root parent forum id |
| 311 |
* |
| 312 |
* @since bbPress (r3575) |
| 313 |
* @param $default bool Optional. Default value 0 |
| 314 |
* @uses get_option() To get the root group forum ID |
| 315 |
* @return int The post ID for the root forum |
| 316 |
*/ |
| 317 |
function bbp_get_group_forums_root_id( $default = 0 ) { |
| 318 |
return (int) apply_filters( 'bbp_get_group_forums_root_id', (int) get_option( '_bbp_group_forums_root_id', $default ) ); |
| 319 |
} |
| 320 |
|
| 321 |
/** |
| 322 |
* Checks if BuddyPress Group Forums are enabled |
| 323 |
* |
| 324 |
* @since bbPress (r3575) |
| 325 |
* @param $default bool Optional. Default value true |
| 326 |
* @uses get_option() To get the group forums option |
| 327 |
* @return bool Is group forums enabled or not |
| 328 |
*/ |
| 329 |
function bbp_is_group_forums_active( $default = 1 ) { |
| 330 |
return (bool) apply_filters( 'bbp_is_group_forums_active', (bool) get_option( '_bbp_enable_group_forums', $default ) ); |
| 331 |
} |
| 332 |
|
| 333 |
/** |
| 334 |
* Checks if Akismet is enabled |
| 335 |
* |
| 336 |
* @since bbPress (r3575) |
| 337 |
* @param $default bool Optional. Default value true |
| 338 |
* @uses get_option() To get the Akismet option |
| 339 |
* @return bool Is Akismet enabled or not |
| 340 |
*/ |
| 341 |
function bbp_is_akismet_active( $default = 1 ) { |
| 342 |
return (bool) apply_filters( 'bbp_is_akismet_active', (bool) get_option( '_bbp_enable_akismet', $default ) ); |
| 343 |
} |
| 344 |
|
| 345 |
/** Slugs *********************************************************************/ |
| 346 |
|
| 347 |
/** |
| 348 |
* Return the root slug |
| 349 |
* |
| 350 |
* @since bbPress (r3759) |
| 351 |
* @return string |
| 352 |
*/ |
| 353 |
function bbp_get_root_slug( $default = 'forums' ) { |
| 354 |
return apply_filters( 'bbp_get_root_slug', get_option( '_bbp_root_slug', $default ) ); |
| 355 |
} |
| 356 |
|
| 357 |
/** |
| 358 |
* Are we including the root slug in front of forum pages? |
| 359 |
* |
| 360 |
* @since bbPress (r3759) |
| 361 |
* @return bool |
| 362 |
*/ |
| 363 |
function bbp_include_root_slug( $default = 1 ) { |
| 364 |
return (bool) apply_filters( 'bbp_include_root_slug', (bool) get_option( '_bbp_include_root', $default ) ); |
| 365 |
} |
| 366 |
|
| 367 |
/** |
| 368 |
* Maybe return the root slug, based on whether or not it's included in the url |
| 369 |
* |
| 370 |
* @since bbPress (r3759) |
| 371 |
* @return string |
| 372 |
*/ |
| 373 |
function bbp_maybe_get_root_slug() { |
| 374 |
$retval = ''; |
| 375 |
|
| 376 |
if ( bbp_get_root_slug() && bbp_include_root_slug() ) |
| 377 |
$retval = trailingslashit( bbp_get_root_slug() ); |
| 378 |
|
| 379 |
return apply_filters( 'bbp_maybe_get_root_slug', $retval ); |
| 380 |
} |
| 381 |
|
| 382 |
/** |
| 383 |
* Return the single forum slug |
| 384 |
* |
| 385 |
* @since bbPress (r3759) |
| 386 |
* @return string |
| 387 |
*/ |
| 388 |
function bbp_get_forum_slug( $default = 'forum' ) {; |
| 389 |
return apply_filters( 'bbp_get_root_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_forum_slug', $default ) ); |
| 390 |
} |
| 391 |
|
| 392 |
/** |
| 393 |
* Return the topic archive slug |
| 394 |
* |
| 395 |
* @since bbPress (r3759) |
| 396 |
* @return string |
| 397 |
*/ |
| 398 |
function bbp_get_topic_archive_slug( $default = 'topics' ) { |
| 399 |
return apply_filters( 'bbp_get_topic_archive_slug', get_option( '_bbp_topic_archive_slug', $default ) ); |
| 400 |
} |
| 401 |
|
| 402 |
/** |
| 403 |
* Return the single topic slug |
| 404 |
* |
| 405 |
* @since bbPress (r3759) |
| 406 |
* @return string |
| 407 |
*/ |
| 408 |
function bbp_get_topic_slug( $default = 'topic' ) { |
| 409 |
return apply_filters( 'bbp_get_topic_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_topic_slug', $default ) ); |
| 410 |
} |
| 411 |
|
| 412 |
/** |
| 413 |
* Return the topic-tag taxonomy slug |
| 414 |
* |
| 415 |
* @since bbPress (r3759) |
| 416 |
* @return string |
| 417 |
*/ |
| 418 |
function bbp_get_topic_tag_tax_slug( $default = 'topic-tag' ) { |
| 419 |
return apply_filters( 'bbp_get_topic_tag_tax_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_topic_tag_slug', $default ) ); |
| 420 |
} |
| 421 |
|
| 422 |
/** |
| 423 |
* Return the single reply slug (used mostly for editing) |
| 424 |
* |
| 425 |
* @since bbPress (r3759) |
| 426 |
* @return string |
| 427 |
*/ |
| 428 |
function bbp_get_reply_slug( $default = 'reply' ) { |
| 429 |
return apply_filters( 'bbp_get_reply_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_reply_slug', $default ) ); |
| 430 |
} |
| 431 |
|
| 432 |
/** |
| 433 |
* Return the single user slug |
| 434 |
* |
| 435 |
* @since bbPress (r3759) |
| 436 |
* @return string |
| 437 |
*/ |
| 438 |
function bbp_get_user_slug( $default = 'user' ) { |
| 439 |
return apply_filters( 'bbp_get_user_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_user_slug', $default ) ); |
| 440 |
} |
| 441 |
|
| 442 |
/** |
| 443 |
* Return the topic view slug |
| 444 |
* |
| 445 |
* @since bbPress (r3759) |
| 446 |
* @return string |
| 447 |
*/ |
| 448 |
function bbp_get_view_slug( $default = 'view' ) { |
| 449 |
return apply_filters( 'bbp_get_view_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_view_slug', $default ) ); |
| 450 |
} |
| 451 |
|
| 452 |
/** Legacy ********************************************************************/ |
| 453 |
|
| 454 |
/** |
| 455 |
* Checks if there is a previous BuddyPress Forum configuration |
| 456 |
* |
| 457 |
* @since bbPress (r3790) |
| 458 |
* @param $default string Optional. Default empty string |
| 459 |
* @uses get_option() To get the old bb-config.php location |
| 460 |
* @return string The location of the bb-config.php file, if any |
| 461 |
*/ |
| 462 |
function bbp_get_config_location( $default = '' ) { |
| 463 |
return apply_filters( 'bbp_get_config_location', get_option( 'bb-config-location', $default ) ); |
| 464 |
} |
| 465 |
|