PluginProbe
bbPress / 2.0-rc-2
bbPress v2.0-rc-2
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-admin.php

bbp-admin.php in bbPress 2.0-rc-2, at bbp-admin/bbp-admin.php

656 lines 21.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Main bbPress Admin Class
5 *
6 * @package bbPress
7 * @subpackage Administration
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 if ( !class_exists( 'BBP_Admin' ) ) :
14 /**
15 * Loads bbPress plugin admin area
16 *
17 * @package bbPress
18 * @subpackage Administration
19 * @since bbPress (r2464)
20 */
21 class BBP_Admin {
22
23 /** URLs ******************************************************************/
24
25 /**
26 * @var string URL to the bbPress images directory
27 */
28 public $images_url = '';
29
30 /**
31 * @var string URL to the bbPress admin styles directory
32 */
33 public $styles_url = '';
34
35 /** URLs ******************************************************************/
36
37 /**
38 * @var bool Enable recounts in Tools area
39 */
40 public $enable_recounts = false;
41
42 /** Functions *************************************************************/
43
44 /**
45 * The main bbPress admin loader
46 *
47 * @since bbPress (r2515)
48 *
49 * @uses BBP_Admin::setup_globals() Setup the globals needed
50 * @uses BBP_Admin::includes() Include the required files
51 * @uses BBP_Admin::setup_actions() Setup the hooks and actions
52 */
53 public function __construct() {
54 $this->setup_globals();
55 $this->includes();
56 $this->setup_actions();
57 }
58
59 /**
60 * Setup the admin hooks, actions and filters
61 *
62 * @since bbPress (r2646)
63 * @access private
64 *
65 * @uses add_action() To add various actions
66 * @uses add_filter() To add various filters
67 */
68 private function setup_actions() {
69
70 /** General Actions ***************************************************/
71
72 // Attach the bbPress admin init action to the WordPress admin init action.
73 add_action( 'admin_init', array( $this, 'init' ) );
74
75 // Add some general styling to the admin area
76 add_action( 'admin_head', array( $this, 'admin_head' ) );
77
78 // Add menu item to settings menu
79 add_action( 'admin_menu', array( $this, 'admin_menus' ) );
80
81 // Add notice if not using a bbPress theme
82 add_action( 'admin_notices', array( $this, 'activation_notice' ) );
83
84 // Register bbPress admin style
85 // @todo Refresh for 3.2 UI
86 //add_action( 'bbp_admin_init', array( $this, 'register_admin_style' ) );
87
88 // Add the importers
89 add_action( 'bbp_admin_init', array( $this, 'register_importers' ) );
90
91 // Add the settings
92 add_action( 'bbp_admin_init', array( $this, 'register_admin_settings' ) );
93
94 // Forums 'Right now' Dashboard widget
95 add_action( 'wp_dashboard_setup', array( $this, 'dashboard_widget_right_now' ) );
96
97 /** Filters ***********************************************************/
98
99 // Add link to settings page
100 add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ), 10, 2 );
101
102 // Add sample permalink filter
103 add_filter( 'post_type_link', 'bbp_filter_sample_permalink', 10, 4 );
104 }
105
106 /**
107 * Include required files
108 *
109 * @since bbPress (r2646)
110 * @access private
111 */
112 private function includes() {
113 global $bbp;
114
115 // Files to include
116 $files = array( 'tools', 'settings', 'functions', 'metaboxes', 'forums', 'topics', 'replies' );
117
118 // Buzz buzz
119 //if ( get_option( '_bbp_first_run' ) ) $files[] = 'first-run';
120
121 // Include the files
122 foreach ( $files as $file )
123 require( $bbp->plugin_dir . 'bbp-admin/bbp-' . $file . '.php' );
124 }
125
126 /**
127 * Admin globals
128 *
129 * @since bbPress (r2646)
130 * @access private
131 */
132 private function setup_globals() {
133 global $bbp;
134
135 // Admin url
136 $this->admin_url = trailingslashit( $bbp->plugin_url . 'bbp-admin' );
137
138 // Admin images URL
139 $this->images_url = trailingslashit( $this->admin_url . 'images' );
140
141 // Admin images URL
142 $this->styles_url = trailingslashit( $this->admin_url . 'styles' );
143 }
144
145 /**
146 * Add the navigational menu elements
147 *
148 * @since bbPress (r2646)
149 *
150 * @uses add_management_page() To add the Recount page in Tools section
151 * @uses add_options_page() To add the Forums settings page in Settings
152 * section
153 */
154 public function admin_menus() {
155
156 // Recounts
157 if ( is_super_admin() || !empty( $this->enable_recounts ) )
158 add_management_page( __( 'Recount', 'bbpress' ), __( 'Recount', 'bbpress' ), 'manage_options', 'bbp-recount', 'bbp_admin_tools' );
159
160 // Forums settings
161 add_options_page ( __( 'Forums', 'bbpress' ), __( 'Forums', 'bbpress' ), 'manage_options', 'bbpress', 'bbp_admin_settings' );
162 }
163
164 /**
165 * Register the settings
166 *
167 * @since bbPress (r2737)
168 *
169 * @uses add_settings_section() To add our own settings section
170 * @uses add_settings_field() To add various settings fields
171 * @uses register_setting() To register various settings
172 * @uses do_action() Calls 'bbp_register_admin_settings'
173 */
174 public function register_admin_settings() {
175
176 /** Main Section ******************************************************/
177
178 // Add the main section
179 add_settings_section( 'bbp_main', __( 'Main Settings', 'bbpress' ), 'bbp_admin_setting_callback_main_section', 'bbpress' );
180
181 // Edit lock setting
182 add_settings_field( '_bbp_edit_lock', __( 'Lock post editing after', 'bbpress' ), 'bbp_admin_setting_callback_editlock', 'bbpress', 'bbp_main' );
183 register_setting ( 'bbpress', '_bbp_edit_lock', 'intval' );
184
185 // Throttle setting
186 add_settings_field( '_bbp_throttle_time', __( 'Throttle time', 'bbpress' ), 'bbp_admin_setting_callback_throttle', 'bbpress', 'bbp_main' );
187 register_setting ( 'bbpress', '_bbp_throttle_time', 'intval' );
188
189 // Allow favorites setting
190 add_settings_field( '_bbp_enable_favorites', __( 'Allow Favorites', 'bbpress' ), 'bbp_admin_setting_callback_favorites', 'bbpress', 'bbp_main' );
191 register_setting ( 'bbpress', '_bbp_enable_favorites', 'intval' );
192
193 // Allow subscriptions setting
194 add_settings_field( '_bbp_enable_subscriptions', __( 'Allow Subscriptions', 'bbpress' ), 'bbp_admin_setting_callback_subscriptions', 'bbpress', 'bbp_main' );
195 register_setting ( 'bbpress', '_bbp_enable_subscriptions', 'intval' );
196
197 // Allow anonymous posting setting
198 add_settings_field( '_bbp_allow_anonymous', __( 'Allow Anonymous Posting', 'bbpress' ), 'bbp_admin_setting_callback_anonymous', 'bbpress', 'bbp_main' );
199 register_setting ( 'bbpress', '_bbp_allow_anonymous', 'intval' );
200
201 // Allow global access setting
202 if ( is_multisite() ) {
203 add_settings_field( '_bbp_allow_global_access', __( 'Allow Global Access', 'bbpress' ), 'bbp_admin_setting_callback_global_access', 'bbpress', 'bbp_main' );
204 register_setting ( 'bbpress', '_bbp_allow_global_access', 'intval' );
205 }
206
207 /** Per Page Section **************************************************/
208
209 // Add the per page section
210 add_settings_section( 'bbp_per_page', __( 'Per Page', 'bbpress' ), 'bbp_admin_setting_callback_per_page_section', 'bbpress' );
211
212 // Topics per page setting
213 add_settings_field( '_bbp_topics_per_page', __( 'Topics', 'bbpress' ), 'bbp_admin_setting_callback_topics_per_page', 'bbpress', 'bbp_per_page' );
214 register_setting ( 'bbpress', '_bbp_topics_per_page', 'intval' );
215
216 // Replies per page setting
217 add_settings_field( '_bbp_replies_per_page', __( 'Replies', 'bbpress' ), 'bbp_admin_setting_callback_replies_per_page', 'bbpress', 'bbp_per_page' );
218 register_setting ( 'bbpress', '_bbp_replies_per_page', 'intval' );
219
220 /** Per RSS Page Section **********************************************/
221
222 // Add the per page section
223 add_settings_section( 'bbp_per_rss_page', __( 'Per RSS Page', 'bbpress' ), 'bbp_admin_setting_callback_per_rss_page_section', 'bbpress' );
224
225 // Topics per page setting
226 add_settings_field( '_bbp_topics_per_page', __( 'Topics', 'bbpress' ), 'bbp_admin_setting_callback_topics_per_rss_page', 'bbpress', 'bbp_per_rss_page' );
227 register_setting ( 'bbpress', '_bbp_topics_per_rss_page', 'intval' );
228
229 // Replies per page setting
230 add_settings_field( '_bbp_replies_per_page', __( 'Replies', 'bbpress' ), 'bbp_admin_setting_callback_replies_per_rss_page', 'bbpress', 'bbp_per_rss_page' );
231 register_setting ( 'bbpress', '_bbp_replies_per_rss_page', 'intval' );
232
233 /** Front Slugs *******************************************************/
234
235 // Add the per page section
236 add_settings_section( 'bbp_root_slug', __( 'Archive Slugs', 'bbpress' ), 'bbp_admin_setting_callback_root_slug_section', 'bbpress' );
237
238 // Root slug setting
239 add_settings_field ( '_bbp_root_slug', __( 'Forums base', 'bbpress' ), 'bbp_admin_setting_callback_root_slug', 'bbpress', 'bbp_root_slug' );
240 register_setting ( 'bbpress', '_bbp_root_slug', 'esc_sql' );
241
242 // Topic archive setting
243 add_settings_field ( '_bbp_topic_archive_slug', __( 'Topics base', 'bbpress' ), 'bbp_admin_setting_callback_topic_archive_slug', 'bbpress', 'bbp_root_slug' );
244 register_setting ( 'bbpress', '_bbp_topic_archive_slug', 'esc_sql' );
245
246 /** Single slugs ******************************************************/
247
248 // Add the per page section
249 add_settings_section( 'bbp_single_slugs', __( 'Single Slugs', 'bbpress' ), 'bbp_admin_setting_callback_single_slug_section', 'bbpress' );
250
251 // Include root setting
252 add_settings_field( '_bbp_include_root', __( 'Forum Prefix', 'bbpress' ), 'bbp_admin_setting_callback_include_root', 'bbpress', 'bbp_single_slugs' );
253 register_setting ( 'bbpress', '_bbp_include_root', 'intval' );
254
255 // Forum slug setting
256 add_settings_field( '_bbp_forum_slug', __( 'Forum slug', 'bbpress' ), 'bbp_admin_setting_callback_forum_slug', 'bbpress', 'bbp_single_slugs' );
257 register_setting ( 'bbpress', '_bbp_forum_slug', 'sanitize_title' );
258
259 // Topic slug setting
260 add_settings_field( '_bbp_topic_slug', __( 'Topic slug', 'bbpress' ), 'bbp_admin_setting_callback_topic_slug', 'bbpress', 'bbp_single_slugs' );
261 register_setting ( 'bbpress', '_bbp_topic_slug', 'sanitize_title' );
262
263 // Topic tag slug setting
264 add_settings_field( '_bbp_topic_tag_slug', __( 'Topic tag slug', 'bbpress' ), 'bbp_admin_setting_callback_topic_tag_slug', 'bbpress', 'bbp_single_slugs' );
265 register_setting ( 'bbpress', '_bbp_topic_tag_slug', 'sanitize_title' );
266
267 // Reply slug setting
268 add_settings_field( '_bbp_reply_slug', __( 'Reply slug', 'bbpress' ), 'bbp_admin_setting_callback_reply_slug', 'bbpress', 'bbp_single_slugs' );
269 register_setting ( 'bbpress', '_bbp_reply_slug', 'sanitize_title' );
270
271 /** Other slugs *******************************************************/
272
273 // User slug setting
274 add_settings_field( '_bbp_user_slug', __( 'User base', 'bbpress' ), 'bbp_admin_setting_callback_user_slug', 'bbpress', 'bbp_single_slugs' );
275 register_setting ( 'bbpress', '_bbp_user_slug', 'sanitize_title' );
276
277 // View slug setting
278 add_settings_field( '_bbp_view_slug', __( 'View base', 'bbpress' ), 'bbp_admin_setting_callback_view_slug', 'bbpress', 'bbp_single_slugs' );
279 register_setting ( 'bbpress', '_bbp_view_slug', 'sanitize_title' );
280
281 do_action( 'bbp_register_admin_settings' );
282 }
283
284 /**
285 * Register the importers
286 *
287 * @since bbPress (r2737)
288 *
289 * @uses do_action() Calls 'bbp_register_importers'
290 */
291 public function register_importers() {
292
293 // Leave if we're not in the import section
294 if ( !defined( 'WP_LOAD_IMPORTERS' ) )
295 return;
296
297 global $bbp;
298
299 // Load Importer API
300 require_once( ABSPATH . 'wp-admin/includes/import.php' );
301
302 // Load our importers
303 $importers = apply_filters( 'bbp_importers', array( 'bbpress' ) );
304
305 // Loop through included importers
306 foreach ( $importers as $importer ) {
307
308 // Compile the importer path
309 $import_file = $bbp->plugin_dir . 'bbp-admin/importers/' . $importer . '.php';
310
311 // If the file exists, include it
312 if ( file_exists( $import_file ) ) {
313 require( $import_file );
314 }
315 }
316
317 // Don't do anything we wouldn't do
318 do_action( 'bbp_register_importers' );
319 }
320
321 /**
322 * Admin area activation notice
323 *
324 * Shows a nag message in admin area about the theme not supporting bbPress
325 *
326 * @since bbPress (r2743)
327 *
328 * @global bbPress $bbp
329 *
330 * @uses current_user_can() To check notice should be displayed.
331 * @uses current_theme_supports() To check theme for bbPress support
332 */
333 public function activation_notice() {
334 global $bbp, $pagenow;
335
336 // Bail if not on admin theme page
337 if ( 'themes.php' != $pagenow )
338 return;
339
340 // Bail if user cannot change the theme
341 if ( !current_user_can( 'switch_themes' ) )
342 return;
343
344 // Set $bbp->theme_compat to true to bypass nag
345 if ( !empty( $bbp->theme_compat->theme ) && !current_theme_supports( 'bbpress' ) ) : ?>
346
347 <div id="message" class="updated fade">
348 <p style="line-height: 150%"><?php printf( __( "Your active theme does not include bbPress template files. Your forums are using the default styling included with bbPress.", 'bbpress' ), admin_url( 'themes.php' ), admin_url( 'theme-install.php?type=tag&s=bbpress&tab=search' ) ) ?></p>
349 </div>
350
351 <?php endif;
352 }
353
354 /**
355 * Add Settings link to plugins area
356 *
357 * @since bbPress (r2737)
358 *
359 * @param array $links Links array in which we would prepend our link
360 * @param string $file Current plugin basename
361 * @return array Processed links
362 */
363 public function add_settings_link( $links, $file ) {
364 global $bbp;
365
366 if ( plugin_basename( $bbp->file ) == $file ) {
367 $settings_link = '<a href="' . add_query_arg( array( 'page' => 'bbpress' ), admin_url( 'options-general.php' ) ) . '">' . __( 'Settings', 'bbpress' ) . '</a>';
368 array_unshift( $links, $settings_link );
369 }
370
371 return $links;
372 }
373
374 /**
375 * bbPress's dedicated admin init action
376 *
377 * @since bbPress (r2464)
378 *
379 * @uses do_action() Calls 'bbp_admin_init'
380 */
381 public function init() {
382 do_action( 'bbp_admin_init' );
383 }
384
385 /**
386 * Add the 'Right now in Forums' dashboard widget
387 *
388 * @since bbPress (r2770)
389 *
390 * @uses wp_add_dashboard_widget() To add the dashboard widget
391 */
392 public function dashboard_widget_right_now() {
393 wp_add_dashboard_widget( 'bbp-dashboard-right-now', __( 'Right Now in Forums', 'bbpress' ), 'bbp_dashboard_widget_right_now' );
394 }
395
396 /**
397 * Add some general styling to the admin area
398 *
399 * @since bbPress (r2464)
400 *
401 * @uses bbp_get_forum_post_type() To get the forum post type
402 * @uses bbp_get_topic_post_type() To get the topic post type
403 * @uses bbp_get_reply_post_type() To get the reply post type
404 * @uses sanitize_html_class() To sanitize the classes
405 * @uses do_action() Calls 'bbp_admin_head'
406 */
407 public function admin_head() {
408
409 // Icons for top level admin menus
410 $menu_icon_url = $this->images_url . 'menu.png';
411 $icon32_url = $this->images_url . 'icons32.png';
412
413 // Top level menu classes
414 $forum_class = sanitize_html_class( bbp_get_forum_post_type() );
415 $topic_class = sanitize_html_class( bbp_get_topic_post_type() );
416 $reply_class = sanitize_html_class( bbp_get_reply_post_type() ); ?>
417
418 <style type="text/css" media="screen">
419 /*<![CDATA[*/
420
421 #bbp-dashboard-right-now p.sub,
422 #bbp-dashboard-right-now .table,
423 #bbp-dashboard-right-now .versions {
424 margin: -12px;
425 }
426
427 #bbp-dashboard-right-now .inside {
428 font-size: 12px;
429 padding-top: 20px;
430 margin-bottom: 0;
431 }
432
433 #bbp-dashboard-right-now p.sub {
434 font-style: italic;
435 font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
436 padding: 5px 10px 15px;
437
438 <?php if ( is_rtl() ) : ?>
439
440 right: 15px;
441
442 <?php else : ?>
443
444 left: 15px;
445
446 <?php endif; ?>
447
448 color: #777;
449 font-size: 13px;
450 position: absolute;
451 top: -17px;
452 }
453
454 #bbp-dashboard-right-now .table {
455 margin: 0 -9px;
456 padding: 0 10px;
457 position: relative;
458 }
459
460 #bbp-dashboard-right-now .table_content {
461
462 <?php if ( is_rtl() ) : ?>
463
464 float: right;
465
466 <?php else : ?>
467
468 float: left;
469
470 <?php endif; ?>
471
472 border-top: #ececec 1px solid;
473 width: 45%;
474 }
475
476 #bbp-dashboard-right-now .table_discussion {
477
478 <?php if ( is_rtl() ) : ?>
479
480 float: left;
481
482 <?php else : ?>
483
484 float: right;
485
486 <?php endif; ?>
487
488 border-top: #ececec 1px solid;
489 width: 45%;
490 }
491
492 #bbp-dashboard-right-now table td {
493 padding: 3px 0;
494 white-space: nowrap;
495 }
496
497 #bbp-dashboard-right-now table tr.first td {
498 border-top: none;
499 }
500
501 #bbp-dashboard-right-now td.b {
502
503 <?php if ( is_rtl() ) : ?>
504
505 padding-left: 6px;
506
507 <?php else : ?>
508
509 padding-right: 6px;
510
511 <?php endif; ?>
512
513 text-align: right;
514 font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
515 font-size: 14px;
516 width: 1%;
517 }
518
519 #bbp-dashboard-right-now td.b a {
520 font-size: 18px;
521 }
522
523 #bbp-dashboard-right-now td.b a:hover {
524 color: #d54e21;
525 }
526
527 #bbp-dashboard-right-now .t {
528 font-size: 12px;
529
530 <?php if ( is_rtl() ) : ?>
531
532 padding-left: 12px;
533
534 <?php else : ?>
535
536 padding-right: 12px;
537
538 <?php endif; ?>
539
540 padding-top: 6px;
541 color: #777;
542 }
543
544 #bbp-dashboard-right-now .t a {
545 white-space: nowrap;
546 }
547
548 #bbp-dashboard-right-now .spam {
549 color: red;
550 }
551
552 #bbp-dashboard-right-now .waiting {
553 color: #e66f00;
554 }
555
556 #bbp-dashboard-right-now .approved {
557 color: green;
558 }
559
560 #bbp-dashboard-right-now .versions {
561 padding: 6px 10px 12px;
562 clear: both;
563 }
564
565 #bbp-dashboard-right-now .versions .b {
566 font-weight: bold;
567 }
568
569 #bbp-dashboard-right-now a.button {
570
571 <?php if ( is_rtl() ) : ?>
572
573 float: left;
574 clear: left;
575
576 <?php else : ?>
577
578 float: right;
579 clear: right;
580
581 <?php endif; ?>
582
583 position: relative;
584 top: -5px;
585 }
586
587 #menu-posts-<?php echo $forum_class; ?> .wp-menu-image {
588 background: url(<?php echo $menu_icon_url; ?>) no-repeat 0px -32px;
589 }
590 #menu-posts-<?php echo $forum_class; ?>:hover .wp-menu-image,
591 #menu-posts-<?php echo $forum_class; ?>.wp-has-current-submenu .wp-menu-image {
592 background: url(<?php echo $menu_icon_url; ?>) no-repeat 0px 0px;
593 }
594 #icon-edit.icon32-posts-<?php echo $forum_class; ?> {
595 background: url(<?php echo $icon32_url; ?>) no-repeat -4px 0px;
596 }
597
598 #menu-posts-<?php echo $topic_class; ?> .wp-menu-image {
599 background: url(<?php echo $menu_icon_url; ?>) no-repeat -70px -32px;
600 }
601 #menu-posts-<?php echo $topic_class; ?>:hover .wp-menu-image,
602 #menu-posts-<?php echo $topic_class; ?>.wp-has-current-submenu .wp-menu-image {
603 background: url(<?php echo $menu_icon_url; ?>) no-repeat -70px 0px;
604 }
605 #icon-edit.icon32-posts-<?php echo $topic_class; ?> {
606 background: url(<?php echo $icon32_url; ?>) no-repeat -4px -90px;
607 }
608
609 #menu-posts-<?php echo $reply_class; ?> .wp-menu-image {
610 background: url(<?php echo $menu_icon_url; ?>) no-repeat -35px -32px;
611 }
612 #menu-posts-<?php echo $reply_class; ?>:hover .wp-menu-image,
613 #menu-posts-<?php echo $reply_class; ?>.wp-has-current-submenu .wp-menu-image {
614 background: url(<?php echo $menu_icon_url; ?>) no-repeat -35px 0px;
615 }
616 #icon-edit.icon32-posts-<?php echo $reply_class; ?> {
617 background: url(<?php echo $icon32_url; ?>) no-repeat -4px -180px;
618 }
619
620 /*]]>*/
621 </style>
622
623 <?php
624
625 // Add extra actions to bbPress admin header area
626 do_action( 'bbp_admin_head' );
627 }
628
629 /**
630 * Registers the bbPress admin color scheme
631 *
632 * @since bbPress (r2521)
633 *
634 * @uses wp_admin_css_color() To register the color scheme
635 */
636 public function register_admin_style () {
637 wp_admin_css_color( 'bbpress', __( 'Green', 'bbpress' ), $this->styles_url . 'admin.css', array( '#222222', '#006600', '#deece1', '#6eb469' ) );
638 }
639 }
640 endif; // class_exists check
641
642 /**
643 * Setup bbPress Admin
644 *
645 * @since bbPress (r2596)
646 *
647 * @uses BBP_Admin
648 */
649 function bbp_admin() {
650 global $bbp;
651
652 $bbp->admin = new BBP_Admin();
653 }
654
655 ?>
656