PluginProbe
bbPress / 2.2.2
bbPress v2.2.2
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
bbpress / includes / core / options.php

options.php in bbPress 2.2.2, at includes/core/options.php

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