PluginProbe
bbPress / 2.0.3
bbPress v2.0.3
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 / bbp-admin / bbp-settings.php

bbp-settings.php in bbPress 2.0.3, at bbp-admin/bbp-settings.php

644 lines 19.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Admin Settings
5 *
6 * @package bbPress
7 * @subpackage Administration
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /** Start Main Section ********************************************************/
14
15 /**
16 * Main settings section description for the settings page
17 *
18 * @since bbPress (r2786)
19 */
20 function bbp_admin_setting_callback_main_section() {
21 ?>
22
23 <p><?php _e( 'Main settings for the bbPress plugin', 'bbpress' ); ?></p>
24
25 <?php
26 }
27
28 /**
29 * Edit lock setting field
30 *
31 * @since bbPress (r2737)
32 *
33 * @uses bbp_form_option() To output the option value
34 */
35 function bbp_admin_setting_callback_editlock() {
36 ?>
37
38 <input name="_bbp_edit_lock" type="text" id="_bbp_edit_lock" value="<?php bbp_form_option( '_bbp_edit_lock', '5' ); ?>" class="small-text" />
39 <label for="_bbp_edit_lock"><?php _e( 'minutes', 'bbpress' ); ?></label>
40
41 <?php
42 }
43
44 /**
45 * Throttle setting field
46 *
47 * @since bbPress (r2737)
48 *
49 * @uses bbp_form_option() To output the option value
50 */
51 function bbp_admin_setting_callback_throttle() {
52 ?>
53
54 <input name="_bbp_throttle_time" type="text" id="_bbp_throttle_time" value="<?php bbp_form_option( '_bbp_throttle_time', '10' ); ?>" class="small-text" />
55 <label for="_bbp_throttle_time"><?php _e( 'seconds', 'bbpress' ); ?></label>
56
57 <?php
58 }
59
60 /**
61 * Allow favorites setting field
62 *
63 * @since bbPress (r2786)
64 *
65 * @uses checked() To display the checked attribute
66 */
67 function bbp_admin_setting_callback_favorites() {
68 ?>
69
70 <input id="_bbp_enable_favorites" name="_bbp_enable_favorites" type="checkbox" id="_bbp_enable_favorites" value="1" <?php checked( bbp_is_favorites_active( true ) ); ?> />
71 <label for="_bbp_enable_favorites"><?php _e( 'Allow users to mark topics as favorites?', 'bbpress' ); ?></label>
72
73 <?php
74 }
75
76 /**
77 * Allow subscriptions setting field
78 *
79 * @since bbPress (r2737)
80 *
81 * @uses checked() To display the checked attribute
82 */
83 function bbp_admin_setting_callback_subscriptions() {
84 ?>
85
86 <input id="_bbp_enable_subscriptions" name="_bbp_enable_subscriptions" type="checkbox" id="_bbp_enable_subscriptions" value="1" <?php checked( bbp_is_subscriptions_active( true ) ); ?> />
87 <label for="_bbp_enable_subscriptions"><?php _e( 'Allow users to subscribe to topics', 'bbpress' ); ?></label>
88
89 <?php
90 }
91
92 /**
93 * Allow topic and reply revisions
94 *
95 * @since bbPress (r3412)
96 *
97 * @uses checked() To display the checked attribute
98 */
99 function bbp_admin_setting_callback_revisions() {
100 ?>
101
102 <input id="_bbp_allow_revisions" name="_bbp_allow_revisions" type="checkbox" id="_bbp_allow_revisions" value="1" <?php checked( bbp_allow_revisions( true ) ); ?> />
103 <label for="_bbp_allow_revisions"><?php _e( 'Allow topic and reply revision logging', 'bbpress' ); ?></label>
104
105 <?php
106 }
107
108 /**
109 * Allow anonymous posting setting field
110 *
111 * @since bbPress (r2737)
112 *
113 * @uses checked() To display the checked attribute
114 */
115 function bbp_admin_setting_callback_anonymous() {
116 ?>
117
118 <input id="_bbp_allow_anonymous" name="_bbp_allow_anonymous" type="checkbox" id="_bbp_allow_anonymous" value="1" <?php checked( bbp_allow_anonymous( false ) ); ?> />
119 <label for="_bbp_allow_anonymous"><?php _e( 'Allow guest users without accounts to create topics and replies', 'bbpress' ); ?></label>
120
121 <?php
122 }
123
124 /**
125 * Allow global access setting field
126 *
127 * @since bbPress (r3378)
128 *
129 * @uses checked() To display the checked attribute
130 */
131 function bbp_admin_setting_callback_global_access() {
132 ?>
133
134 <input id="_bbp_allow_global_access" name="_bbp_allow_global_access" type="checkbox" id="_bbp_allow_global_access" value="1" <?php checked( bbp_allow_global_access( false ) ); ?> />
135 <label for="_bbp_allow_global_access"><?php _e( 'Allow all users of your multisite installation to create topics and replies', 'bbpress' ); ?></label>
136
137 <?php
138 }
139
140 /** Start Per Page Section ****************************************************/
141
142 /**
143 * Per page settings section description for the settings page
144 *
145 * @since bbPress (r2786)
146 */
147 function bbp_admin_setting_callback_per_page_section() {
148 ?>
149
150 <p><?php _e( 'Per page settings for the bbPress plugin', 'bbpress' ); ?></p>
151
152 <?php
153 }
154
155 /**
156 * Topics per page setting field
157 *
158 * @since bbPress (r2786)
159 *
160 * @uses bbp_form_option() To output the option value
161 */
162 function bbp_admin_setting_callback_topics_per_page() {
163 ?>
164
165 <input name="_bbp_topics_per_page" type="text" id="_bbp_topics_per_page" value="<?php bbp_form_option( '_bbp_topics_per_page', '15' ); ?>" class="small-text" />
166 <label for="_bbp_topics_per_page"><?php _e( 'per page', 'bbpress' ); ?></label>
167
168 <?php
169 }
170
171 /**
172 * Replies per page setting field
173 *
174 * @since bbPress (r2786)
175 *
176 * @uses bbp_form_option() To output the option value
177 */
178 function bbp_admin_setting_callback_replies_per_page() {
179 ?>
180
181 <input name="_bbp_replies_per_page" type="text" id="_bbp_replies_per_page" value="<?php bbp_form_option( '_bbp_replies_per_page', '15' ); ?>" class="small-text" />
182 <label for="_bbp_replies_per_page"><?php _e( 'per page', 'bbpress' ); ?></label>
183
184 <?php
185 }
186
187 /** Start Per RSS Page Section ************************************************/
188
189 /**
190 * Per page settings section description for the settings page
191 *
192 * @since bbPress (r2786)
193 */
194 function bbp_admin_setting_callback_per_rss_page_section() {
195 ?>
196
197 <p><?php _e( 'Per RSS page settings for the bbPress plugin', 'bbpress' ); ?></p>
198
199 <?php
200 }
201
202 /**
203 * Topics per RSS page setting field
204 *
205 * @since bbPress (r2786)
206 *
207 * @uses bbp_form_option() To output the option value
208 */
209 function bbp_admin_setting_callback_topics_per_rss_page() {
210 ?>
211
212 <input name="_bbp_topics_per_rss_page" type="text" id="_bbp_topics_per_rss_page" value="<?php bbp_form_option( '_bbp_topics_per_rss_page', '25' ); ?>" class="small-text" />
213 <label for="_bbp_topics_per_rss_page"><?php _e( 'per page', 'bbpress' ); ?></label>
214
215 <?php
216 }
217
218 /**
219 * Replies per RSS page setting field
220 *
221 * @since bbPress (r2786)
222 *
223 * @uses bbp_form_option() To output the option value
224 */
225 function bbp_admin_setting_callback_replies_per_rss_page() {
226 ?>
227
228 <input name="_bbp_replies_per_rss_page" type="text" id="_bbp_replies_per_rss_page" value="<?php bbp_form_option( '_bbp_replies_per_rss_page', '25' ); ?>" class="small-text" />
229 <label for="_bbp_replies_per_rss_page"><?php _e( 'per page', 'bbpress' ); ?></label>
230
231 <?php
232 }
233
234 /** Start Slug Section ********************************************************/
235
236 /**
237 * Slugs settings section description for the settings page
238 *
239 * @since bbPress (r2786)
240 */
241 function bbp_admin_setting_callback_root_slug_section() {
242
243 // Flush rewrite rules when this section is saved
244 if ( isset( $_GET['settings-updated'] ) && isset( $_GET['page'] ) )
245 flush_rewrite_rules(); ?>
246
247 <p><?php printf( __( 'Include custom root slugs to prefix your forums and topics with. These can be partnered with WordPress pages to allow more flexibility.', 'bbpress' ), get_admin_url( null, 'options-permalink.php' ) ); ?></p>
248
249 <?php
250 }
251
252 /**
253 * Root slug setting field
254 *
255 * @since bbPress (r2786)
256 *
257 * @uses bbp_form_option() To output the option value
258 */
259 function bbp_admin_setting_callback_root_slug() {
260 ?>
261
262 <input name="_bbp_root_slug" type="text" id="_bbp_root_slug" class="regular-text code" value="<?php bbp_form_option( '_bbp_root_slug', 'forums', true ); ?>" />
263
264 <?php
265 // Slug Check
266 bbp_form_slug_conflict_check( '_bbp_root_slug', 'forums' );
267 }
268
269 /**
270 * Topic archive slug setting field
271 *
272 * @since bbPress (r2786)
273 *
274 * @uses bbp_form_option() To output the option value
275 */
276 function bbp_admin_setting_callback_topic_archive_slug() {
277 ?>
278
279 <input name="_bbp_topic_archive_slug" type="text" id="_bbp_topic_archive_slug" class="regular-text code" value="<?php bbp_form_option( '_bbp_topic_archive_slug', 'topics', true ); ?>" />
280
281 <?php
282 // Slug Check
283 bbp_form_slug_conflict_check( '_bbp_topic_archive_slug', 'topics' );
284 }
285
286 /** Single Slugs **************************************************************/
287
288 /**
289 * Slugs settings section description for the settings page
290 *
291 * @since bbPress (r2786)
292 */
293 function bbp_admin_setting_callback_single_slug_section() {
294 ?>
295
296 <p><?php printf( __( 'You can enter custom slugs for your single forums, topics, replies, and tags URLs here. If you change these, existing permalinks will also change.', 'bbpress' ), get_admin_url( null, 'options-permalink.php' ) ); ?></p>
297
298 <?php
299 }
300
301 /**
302 * Include root slug setting field
303 *
304 * @since bbPress (r2786)
305 *
306 * @uses checked() To display the checked attribute
307 */
308 function bbp_admin_setting_callback_include_root() {
309 ?>
310
311 <input id="_bbp_include_root" name="_bbp_include_root" type="checkbox" id="_bbp_include_root" value="1" <?php checked( get_option( '_bbp_include_root', true ) ); ?> />
312 <label for="_bbp_include_root"><?php _e( 'Prefix your forum area with the Forum Base slug (Recommended)', 'bbpress' ); ?></label>
313
314 <?php
315 }
316
317 /**
318 * Forum slug setting field
319 *
320 * @since bbPress (r2786)
321 *
322 * @uses bbp_form_option() To output the option value
323 */
324 function bbp_admin_setting_callback_forum_slug() {
325 ?>
326
327 <input name="_bbp_forum_slug" type="text" id="_bbp_forum_slug" class="regular-text code" value="<?php bbp_form_option( '_bbp_forum_slug', 'forum', true ); ?>" />
328
329 <?php
330 // Slug Check
331 bbp_form_slug_conflict_check( '_bbp_forum_slug', 'forum' );
332 }
333
334 /**
335 * Topic slug setting field
336 *
337 * @since bbPress (r2786)
338 *
339 * @uses bbp_form_option() To output the option value
340 */
341 function bbp_admin_setting_callback_topic_slug() {
342 ?>
343
344 <input name="_bbp_topic_slug" type="text" id="_bbp_topic_slug" class="regular-text code" value="<?php bbp_form_option( '_bbp_topic_slug', 'topic', true ); ?>" />
345
346 <?php
347 // Slug Check
348 bbp_form_slug_conflict_check( '_bbp_topic_slug', 'topic' );
349 }
350
351 /**
352 * Reply slug setting field
353 *
354 * @since bbPress (r2786)
355 *
356 * @uses bbp_form_option() To output the option value
357 */
358 function bbp_admin_setting_callback_reply_slug() {
359 ?>
360
361 <input name="_bbp_reply_slug" type="text" id="_bbp_reply_slug" class="regular-text code" value="<?php bbp_form_option( '_bbp_reply_slug', 'reply', true ); ?>" />
362
363 <?php
364 // Slug Check
365 bbp_form_slug_conflict_check( '_bbp_reply_slug', 'reply' );
366 }
367
368 /**
369 * Topic tag slug setting field
370 *
371 * @since bbPress (r2786)
372 *
373 * @uses bbp_form_option() To output the option value
374 */
375 function bbp_admin_setting_callback_topic_tag_slug() {
376 ?>
377
378 <input name="_bbp_topic_tag_slug" type="text" id="_bbp_topic_tag_slug" class="regular-text code" value="<?php bbp_form_option( '_bbp_topic_tag_slug', 'topic-tag', true ); ?>" />
379
380 <?php
381
382 // Slug Check
383 bbp_form_slug_conflict_check( '_bbp_topic_tag_slug', 'topic-tag' );
384 }
385
386 /** Other Slugs ***************************************************************/
387
388 /**
389 * User slug setting field
390 *
391 * @since bbPress (r2786)
392 *
393 * @uses bbp_form_option() To output the option value
394 */
395 function bbp_admin_setting_callback_user_slug() {
396 ?>
397
398 <input name="_bbp_user_slug" type="text" id="_bbp_user_slug" class="regular-text code" value="<?php bbp_form_option( '_bbp_user_slug', 'users', true ); ?>" />
399
400 <?php
401 // Slug Check
402 bbp_form_slug_conflict_check( '_bbp_user_slug', 'users' );
403 }
404
405 /**
406 * View slug setting field
407 *
408 * @since bbPress (r2789)
409 *
410 * @uses bbp_form_option() To output the option value
411 */
412 function bbp_admin_setting_callback_view_slug() {
413 ?>
414
415 <input name="_bbp_view_slug" type="text" id="_bbp_view_slug" class="regular-text code" value="<?php bbp_form_option( '_bbp_view_slug', 'view', true ); ?>" />
416
417 <?php
418 // Slug Check
419 bbp_form_slug_conflict_check( '_bbp_view_slug', 'view' );
420 }
421
422 /** Settings Page *************************************************************/
423
424 /**
425 * The main settings page
426 *
427 * @since bbPress (r2643)
428 *
429 * @uses screen_icon() To display the screen icon
430 * @uses settings_fields() To output the hidden fields for the form
431 * @uses do_settings_sections() To output the settings sections
432 */
433 function bbp_admin_settings() {
434 ?>
435
436 <div class="wrap">
437
438 <?php screen_icon(); ?>
439
440 <h2><?php _e( 'bbPress Settings', 'bbpress' ) ?></h2>
441
442 <form action="options.php" method="post">
443
444 <?php settings_fields( 'bbpress' ); ?>
445
446 <?php do_settings_sections( 'bbpress' ); ?>
447
448 <p class="submit">
449 <input type="submit" name="submit" class="button-primary" value="<?php _e( 'Save Changes', 'bbpress' ); ?>" />
450 </p>
451 </form>
452 </div>
453
454 <?php
455 }
456
457 /**
458 * Contextual help for bbPress settings page
459 *
460 * @since bbPress (r3119)
461 */
462 function bbp_admin_settings_help() {
463
464 $bbp_contextual_help[] = __('This screen provides access to basic bbPress settings.', 'bbpress' );
465 $bbp_contextual_help[] = __('In the Main Settings you have a number of options:', 'bbpress' );
466 $bbp_contextual_help[] =
467 '<ul>' .
468 '<li>' . __( 'You can choose to lock a post after a certain number of minutes. "Locking post editing" will prevent the author from editing some amount of time after saving a post.', 'bbpress' ) . '</li>' .
469 '<li>' . __( '"Throttle time" is the amount of time required between posts from a single author. The higher the throttle time, the longer a user will need to wait between posting to the forum.', 'bbpress' ) . '</li>' .
470 '<li>' . __( 'You may choose to allow favorites, which are a way for users to save and later return to topics they favor. This is enabled by default.', 'bbpress' ) . '</li>' .
471 '<li>' . __( 'You may choose to allow subscriptions, which allows users to subscribe for notifications to topics that interest them. This is enabled by default.', 'bbpress' ) . '</li>' .
472 '<li>' . __( 'You may choose to allow "Anonymous Posting", which will allow guest users who do not have accounts on your site to both create topics as well as replies.', 'bbpress' ) . '</li>' .
473 '</ul>';
474
475 $bbp_contextual_help[] = __( 'Per Page settings allow you to control the number of topics and replies will appear on each of those pages. This is comparable to the WordPress "Reading Settings" page, where you can set the number of posts that should show on blog pages and in feeds.', 'bbpress' );
476 $bbp_contextual_help[] = __( 'The Forums section allows you to control the permalink structure for your forums. Each "base" is what will be displayed after your main URL and right before your permalink slug.', 'bbpress' );
477 $bbp_contextual_help[] = __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.', 'bbpress' );
478 $bbp_contextual_help[] = __( '<strong>For more information:</strong>', 'bbpress' );
479 $bbp_contextual_help[] =
480 '<ul>' .
481 '<li>' . __( '<a href="http://bbpress.org/documentation/">bbPress Documentation</a>', 'bbpress' ) . '</li>' .
482 '<li>' . __( '<a href="http://bbpress.org/forums/">bbPress Support Forums</a>', 'bbpress' ) . '</li>' .
483 '</ul>' ;
484
485 // Empty the default $contextual_help var
486 $contextual_help = '';
487
488 // Wrap each help item in paragraph tags
489 foreach( $bbp_contextual_help as $paragraph )
490 $contextual_help .= '<p>' . $paragraph . '</p>';
491
492 // Add help
493 add_contextual_help( 'settings_page_bbpress', $contextual_help );
494 }
495
496 /**
497 * Output settings API option
498 *
499 * @since bbPress (r3203)
500 *
501 * @uses bbp_get_bbp_form_option()
502 *
503 * @param string $option
504 * @param string $default
505 * @param bool $slug
506 */
507 function bbp_form_option( $option, $default = '' , $slug = false ) {
508 echo bbp_get_form_option( $option, $default, $slug );
509 }
510 /**
511 * Return settings API option
512 *
513 * @since bbPress (r3203)
514 *
515 * @uses get_option()
516 * @uses esc_attr()
517 * @uses apply_filters()
518 *
519 * @param string $option
520 * @param string $default
521 * @param bool $slug
522 */
523 function bbp_get_form_option( $option, $default = '', $slug = false ) {
524
525 // Get the option and sanitize it
526 $value = get_option( $option, $default );
527
528 // Slug?
529 if ( true === $slug )
530 $value = esc_attr( apply_filters( 'editable_slug', $value ) );
531
532 // Not a slug
533 else
534 $value = esc_attr( $value );
535
536 // Fallback to default
537 if ( empty( $value ) )
538 $value = $default;
539
540 // Allow plugins to further filter the output
541 return apply_filters( 'bbp_get_form_option', $value, $option );
542 }
543
544 /**
545 * Used to check if a bbPress slug conflicts with an existing known slug.
546 *
547 * @since bbPress (r3306)
548 *
549 * @param string $slug
550 * @param string $default
551 *
552 * @uses bbp_get_form_option() To get a sanitized slug string
553 */
554 function bbp_form_slug_conflict_check( $slug, $default ) {
555
556 // Only set the slugs once ver page load
557 static $the_core_slugs = array();
558
559 // Get the form value
560 $this_slug = bbp_get_form_option( $slug, $default, true );
561
562 if ( empty( $the_core_slugs ) ) {
563
564 // Slugs to check
565 $core_slugs = apply_filters( 'bbp_slug_conflict_check', array(
566
567 /** WordPress Core ****************************************************/
568
569 // Core Post Types
570 'post_base' => array( 'name' => __( 'Posts' ), 'default' => 'post', 'context' => 'WordPress' ),
571 'page_base' => array( 'name' => __( 'Pages' ), 'default' => 'page', 'context' => 'WordPress' ),
572 'revision_base' => array( 'name' => __( 'Revisions' ), 'default' => 'revision', 'context' => 'WordPress' ),
573 'attachment_base' => array( 'name' => __( 'Attachments' ), 'default' => 'attachment', 'context' => 'WordPress' ),
574 'nav_menu_base' => array( 'name' => __( 'Menus' ), 'default' => 'nav_menu_item', 'context' => 'WordPress' ),
575
576 // Post Tags
577 'tag_base' => array( 'name' => __( 'Tag base' ), 'default' => 'tag', 'context' => 'WordPress' ),
578
579 // Post Categories
580 'category_base' => array( 'name' => __( 'Category base' ), 'default' => 'category', 'context' => 'WordPress' ),
581
582 /** bbPress Core ******************************************************/
583
584 // Forum archive slug
585 '_bbp_root_slug' => array( 'name' => __( 'Forums base', 'bbpress' ), 'default' => 'forums', 'context' => 'bbPress' ),
586
587 // Topic archive slug
588 '_bbp_topic_archive_slug' => array( 'name' => __( 'Topics base', 'bbpress' ), 'default' => 'topics', 'context' => 'bbPress' ),
589
590 // Forum slug
591 '_bbp_forum_slug' => array( 'name' => __( 'Forum slug', 'bbpress' ), 'default' => 'forum', 'context' => 'bbPress' ),
592
593 // Topic slug
594 '_bbp_topic_slug' => array( 'name' => __( 'Topic slug', 'bbpress' ), 'default' => 'topic', 'context' => 'bbPress' ),
595
596 // Reply slug
597 '_bbp_reply_slug' => array( 'name' => __( 'Reply slug', 'bbpress' ), 'default' => 'reply', 'context' => 'bbPress' ),
598
599 // User profile slug
600 '_bbp_user_slug' => array( 'name' => __( 'User base', 'bbpress' ), 'default' => 'users', 'context' => 'bbPress' ),
601
602 // View slug
603 '_bbp_view_slug' => array( 'name' => __( 'View base', 'bbpress' ), 'default' => 'view', 'context' => 'bbPress' ),
604
605 // Topic tag slug
606 '_bbp_topic_tag_slug' => array( 'name' => __( 'Topic tag slug', 'bbpress' ), 'default' => 'topic-tag', 'context' => 'bbPress' ),
607 ) );
608
609 /** BuddyPress Core *******************************************************/
610
611 if ( defined( 'BP_VERSION' ) ) {
612 global $bp;
613
614 // Loop through root slugs and check for conflict
615 if ( !empty( $bp->pages ) ) {
616 foreach ( $bp->pages as $page => $page_data ) {
617 $page_base = $page . '_base';
618 $page_title = sprintf( __( '%s page', 'bbpress' ), $page_data->title );
619 $core_slugs[$page_base] = array( 'name' => $page_title, 'default' => $page_data->slug, 'context' => 'BuddyPress' );
620 }
621 }
622 }
623
624 // Set the static
625 $the_core_slugs = apply_filters( 'bbp_slug_conflict', $core_slugs );
626 }
627
628 // Loop through slugs to check
629 foreach( $the_core_slugs as $key => $value ) {
630
631 // Get the slug
632 $slug_check = bbp_get_form_option( $key, $value['default'], true );
633
634 // Compare
635 if ( ( $slug != $key ) && ( $slug_check == $this_slug ) ) : ?>
636
637 <span class="attention"><?php printf( __( 'Possible %1$s conflict: <strong>%2$s</strong>', 'bbpress' ), $value['context'], $value['name'] ); ?></span>
638
639 <?php endif;
640 }
641 }
642
643 ?>
644