PluginProbe
bbPress / 2.0-beta-3
bbPress v2.0-beta-3
2.6.17 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 All 72 releases
bbpress / bbp-admin / bbp-settings.php

bbp-settings.php in bbPress 2.0-beta-3, at bbp-admin/bbp-settings.php

591 lines 17.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 anonymous posting setting field
94 *
95 * @since bbPress (r2737)
96 *
97 * @uses checked() To display the checked attribute
98 */
99 function bbp_admin_setting_callback_anonymous() {
100 ?>
101
102 <input id="_bbp_allow_anonymous" name="_bbp_allow_anonymous" type="checkbox" id="_bbp_allow_anonymous" value="1" <?php checked( bbp_allow_anonymous( false ) ); ?> />
103 <label for="_bbp_allow_anonymous"><?php _e( 'Allow guest users without accounts to create topics and replies', 'bbpress' ); ?></label>
104
105 <?php
106 }
107
108 /** Start Per Page Section ****************************************************/
109
110 /**
111 * Per page settings section description for the settings page
112 *
113 * @since bbPress (r2786)
114 */
115 function bbp_admin_setting_callback_per_page_section() {
116 ?>
117
118 <p><?php _e( 'Per page settings for the bbPress plugin', 'bbpress' ); ?></p>
119
120 <?php
121 }
122
123 /**
124 * Topics per page setting field
125 *
126 * @since bbPress (r2786)
127 *
128 * @uses bbp_form_option() To output the option value
129 */
130 function bbp_admin_setting_callback_topics_per_page() {
131 ?>
132
133 <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" />
134 <label for="_bbp_topics_per_page"><?php _e( 'per page', 'bbpress' ); ?></label>
135
136 <?php
137 }
138
139 /**
140 * Replies per page setting field
141 *
142 * @since bbPress (r2786)
143 *
144 * @uses bbp_form_option() To output the option value
145 */
146 function bbp_admin_setting_callback_replies_per_page() {
147 ?>
148
149 <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" />
150 <label for="_bbp_replies_per_page"><?php _e( 'per page', 'bbpress' ); ?></label>
151
152 <?php
153 }
154
155 /** Start Per RSS Page Section ************************************************/
156
157 /**
158 * Per page settings section description for the settings page
159 *
160 * @since bbPress (r2786)
161 */
162 function bbp_admin_setting_callback_per_rss_page_section() {
163 ?>
164
165 <p><?php _e( 'Per RSS page settings for the bbPress plugin', 'bbpress' ); ?></p>
166
167 <?php
168 }
169
170 /**
171 * Topics per RSS page setting field
172 *
173 * @since bbPress (r2786)
174 *
175 * @uses bbp_form_option() To output the option value
176 */
177 function bbp_admin_setting_callback_topics_per_rss_page() {
178 ?>
179
180 <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" />
181 <label for="_bbp_topics_per_rss_page"><?php _e( 'per page', 'bbpress' ); ?></label>
182
183 <?php
184 }
185
186 /**
187 * Replies per RSS page setting field
188 *
189 * @since bbPress (r2786)
190 *
191 * @uses bbp_form_option() To output the option value
192 */
193 function bbp_admin_setting_callback_replies_per_rss_page() {
194 ?>
195
196 <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" />
197 <label for="_bbp_replies_per_rss_page"><?php _e( 'per page', 'bbpress' ); ?></label>
198
199 <?php
200 }
201
202 /** Start Slug Section ********************************************************/
203
204 /**
205 * Slugs settings section description for the settings page
206 *
207 * @since bbPress (r2786)
208 */
209 function bbp_admin_setting_callback_root_slug_section() {
210
211 // Flush rewrite rules when this section is saved
212 if ( isset( $_GET['settings-updated'] ) && isset( $_GET['page'] ) )
213 flush_rewrite_rules(); ?>
214
215 <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>
216
217 <?php
218 }
219
220 /**
221 * Root slug setting field
222 *
223 * @since bbPress (r2786)
224 *
225 * @uses bbp_form_option() To output the option value
226 */
227 function bbp_admin_setting_callback_root_slug() {
228 ?>
229
230 <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 ); ?>" />
231
232 <?php
233 // Slug Check
234 bbp_form_slug_conflict_check( '_bbp_root_slug', 'forums' );
235 }
236
237 /**
238 * Topic archive slug setting field
239 *
240 * @since bbPress (r2786)
241 *
242 * @uses bbp_form_option() To output the option value
243 */
244 function bbp_admin_setting_callback_topic_archive_slug() {
245 ?>
246
247 <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 ); ?>" />
248
249 <?php
250 // Slug Check
251 bbp_form_slug_conflict_check( '_bbp_topic_archive_slug', 'topics' );
252 }
253
254 /** Single Slugs **************************************************************/
255
256 /**
257 * Slugs settings section description for the settings page
258 *
259 * @since bbPress (r2786)
260 */
261 function bbp_admin_setting_callback_single_slug_section() {
262
263 // Flush rewrite rules when this section is saved
264 if ( isset( $_GET['settings-updated'] ) && isset( $_GET['page'] ) )
265 flush_rewrite_rules(); ?>
266
267 <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>
268
269 <?php
270 }
271
272 /**
273 * Include root slug setting field
274 *
275 * @since bbPress (r2786)
276 *
277 * @uses checked() To display the checked attribute
278 */
279 function bbp_admin_setting_callback_include_root() {
280 ?>
281
282 <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 ) ); ?> />
283 <label for="_bbp_include_root"><?php _e( 'Incude the Forum Base slug in your single forum item links', 'bbpress' ); ?></label>
284
285 <?php
286 }
287
288 /**
289 * Forum slug setting field
290 *
291 * @since bbPress (r2786)
292 *
293 * @uses bbp_form_option() To output the option value
294 */
295 function bbp_admin_setting_callback_forum_slug() {
296 ?>
297
298 <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 ); ?>" />
299
300 <?php
301 // Slug Check
302 bbp_form_slug_conflict_check( '_bbp_forum_slug', 'forum' );
303 }
304
305 /**
306 * Topic slug setting field
307 *
308 * @since bbPress (r2786)
309 *
310 * @uses bbp_form_option() To output the option value
311 */
312 function bbp_admin_setting_callback_topic_slug() {
313 ?>
314
315 <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 ); ?>" />
316
317 <?php
318 // Slug Check
319 bbp_form_slug_conflict_check( '_bbp_topic_slug', 'topic' );
320 }
321
322 /**
323 * Reply slug setting field
324 *
325 * @since bbPress (r2786)
326 *
327 * @uses bbp_form_option() To output the option value
328 */
329 function bbp_admin_setting_callback_reply_slug() {
330 ?>
331
332 <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 ); ?>" />
333
334 <?php
335 // Slug Check
336 bbp_form_slug_conflict_check( '_bbp_reply_slug', 'reply' );
337 }
338
339 /**
340 * Topic tag slug setting field
341 *
342 * @since bbPress (r2786)
343 *
344 * @uses bbp_form_option() To output the option value
345 */
346 function bbp_admin_setting_callback_topic_tag_slug() {
347 ?>
348
349 <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 ); ?>" />
350
351 <?php
352
353 // Slug Check
354 bbp_form_slug_conflict_check( '_bbp_topic_tag_slug', 'topic-tag' );
355 }
356
357 /** Other Slugs ***************************************************************/
358
359 /**
360 * User slug setting field
361 *
362 * @since bbPress (r2786)
363 *
364 * @uses bbp_form_option() To output the option value
365 */
366 function bbp_admin_setting_callback_user_slug() {
367 ?>
368
369 <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 ); ?>" />
370
371 <?php
372 // Slug Check
373 bbp_form_slug_conflict_check( '_bbp_user_slug', 'users' );
374 }
375
376 /**
377 * View slug setting field
378 *
379 * @since bbPress (r2789)
380 *
381 * @uses bbp_form_option() To output the option value
382 */
383 function bbp_admin_setting_callback_view_slug() {
384 ?>
385
386 <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 ); ?>" />
387
388 <?php
389 // Slug Check
390 bbp_form_slug_conflict_check( '_bbp_view_slug', 'view' );
391 }
392
393 /** Settings Page *************************************************************/
394
395 /**
396 * The main settings page
397 *
398 * @since bbPress (r2643)
399 *
400 * @uses screen_icon() To display the screen icon
401 * @uses settings_fields() To output the hidden fields for the form
402 * @uses do_settings_sections() To output the settings sections
403 */
404 function bbp_admin_settings() {
405 ?>
406
407 <div class="wrap">
408
409 <?php screen_icon(); ?>
410
411 <h2><?php _e( 'bbPress Settings', 'bbpress' ) ?></h2>
412
413 <form action="options.php" method="post">
414
415 <?php settings_fields( 'bbpress' ); ?>
416
417 <?php do_settings_sections( 'bbpress' ); ?>
418
419 <p class="submit">
420 <input type="submit" name="submit" class="button-primary" value="<?php _e( 'Save Changes', 'bbpress' ); ?>" />
421 </p>
422 </form>
423 </div>
424
425 <?php
426 }
427
428 /**
429 * Contextual help for bbPress settings page
430 *
431 * @since bbPress (r3119)
432 */
433 function bbp_admin_settings_help() {
434
435 $bbp_contextual_help[] = __('This screen provides access to basic bbPress settings.', 'bbpress' );
436 $bbp_contextual_help[] = __('In the Main Settings you have a number of options:', 'bbpress' );
437 $bbp_contextual_help[] =
438 '<ul>' .
439 '<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>' .
440 '<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>' .
441 '<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>' .
442 '<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>' .
443 '<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>' .
444 '</ul>';
445
446 $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' );
447 $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' );
448 $bbp_contextual_help[] = __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.', 'bbpress' );
449 $bbp_contextual_help[] = __( '<strong>For more information:</strong>', 'bbpress' );
450 $bbp_contextual_help[] =
451 '<ul>' .
452 '<li>' . __( '<a href="http://bbpress.org/documentation/">bbPress Documentation</a>', 'bbpress' ) . '</li>' .
453 '<li>' . __( '<a href="http://bbpress.org/forums/">bbPress Support Forums</a>', 'bbpress' ) . '</li>' .
454 '</ul>' ;
455
456 // Empty the default $contextual_help var
457 $contextual_help = '';
458
459 // Wrap each help item in paragraph tags
460 foreach( $bbp_contextual_help as $paragraph )
461 $contextual_help .= '<p>' . $paragraph . '</p>';
462
463 // Add help
464 add_contextual_help( 'settings_page_bbpress', $contextual_help );
465 }
466
467 /**
468 * Output settings API option
469 *
470 * @since bbPress (r3203)
471 *
472 * @uses bbp_get_bbp_form_option()
473 *
474 * @param string $option
475 * @param string $default
476 * @param bool $slug
477 */
478 function bbp_form_option( $option, $default = '' , $slug = false ) {
479 echo bbp_get_form_option( $option, $default, $slug );
480 }
481 /**
482 * Return settings API option
483 *
484 * @since bbPress (r3203)
485 *
486 * @uses get_option()
487 * @uses esc_attr()
488 * @uses apply_filters()
489 *
490 * @param string $option
491 * @param string $default
492 * @param bool $slug
493 */
494 function bbp_get_form_option( $option, $default = '', $slug = false ) {
495
496 // Get the option and sanitize it
497 $value = get_option( $option, $default );
498
499 // Slug?
500 if ( true === $slug )
501 $value = esc_attr( apply_filters( 'editable_slug', $value ) );
502
503 // Not a slug
504 else
505 $value = esc_attr( $value );
506
507 // Fallback to default
508 if ( empty( $value ) )
509 $value = $default;
510
511 // Allow plugins to further filter the output
512 return apply_filters( 'bbp_get_form_option', $value, $option );
513 }
514
515 /**
516 * Used to check if a bbPress slug conflicts with an existing known slug.
517 *
518 * @since bbPress (r3306)
519 *
520 * @param string $slug
521 * @param string $default
522 *
523 * @uses bbp_get_form_option() To get a sanitized slug string
524 */
525 function bbp_form_slug_conflict_check( $slug, $default ) {
526
527 // Get the form value
528 $this_slug = bbp_get_form_option( $slug, $default, true );
529
530 // Slugs to check
531 $core_slugs = apply_filters( 'bbp_slug_conflict_check', array(
532
533 /** WordPress Core ****************************************************/
534
535 // Core Post Types
536 'post_base' => array( 'name' => __( 'Posts' ), 'default' => 'post' ),
537 'page_base' => array( 'name' => __( 'Pages' ), 'default' => 'page' ),
538 'revision_base' => array( 'name' => __( 'Revisions' ), 'default' => 'revision' ),
539 'attachment_base' => array( 'name' => __( 'Attachments' ), 'default' => 'attachment' ),
540 'nav_menu_base' => array( 'name' => __( 'Menus' ), 'default' => 'nav_menu_item' ),
541
542 // Post Tags
543 'tag_base' => array( 'name' => __( 'Tag base' ), 'default' => 'tag' ),
544
545 // Post Categories
546 'category_base' => array( 'name' => __( 'Category base' ), 'default' => 'category' ),
547
548 /** bbPress Core ******************************************************/
549
550 // Forum archive slug
551 '_bbp_root_slug' => array( 'name' => __( 'Forums base', 'bbpress' ), 'default' => 'forums' ),
552
553 // Topic archive slug
554 '_bbp_topic_archive_slug' => array( 'name' => __( 'Topics base', 'bbpress' ), 'default' => 'topics' ),
555
556 // Forum slug
557 '_bbp_forum_slug' => array( 'name' => __( 'Forum slug', 'bbpress' ), 'default' => 'forum' ),
558
559 // Topic slug
560 '_bbp_topic_slug' => array( 'name' => __( 'Topic slug', 'bbpress' ), 'default' => 'topic' ),
561
562 // Reply slug
563 '_bbp_reply_slug' => array( 'name' => __( 'Reply slug', 'bbpress' ), 'default' => 'reply' ),
564
565 // User profile slug
566 '_bbp_user_slug' => array( 'name' => __( 'User base', 'bbpress' ), 'default' => 'users' ),
567
568 // View slug
569 '_bbp_view_slug' => array( 'name' => __( 'View base', 'bbpress' ), 'default' => 'view' ),
570
571 // Topic tag slug
572 '_bbp_topic_tag_slug' => array( 'name' => __( 'Topic tag slug', 'bbpress' ), 'default' => 'topic-tag' ),
573 ) );
574
575 // Loop through slugs to check
576 foreach( $core_slugs as $key => $value ) {
577
578 // Get the slug
579 $slug_check = bbp_get_form_option( $key, $value['default'], true );
580
581 // Compare
582 if ( ( $slug != $key ) && ( $slug_check == $this_slug ) ) : ?>
583
584 <span class="attention"><?php printf( __( 'Possible "%s" conflict', 'bbpress' ), $value['name'] ); ?></span>
585
586 <?php endif;
587 }
588 }
589
590 ?>
591