| 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 |
* @since bbPress (r3421) |
| 17 |
* |
| 18 |
* @return array Filtered option names and values |
| 19 |
*/ |
| 20 |
function bbp_get_default_options() { |
| 21 |
|
| 22 |
// Default options |
| 23 |
$options = array ( |
| 24 |
|
| 25 |
/** DB Version ********************************************************/ |
| 26 |
|
| 27 |
'_bbp_db_version' => '155', |
| 28 |
|
| 29 |
/** Settings **********************************************************/ |
| 30 |
|
| 31 |
// Lock post editing after 5 minutes |
| 32 |
'_bbp_edit_lock' => '5', |
| 33 |
|
| 34 |
// Throttle post time to 10 seconds |
| 35 |
'_bbp_throttle_time' => '10', |
| 36 |
|
| 37 |
// Favorites |
| 38 |
'_bbp_enable_favorites' => true, |
| 39 |
|
| 40 |
// Subscriptions |
| 41 |
'_bbp_enable_subscriptions' => true, |
| 42 |
|
| 43 |
// Allow anonymous posting |
| 44 |
'_bbp_allow_anonymous' => false, |
| 45 |
|
| 46 |
// Users from all sites can post |
| 47 |
'_bbp_allow_global_access' => false, |
| 48 |
|
| 49 |
/** Per Page **********************************************************/ |
| 50 |
|
| 51 |
// Topics per page |
| 52 |
'_bbp_topics_per_page' => '15', |
| 53 |
|
| 54 |
// Replies per page |
| 55 |
'_bbp_replies_per_page' => '15', |
| 56 |
|
| 57 |
// Forums per page |
| 58 |
'_bbp_forums_per_page' => '50', |
| 59 |
|
| 60 |
// Topics per RSS page |
| 61 |
'_bbp_topics_per_rss_page' => '25', |
| 62 |
|
| 63 |
// Replies per RSS page |
| 64 |
'_bbp_replies_per_rss_page' => '25', |
| 65 |
|
| 66 |
/** Page For **********************************************************/ |
| 67 |
|
| 68 |
// Page for forums |
| 69 |
'_bbp_page_for_forums' => '0', |
| 70 |
|
| 71 |
// Page for forums |
| 72 |
'_bbp_page_for_topics' => '0', |
| 73 |
|
| 74 |
// Page for login |
| 75 |
'_bbp_page_for_login' => '0', |
| 76 |
|
| 77 |
// Page for register |
| 78 |
'_bbp_page_for_register' => '0', |
| 79 |
|
| 80 |
// Page for lost-pass |
| 81 |
'_bbp_page_for_lost_pass' => '0', |
| 82 |
|
| 83 |
/** Archive Slugs *****************************************************/ |
| 84 |
|
| 85 |
// Forum archive slug |
| 86 |
'_bbp_root_slug' => 'forums', |
| 87 |
|
| 88 |
// Topic archive slug |
| 89 |
'_bbp_topic_archive_slug' => 'topics', |
| 90 |
|
| 91 |
/** Single Slugs ******************************************************/ |
| 92 |
|
| 93 |
// Include Forum archive before single slugs |
| 94 |
'_bbp_include_root' => true, |
| 95 |
|
| 96 |
// Forum slug |
| 97 |
'_bbp_forum_slug' => 'forum', |
| 98 |
|
| 99 |
// Topic slug |
| 100 |
'_bbp_topic_slug' => 'topic', |
| 101 |
|
| 102 |
// Reply slug |
| 103 |
'_bbp_reply_slug' => 'reply', |
| 104 |
|
| 105 |
// Topic tag slug |
| 106 |
'_bbp_topic_tag_slug' => 'topic-tag', |
| 107 |
|
| 108 |
/** Other Slugs *******************************************************/ |
| 109 |
|
| 110 |
// User profile slug |
| 111 |
'_bbp_user_slug' => 'users', |
| 112 |
|
| 113 |
// View slug |
| 114 |
'_bbp_view_slug' => 'view', |
| 115 |
|
| 116 |
/** Topics ************************************************************/ |
| 117 |
|
| 118 |
// Title Max Length |
| 119 |
'_bbp_title_max_length' => '80', |
| 120 |
|
| 121 |
// Super stickies |
| 122 |
'_bbp_super_sticky_topics' => '', |
| 123 |
|
| 124 |
/** Forums ************************************************************/ |
| 125 |
|
| 126 |
// Private forums |
| 127 |
'_bbp_private_forums' => '', |
| 128 |
|
| 129 |
// Hidden forums |
| 130 |
'_bbp_hidden_forums' => '', |
| 131 |
); |
| 132 |
|
| 133 |
return apply_filters( 'bbp_get_default_options', $options ); |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Add default options |
| 138 |
* |
| 139 |
* Hooked to bbp_activate, it is only called once when bbPress is activated. |
| 140 |
* This is non-destructive, so existing settings will not be overridden. |
| 141 |
* |
| 142 |
* @uses bbp_get_default_options() To get default options |
| 143 |
* @uses add_option() Adds default options |
| 144 |
* @uses do_action() Calls 'bbp_add_options' |
| 145 |
*/ |
| 146 |
function bbp_add_options() { |
| 147 |
|
| 148 |
// Get the default options and values |
| 149 |
$options = bbp_get_default_options(); |
| 150 |
|
| 151 |
// Add default options |
| 152 |
foreach ( $options as $key => $value ) |
| 153 |
add_option( $key, $value ); |
| 154 |
|
| 155 |
// Allow previously activated plugins to append their own options. |
| 156 |
do_action( 'bbp_add_options' ); |
| 157 |
} |
| 158 |
/** |
| 159 |
* Delete default options |
| 160 |
* |
| 161 |
* Hooked to bbp_uninstall, it is only called once when bbPress is uninstalled. |
| 162 |
* This is destructive, so existing settings will be destroyed. |
| 163 |
* |
| 164 |
* @uses bbp_get_default_options() To get default options |
| 165 |
* @uses delete_option() Removes default options |
| 166 |
* @uses do_action() Calls 'bbp_delete_options' |
| 167 |
*/ |
| 168 |
function bbp_delete_options() { |
| 169 |
|
| 170 |
// Get the default options and values |
| 171 |
$options = bbp_get_default_options(); |
| 172 |
|
| 173 |
// Add default options |
| 174 |
foreach ( $options as $key => $value ) |
| 175 |
delete_option( $key ); |
| 176 |
|
| 177 |
// Allow previously activated plugins to append their own options. |
| 178 |
do_action( 'bbp_delete_options' ); |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Add filters to each bbPress option and allow them to be overloaded from |
| 183 |
* inside the $bbp->options array. |
| 184 |
* |
| 185 |
* @since bbPress (r3451) |
| 186 |
* |
| 187 |
* @uses bbp_get_default_options() To get default options |
| 188 |
* @uses add_filter() To add filters to 'pre_option_{$key}' |
| 189 |
* @uses do_action() Calls 'bbp_add_option_filters' |
| 190 |
*/ |
| 191 |
function bbp_setup_option_filters() { |
| 192 |
|
| 193 |
// Get the default options and values |
| 194 |
$options = bbp_get_default_options(); |
| 195 |
|
| 196 |
// Add filters to each bbPress option |
| 197 |
foreach ( $options as $key => $value ) |
| 198 |
add_filter( 'pre_option_' . $key, 'bbp_pre_get_option' ); |
| 199 |
|
| 200 |
// Allow previously activated plugins to append their own options. |
| 201 |
do_action( 'bbp_setup_option_filters' ); |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* Filter default options and allow them to be overloaded from inside the |
| 206 |
* $bbp->options array. |
| 207 |
* |
| 208 |
* @since bbPress (r3451) |
| 209 |
* |
| 210 |
* @global bbPress $bbp |
| 211 |
* @param bool $value |
| 212 |
* @return mixed false if not overloaded, mixed if set |
| 213 |
*/ |
| 214 |
function bbp_pre_get_option( $value = false ) { |
| 215 |
global $bbp; |
| 216 |
|
| 217 |
// Get the name of the current filter so we can manipulate it |
| 218 |
$filter = current_filter(); |
| 219 |
|
| 220 |
// Remove the filter prefix |
| 221 |
$option = str_replace( 'pre_option_', '', $filter ); |
| 222 |
|
| 223 |
// Check the options global for preset value |
| 224 |
if ( !empty( $bbp->options[$option] ) ) |
| 225 |
$value = $bbp->options[$option]; |
| 226 |
|
| 227 |
// Always return a value, even if false |
| 228 |
return $value; |
| 229 |
} |
| 230 |
|
| 231 |
/** Active? *******************************************************************/ |
| 232 |
|
| 233 |
/** |
| 234 |
* Checks if favorites feature is enabled. |
| 235 |
* |
| 236 |
* @since bbPress (r2658) |
| 237 |
* |
| 238 |
* @param $default bool Optional.Default value |
| 239 |
* |
| 240 |
* @uses get_option() To get the favorites option |
| 241 |
* @return bool Is favorites enabled or not |
| 242 |
*/ |
| 243 |
function bbp_is_favorites_active( $default = true ) { |
| 244 |
return apply_filters( 'bbp_is_favorites_active', (bool) get_option( '_bbp_enable_favorites', $default ) ); |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* Checks if subscription feature is enabled. |
| 249 |
* |
| 250 |
* @since bbPress (r2658) |
| 251 |
* |
| 252 |
* @param $default bool Optional.Default value |
| 253 |
* |
| 254 |
* @uses get_option() To get the subscriptions option |
| 255 |
* @return bool Is subscription enabled or not |
| 256 |
*/ |
| 257 |
function bbp_is_subscriptions_active( $default = true ) { |
| 258 |
return apply_filters( 'bbp_is_subscriptions_active', (bool) get_option( '_bbp_enable_subscriptions', $default ) ); |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* Are topic and reply revisions allowed |
| 263 |
* |
| 264 |
* @since bbPress (r3412) |
| 265 |
* |
| 266 |
* @param $default bool Optional. Default value |
| 267 |
* |
| 268 |
* @uses get_option() To get the allow revisions |
| 269 |
* @return bool Are revisions allowed? |
| 270 |
*/ |
| 271 |
function bbp_allow_revisions( $default = true ) { |
| 272 |
return apply_filters( 'bbp_allow_revisions', (bool) get_option( '_bbp_allow_revisions', $default ) ); |
| 273 |
} |
| 274 |
|
| 275 |
/** |
| 276 |
* Is the anonymous posting allowed? |
| 277 |
* |
| 278 |
* @since bbPress (r2659) |
| 279 |
* |
| 280 |
* @param $default bool Optional. Default value |
| 281 |
* |
| 282 |
* @uses get_option() To get the allow anonymous option |
| 283 |
* @return bool Is anonymous posting allowed? |
| 284 |
*/ |
| 285 |
function bbp_allow_anonymous( $default = false ) { |
| 286 |
return apply_filters( 'bbp_allow_anonymous', (bool) get_option( '_bbp_allow_anonymous', $default ) ); |
| 287 |
} |
| 288 |
|
| 289 |
/** |
| 290 |
* Is this forum available to all users on all sites in this installation? |
| 291 |
* |
| 292 |
* @since bbPress (r3378) |
| 293 |
* |
| 294 |
* @param $default bool Optional. Default value |
| 295 |
* |
| 296 |
* @uses get_option() To get the global access option |
| 297 |
* @return bool Is global access allowed? |
| 298 |
*/ |
| 299 |
function bbp_allow_global_access( $default = false ) { |
| 300 |
return apply_filters( 'bbp_allow_global_access', (bool) get_option( '_bbp_allow_global_access', $default ) ); |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* Output the maximum length of a title |
| 305 |
* |
| 306 |
* @since bbPress (r3246) |
| 307 |
* |
| 308 |
* @param $default bool Optional. Default value |
| 309 |
*/ |
| 310 |
function bbp_title_max_length( $default = '80' ) { |
| 311 |
echo bbp_get_title_max_length( $default ); |
| 312 |
} |
| 313 |
/** |
| 314 |
* Return the maximum length of a title |
| 315 |
* |
| 316 |
* @since bbPress (r3246) |
| 317 |
* |
| 318 |
* @param $default bool Optional. Default value |
| 319 |
* |
| 320 |
* @uses get_option() To get the maximum title length |
| 321 |
* @return int Is anonymous posting allowed? |
| 322 |
*/ |
| 323 |
function bbp_get_title_max_length( $default = '80' ) { |
| 324 |
return apply_filters( 'bbp_get_title_max_length', (int) get_option( '_bbp_title_max_length', $default ) ); |
| 325 |
} |
| 326 |
|
| 327 |
?> |
| 328 |
|