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

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

660 lines 21.6 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 topic and reply revisions
190 add_settings_field( '_bbp_allow_revisions', __( 'Allow Revisions', 'bbpress' ), 'bbp_admin_setting_callback_revisions', 'bbpress', 'bbp_main' );
191 register_setting ( 'bbpress', '_bbp_allow_revisions', 'intval' );
192
193 // Allow favorites setting
194 add_settings_field( '_bbp_enable_favorites', __( 'Allow Favorites', 'bbpress' ), 'bbp_admin_setting_callback_favorites', 'bbpress', 'bbp_main' );
195 register_setting ( 'bbpress', '_bbp_enable_favorites', 'intval' );
196
197 // Allow subscriptions setting
198 add_settings_field( '_bbp_enable_subscriptions', __( 'Allow Subscriptions', 'bbpress' ), 'bbp_admin_setting_callback_subscriptions', 'bbpress', 'bbp_main' );
199 register_setting ( 'bbpress', '_bbp_enable_subscriptions', 'intval' );
200
201 // Allow anonymous posting setting
202 add_settings_field( '_bbp_allow_anonymous', __( 'Allow Anonymous Posting', 'bbpress' ), 'bbp_admin_setting_callback_anonymous', 'bbpress', 'bbp_main' );
203 register_setting ( 'bbpress', '_bbp_allow_anonymous', 'intval' );
204
205 // Allow global access setting
206 if ( is_multisite() ) {
207 add_settings_field( '_bbp_allow_global_access', __( 'Allow Global Access', 'bbpress' ), 'bbp_admin_setting_callback_global_access', 'bbpress', 'bbp_main' );
208 register_setting ( 'bbpress', '_bbp_allow_global_access', 'intval' );
209 }
210
211 /** Per Page Section **************************************************/
212
213 // Add the per page section
214 add_settings_section( 'bbp_per_page', __( 'Per Page', 'bbpress' ), 'bbp_admin_setting_callback_per_page_section', 'bbpress' );
215
216 // Topics per page setting
217 add_settings_field( '_bbp_topics_per_page', __( 'Topics', 'bbpress' ), 'bbp_admin_setting_callback_topics_per_page', 'bbpress', 'bbp_per_page' );
218 register_setting ( 'bbpress', '_bbp_topics_per_page', 'intval' );
219
220 // Replies per page setting
221 add_settings_field( '_bbp_replies_per_page', __( 'Replies', 'bbpress' ), 'bbp_admin_setting_callback_replies_per_page', 'bbpress', 'bbp_per_page' );
222 register_setting ( 'bbpress', '_bbp_replies_per_page', 'intval' );
223
224 /** Per RSS Page Section **********************************************/
225
226 // Add the per page section
227 add_settings_section( 'bbp_per_rss_page', __( 'Per RSS Page', 'bbpress' ), 'bbp_admin_setting_callback_per_rss_page_section', 'bbpress' );
228
229 // Topics per page setting
230 add_settings_field( '_bbp_topics_per_page', __( 'Topics', 'bbpress' ), 'bbp_admin_setting_callback_topics_per_rss_page', 'bbpress', 'bbp_per_rss_page' );
231 register_setting ( 'bbpress', '_bbp_topics_per_rss_page', 'intval' );
232
233 // Replies per page setting
234 add_settings_field( '_bbp_replies_per_page', __( 'Replies', 'bbpress' ), 'bbp_admin_setting_callback_replies_per_rss_page', 'bbpress', 'bbp_per_rss_page' );
235 register_setting ( 'bbpress', '_bbp_replies_per_rss_page', 'intval' );
236
237 /** Front Slugs *******************************************************/
238
239 // Add the per page section
240 add_settings_section( 'bbp_root_slug', __( 'Archive Slugs', 'bbpress' ), 'bbp_admin_setting_callback_root_slug_section', 'bbpress' );
241
242 // Root slug setting
243 add_settings_field ( '_bbp_root_slug', __( 'Forums base', 'bbpress' ), 'bbp_admin_setting_callback_root_slug', 'bbpress', 'bbp_root_slug' );
244 register_setting ( 'bbpress', '_bbp_root_slug', 'esc_sql' );
245
246 // Topic archive setting
247 add_settings_field ( '_bbp_topic_archive_slug', __( 'Topics base', 'bbpress' ), 'bbp_admin_setting_callback_topic_archive_slug', 'bbpress', 'bbp_root_slug' );
248 register_setting ( 'bbpress', '_bbp_topic_archive_slug', 'esc_sql' );
249
250 /** Single slugs ******************************************************/
251
252 // Add the per page section
253 add_settings_section( 'bbp_single_slugs', __( 'Single Slugs', 'bbpress' ), 'bbp_admin_setting_callback_single_slug_section', 'bbpress' );
254
255 // Include root setting
256 add_settings_field( '_bbp_include_root', __( 'Forum Prefix', 'bbpress' ), 'bbp_admin_setting_callback_include_root', 'bbpress', 'bbp_single_slugs' );
257 register_setting ( 'bbpress', '_bbp_include_root', 'intval' );
258
259 // Forum slug setting
260 add_settings_field( '_bbp_forum_slug', __( 'Forum slug', 'bbpress' ), 'bbp_admin_setting_callback_forum_slug', 'bbpress', 'bbp_single_slugs' );
261 register_setting ( 'bbpress', '_bbp_forum_slug', 'sanitize_title' );
262
263 // Topic slug setting
264 add_settings_field( '_bbp_topic_slug', __( 'Topic slug', 'bbpress' ), 'bbp_admin_setting_callback_topic_slug', 'bbpress', 'bbp_single_slugs' );
265 register_setting ( 'bbpress', '_bbp_topic_slug', 'sanitize_title' );
266
267 // Topic tag slug setting
268 add_settings_field( '_bbp_topic_tag_slug', __( 'Topic tag slug', 'bbpress' ), 'bbp_admin_setting_callback_topic_tag_slug', 'bbpress', 'bbp_single_slugs' );
269 register_setting ( 'bbpress', '_bbp_topic_tag_slug', 'sanitize_title' );
270
271 // Reply slug setting
272 add_settings_field( '_bbp_reply_slug', __( 'Reply slug', 'bbpress' ), 'bbp_admin_setting_callback_reply_slug', 'bbpress', 'bbp_single_slugs' );
273 register_setting ( 'bbpress', '_bbp_reply_slug', 'sanitize_title' );
274
275 /** Other slugs *******************************************************/
276
277 // User slug setting
278 add_settings_field( '_bbp_user_slug', __( 'User base', 'bbpress' ), 'bbp_admin_setting_callback_user_slug', 'bbpress', 'bbp_single_slugs' );
279 register_setting ( 'bbpress', '_bbp_user_slug', 'sanitize_title' );
280
281 // View slug setting
282 add_settings_field( '_bbp_view_slug', __( 'View base', 'bbpress' ), 'bbp_admin_setting_callback_view_slug', 'bbpress', 'bbp_single_slugs' );
283 register_setting ( 'bbpress', '_bbp_view_slug', 'sanitize_title' );
284
285 do_action( 'bbp_register_admin_settings' );
286 }
287
288 /**
289 * Register the importers
290 *
291 * @since bbPress (r2737)
292 *
293 * @uses do_action() Calls 'bbp_register_importers'
294 */
295 public function register_importers() {
296
297 // Leave if we're not in the import section
298 if ( !defined( 'WP_LOAD_IMPORTERS' ) )
299 return;
300
301 global $bbp;
302
303 // Load Importer API
304 require_once( ABSPATH . 'wp-admin/includes/import.php' );
305
306 // Load our importers
307 $importers = apply_filters( 'bbp_importers', array( 'bbpress' ) );
308
309 // Loop through included importers
310 foreach ( $importers as $importer ) {
311
312 // Compile the importer path
313 $import_file = $bbp->plugin_dir . 'bbp-admin/importers/' . $importer . '.php';
314
315 // If the file exists, include it
316 if ( file_exists( $import_file ) ) {
317 require( $import_file );
318 }
319 }
320
321 // Don't do anything we wouldn't do
322 do_action( 'bbp_register_importers' );
323 }
324
325 /**
326 * Admin area activation notice
327 *
328 * Shows a nag message in admin area about the theme not supporting bbPress
329 *
330 * @since bbPress (r2743)
331 *
332 * @global bbPress $bbp
333 *
334 * @uses current_user_can() To check notice should be displayed.
335 * @uses current_theme_supports() To check theme for bbPress support
336 */
337 public function activation_notice() {
338 global $bbp, $pagenow;
339
340 // Bail if not on admin theme page
341 if ( 'themes.php' != $pagenow )
342 return;
343
344 // Bail if user cannot change the theme
345 if ( !current_user_can( 'switch_themes' ) )
346 return;
347
348 // Set $bbp->theme_compat to true to bypass nag
349 if ( !empty( $bbp->theme_compat->theme ) && !current_theme_supports( 'bbpress' ) ) : ?>
350
351 <div id="message" class="updated fade">
352 <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>
353 </div>
354
355 <?php endif;
356 }
357
358 /**
359 * Add Settings link to plugins area
360 *
361 * @since bbPress (r2737)
362 *
363 * @param array $links Links array in which we would prepend our link
364 * @param string $file Current plugin basename
365 * @return array Processed links
366 */
367 public function add_settings_link( $links, $file ) {
368 global $bbp;
369
370 if ( plugin_basename( $bbp->file ) == $file ) {
371 $settings_link = '<a href="' . add_query_arg( array( 'page' => 'bbpress' ), admin_url( 'options-general.php' ) ) . '">' . __( 'Settings', 'bbpress' ) . '</a>';
372 array_unshift( $links, $settings_link );
373 }
374
375 return $links;
376 }
377
378 /**
379 * bbPress's dedicated admin init action
380 *
381 * @since bbPress (r2464)
382 *
383 * @uses do_action() Calls 'bbp_admin_init'
384 */
385 public function init() {
386 do_action( 'bbp_admin_init' );
387 }
388
389 /**
390 * Add the 'Right now in Forums' dashboard widget
391 *
392 * @since bbPress (r2770)
393 *
394 * @uses wp_add_dashboard_widget() To add the dashboard widget
395 */
396 public function dashboard_widget_right_now() {
397 wp_add_dashboard_widget( 'bbp-dashboard-right-now', __( 'Right Now in Forums', 'bbpress' ), 'bbp_dashboard_widget_right_now' );
398 }
399
400 /**
401 * Add some general styling to the admin area
402 *
403 * @since bbPress (r2464)
404 *
405 * @uses bbp_get_forum_post_type() To get the forum post type
406 * @uses bbp_get_topic_post_type() To get the topic post type
407 * @uses bbp_get_reply_post_type() To get the reply post type
408 * @uses sanitize_html_class() To sanitize the classes
409 * @uses do_action() Calls 'bbp_admin_head'
410 */
411 public function admin_head() {
412
413 // Icons for top level admin menus
414 $menu_icon_url = $this->images_url . 'menu.png';
415 $icon32_url = $this->images_url . 'icons32.png';
416
417 // Top level menu classes
418 $forum_class = sanitize_html_class( bbp_get_forum_post_type() );
419 $topic_class = sanitize_html_class( bbp_get_topic_post_type() );
420 $reply_class = sanitize_html_class( bbp_get_reply_post_type() ); ?>
421
422 <style type="text/css" media="screen">
423 /*<![CDATA[*/
424
425 #bbp-dashboard-right-now p.sub,
426 #bbp-dashboard-right-now .table,
427 #bbp-dashboard-right-now .versions {
428 margin: -12px;
429 }
430
431 #bbp-dashboard-right-now .inside {
432 font-size: 12px;
433 padding-top: 20px;
434 margin-bottom: 0;
435 }
436
437 #bbp-dashboard-right-now p.sub {
438 font-style: italic;
439 font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
440 padding: 5px 10px 15px;
441
442 <?php if ( is_rtl() ) : ?>
443
444 right: 15px;
445
446 <?php else : ?>
447
448 left: 15px;
449
450 <?php endif; ?>
451
452 color: #777;
453 font-size: 13px;
454 position: absolute;
455 top: -17px;
456 }
457
458 #bbp-dashboard-right-now .table {
459 margin: 0 -9px;
460 padding: 0 10px;
461 position: relative;
462 }
463
464 #bbp-dashboard-right-now .table_content {
465
466 <?php if ( is_rtl() ) : ?>
467
468 float: right;
469
470 <?php else : ?>
471
472 float: left;
473
474 <?php endif; ?>
475
476 border-top: #ececec 1px solid;
477 width: 45%;
478 }
479
480 #bbp-dashboard-right-now .table_discussion {
481
482 <?php if ( is_rtl() ) : ?>
483
484 float: left;
485
486 <?php else : ?>
487
488 float: right;
489
490 <?php endif; ?>
491
492 border-top: #ececec 1px solid;
493 width: 45%;
494 }
495
496 #bbp-dashboard-right-now table td {
497 padding: 3px 0;
498 white-space: nowrap;
499 }
500
501 #bbp-dashboard-right-now table tr.first td {
502 border-top: none;
503 }
504
505 #bbp-dashboard-right-now td.b {
506
507 <?php if ( is_rtl() ) : ?>
508
509 padding-left: 6px;
510
511 <?php else : ?>
512
513 padding-right: 6px;
514
515 <?php endif; ?>
516
517 text-align: right;
518 font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
519 font-size: 14px;
520 width: 1%;
521 }
522
523 #bbp-dashboard-right-now td.b a {
524 font-size: 18px;
525 }
526
527 #bbp-dashboard-right-now td.b a:hover {
528 color: #d54e21;
529 }
530
531 #bbp-dashboard-right-now .t {
532 font-size: 12px;
533
534 <?php if ( is_rtl() ) : ?>
535
536 padding-left: 12px;
537
538 <?php else : ?>
539
540 padding-right: 12px;
541
542 <?php endif; ?>
543
544 padding-top: 6px;
545 color: #777;
546 }
547
548 #bbp-dashboard-right-now .t a {
549 white-space: nowrap;
550 }
551
552 #bbp-dashboard-right-now .spam {
553 color: red;
554 }
555
556 #bbp-dashboard-right-now .waiting {
557 color: #e66f00;
558 }
559
560 #bbp-dashboard-right-now .approved {
561 color: green;
562 }
563
564 #bbp-dashboard-right-now .versions {
565 padding: 6px 10px 12px;
566 clear: both;
567 }
568
569 #bbp-dashboard-right-now .versions .b {
570 font-weight: bold;
571 }
572
573 #bbp-dashboard-right-now a.button {
574
575 <?php if ( is_rtl() ) : ?>
576
577 float: left;
578 clear: left;
579
580 <?php else : ?>
581
582 float: right;
583 clear: right;
584
585 <?php endif; ?>
586
587 position: relative;
588 top: -5px;
589 }
590
591 #menu-posts-<?php echo $forum_class; ?> .wp-menu-image {
592 background: url(<?php echo $menu_icon_url; ?>) no-repeat 0px -32px;
593 }
594 #menu-posts-<?php echo $forum_class; ?>:hover .wp-menu-image,
595 #menu-posts-<?php echo $forum_class; ?>.wp-has-current-submenu .wp-menu-image {
596 background: url(<?php echo $menu_icon_url; ?>) no-repeat 0px 0px;
597 }
598 #icon-edit.icon32-posts-<?php echo $forum_class; ?> {
599 background: url(<?php echo $icon32_url; ?>) no-repeat -4px 0px;
600 }
601
602 #menu-posts-<?php echo $topic_class; ?> .wp-menu-image {
603 background: url(<?php echo $menu_icon_url; ?>) no-repeat -70px -32px;
604 }
605 #menu-posts-<?php echo $topic_class; ?>:hover .wp-menu-image,
606 #menu-posts-<?php echo $topic_class; ?>.wp-has-current-submenu .wp-menu-image {
607 background: url(<?php echo $menu_icon_url; ?>) no-repeat -70px 0px;
608 }
609 #icon-edit.icon32-posts-<?php echo $topic_class; ?> {
610 background: url(<?php echo $icon32_url; ?>) no-repeat -4px -90px;
611 }
612
613 #menu-posts-<?php echo $reply_class; ?> .wp-menu-image {
614 background: url(<?php echo $menu_icon_url; ?>) no-repeat -35px -32px;
615 }
616 #menu-posts-<?php echo $reply_class; ?>:hover .wp-menu-image,
617 #menu-posts-<?php echo $reply_class; ?>.wp-has-current-submenu .wp-menu-image {
618 background: url(<?php echo $menu_icon_url; ?>) no-repeat -35px 0px;
619 }
620 #icon-edit.icon32-posts-<?php echo $reply_class; ?> {
621 background: url(<?php echo $icon32_url; ?>) no-repeat -4px -180px;
622 }
623
624 /*]]>*/
625 </style>
626
627 <?php
628
629 // Add extra actions to bbPress admin header area
630 do_action( 'bbp_admin_head' );
631 }
632
633 /**
634 * Registers the bbPress admin color scheme
635 *
636 * @since bbPress (r2521)
637 *
638 * @uses wp_admin_css_color() To register the color scheme
639 */
640 public function register_admin_style () {
641 wp_admin_css_color( 'bbpress', __( 'Green', 'bbpress' ), $this->styles_url . 'admin.css', array( '#222222', '#006600', '#deece1', '#6eb469' ) );
642 }
643 }
644 endif; // class_exists check
645
646 /**
647 * Setup bbPress Admin
648 *
649 * @since bbPress (r2596)
650 *
651 * @uses BBP_Admin
652 */
653 function bbp_admin() {
654 global $bbp;
655
656 $bbp->admin = new BBP_Admin();
657 }
658
659 ?>
660