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 / bbpress.php

bbpress.php in bbPress 2.0-rc-3, at bbpress.php

956 lines 30.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The bbPress Plugin
5 *
6 * bbPress is forum software with a twist from the creators of WordPress.
7 *
8 * @package bbPress
9 * @subpackage Main
10 */
11
12 /**
13 * Plugin Name: bbPress
14 * Plugin URI: http://bbpress.org
15 * Description: bbPress is forum software with a twist from the creators of WordPress.
16 * Author: The bbPress Community
17 * Author URI: http://bbpress.org
18 * Version: 2.0-rc-3
19 */
20
21 // Exit if accessed directly
22 if ( !defined( 'ABSPATH' ) ) exit;
23
24 if ( !class_exists( 'bbPress' ) ) :
25 /**
26 * Main bbPress Class
27 *
28 * Tap tap tap... Is this thing on?
29 *
30 * @since bbPress (r2464)
31 */
32 class bbPress {
33
34 /** Version ***************************************************************/
35
36 /**
37 * @public string bbPress version
38 */
39 public $version = '2.0-rc-3';
40
41 /**
42 * @public string bbPress DB version
43 */
44 public $db_version = '155';
45
46 /** Post types ************************************************************/
47
48 /**
49 * @public string Forum post type id
50 */
51 public $forum_post_type = '';
52
53 /**
54 * @public string Topic post type id
55 */
56 public $topic_post_type = '';
57
58 /**
59 * @ string Reply post type id
60 */
61 public $reply_post_type = '';
62
63 /** Taxonomies ************************************************************/
64
65 /**
66 * @public string Topic tag id
67 */
68 public $topic_tag_tax_id = '';
69
70 /** Permastructs **********************************************************/
71
72 /**
73 * @public string User struct
74 */
75 public $user_id = '';
76
77 /**
78 * @public string View struct
79 */
80 public $view_id = '';
81
82 /**
83 * @public string Edit struct
84 */
85 public $edit_id = '';
86
87 /** Post statuses *********************************************************/
88
89 /**
90 * @public string Closed post status id. Used by topics.
91 */
92 public $closed_status_id = '';
93
94 /**
95 * @public string Spam post status id. Used by topics and replies.
96 */
97 public $spam_status_id = '';
98
99 /**
100 * @public string Trash post status id. Used by topics and replies.
101 */
102 public $trash_status_id = '';
103
104 /**
105 * @public string Orphan post status id. Used by topics and replies.
106 */
107 public $orphan_status_id = '';
108
109 /**
110 * @public string Hidden post status id. Used by forums.
111 */
112 public $hidden_status_id = '';
113
114 /** Slugs *****************************************************************/
115
116 /**
117 * @public string Root slug
118 */
119 public $root_slug = '';
120
121 /**
122 * @public string Forum slug
123 */
124 public $forum_slug = '';
125
126 /**
127 * @public string Topic slug
128 */
129 public $topic_slug = '';
130
131 /**
132 * @public string Topic archive slug
133 */
134 public $topic_archive_slug = '';
135
136 /**
137 * @public string Reply slug
138 */
139 public $reply_slug = '';
140
141 /**
142 * @public string Topic tag slug
143 */
144 public $topic_tag_slug = '';
145
146 /**
147 * @public string User slug
148 */
149 public $user_slug = '';
150
151 /**
152 * @public string View slug
153 */
154 public $view_slug = '';
155
156 /** Paths *****************************************************************/
157
158 /**
159 * @public string Basename of the bbPress plugin directory
160 */
161 public $basename = '';
162
163 /**
164 * @public string Absolute path to the bbPress plugin directory
165 */
166 public $plugin_dir = '';
167
168 /**
169 * @public string Absolute path to the bbPress themes directory
170 */
171 public $themes_dir = '';
172
173 /**
174 * @public string Absolute path to the bbPress language directory
175 */
176 public $lang_dir = '';
177
178 /** URLs ******************************************************************/
179
180 /**
181 * @public string URL to the bbPress plugin directory
182 */
183 public $plugin_url = '';
184
185 /**
186 * @public string URL to the bbPress themes directory
187 */
188 public $themes_url = '';
189
190 /** Current ID's **********************************************************/
191
192 /**
193 * @public string Current forum id
194 */
195 public $current_forum_id = 0;
196
197 /**
198 * @public string Current topic id
199 */
200 public $current_topic_id = 0;
201
202 /**
203 * @public string Current reply id
204 */
205 public $current_reply_id = 0;
206
207 /** Users *****************************************************************/
208
209 /**
210 * @public object Current user
211 */
212 public $current_user = array();
213
214 /**
215 * @public object Displayed user
216 */
217 public $displayed_user = array();
218
219 /** Queries ***************************************************************/
220
221 /**
222 * @public WP_Query For forums
223 */
224 public $forum_query;
225
226 /**
227 * @public WP_Query For topics
228 */
229 public $topic_query;
230
231 /**
232 * @public WP_Query For replies
233 */
234 public $reply_query;
235
236 /** Arrays ****************************************************************/
237
238 /**
239 * @public array Sub Forums
240 */
241 public $sub_forums = array();
242
243 /** Errors ****************************************************************/
244
245 /**
246 * @public WP_Error Used to log and display errors
247 */
248 public $errors = array();
249
250 /** Views *****************************************************************/
251
252 /**
253 * @public array An array of registered bbPress views
254 */
255 public $views = array();
256
257 /** Forms *****************************************************************/
258
259 /**
260 * @public int The current tab index for form building
261 */
262 public $tab_index = 0;
263
264 /** Theme Compat **********************************************************/
265
266 /**
267 * @public string Theme to use for theme compatibility
268 */
269 public $theme_compat = '';
270
271 /** Extensions ************************************************************/
272
273 /**
274 * @public mixed bbPress add-ons should append globals to this
275 */
276 public $extend = false;
277
278 /** Functions *************************************************************/
279
280 /**
281 * The main bbPress loader (PHP4 compat)
282 *
283 * @since bbPress (r2464)
284 *
285 * @uses bbPress::__construct() Setup the globals needed
286 */
287 public function bbPress() {
288 $this->__construct();
289 }
290
291 /**
292 * The main bbPress loader
293 *
294 * @since bbPress (r2464)
295 *
296 * @uses bbPress::setup_globals() Setup the globals needed
297 * @uses bbPress::includes() Include the required files
298 * @uses bbPress::setup_actions() Setup the hooks and actions
299 */
300 public function __construct() {
301 $this->setup_globals();
302 $this->includes();
303 $this->setup_actions();
304 }
305
306 /**
307 * Component global variables
308 *
309 * @since bbPress (r2626)
310 * @access private
311 *
312 * @uses plugin_dir_path() To generate bbPress plugin path
313 * @uses plugin_dir_url() To generate bbPress plugin url
314 * @uses apply_filters() Calls various filters
315 */
316 private function setup_globals() {
317
318 /** Paths *************************************************************/
319
320 // bbPress root directory
321 $this->file = __FILE__;
322 $this->basename = plugin_basename( $this->file );
323 $this->plugin_dir = plugin_dir_path( $this->file );
324 $this->plugin_url = plugin_dir_url ( $this->file );
325
326 // Themes
327 $this->themes_dir = $this->plugin_dir . 'bbp-themes';
328 $this->themes_url = $this->plugin_url . 'bbp-themes';
329
330 // Languages
331 $this->lang_dir = $this->plugin_dir . 'bbp-languages';
332
333 /** Identifiers *******************************************************/
334
335 // Post type identifiers
336 $this->forum_post_type = apply_filters( 'bbp_forum_post_type', 'forum' );
337 $this->topic_post_type = apply_filters( 'bbp_topic_post_type', 'topic' );
338 $this->reply_post_type = apply_filters( 'bbp_reply_post_type', 'reply' );
339 $this->topic_tag_tax_id = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' );
340
341 // Status identifiers
342 $this->spam_status_id = apply_filters( 'bbp_spam_post_status', 'spam' );
343 $this->closed_status_id = apply_filters( 'bbp_closed_post_status', 'closed' );
344 $this->orphan_status_id = apply_filters( 'bbp_orphan_post_status', 'orphan' );
345 $this->hidden_status_id = apply_filters( 'bbp_hidden_post_status', 'hidden' );
346 $this->trash_status_id = 'trash';
347
348 // Other identifiers
349 $this->user_id = apply_filters( 'bbp_user_id', 'bbp_user' );
350 $this->view_id = apply_filters( 'bbp_view_id', 'bbp_view' );
351 $this->edit_id = apply_filters( 'bbp_edit_id', 'edit' );
352
353 /** Slugs *************************************************************/
354
355 // Root forum slug
356 $this->root_slug = apply_filters( 'bbp_root_slug', get_option( '_bbp_root_slug', 'forums' ) );
357 $this->topic_archive_slug = apply_filters( 'bbp_topic_archive_slug', get_option( '_bbp_topic_archive_slug', 'topics' ) );
358
359 // Should we include the root slug in front of component slugs
360 $prefix = !empty( $this->root_slug ) && get_option( '_bbp_include_root', true ) ? trailingslashit( $this->root_slug ) : '';
361
362 // Component slugs
363 $this->forum_slug = apply_filters( 'bbp_forum_slug', $prefix . get_option( '_bbp_forum_slug', 'forum' ) );
364 $this->topic_slug = apply_filters( 'bbp_topic_slug', $prefix . get_option( '_bbp_topic_slug', 'topic' ) );
365 $this->reply_slug = apply_filters( 'bbp_reply_slug', $prefix . get_option( '_bbp_reply_slug', 'reply' ) );
366
367 // Taxonomy slugs
368 $this->topic_tag_slug = apply_filters( 'bbp_topic_tag_slug', $prefix . get_option( '_bbp_topic_tag_slug', 'topic-tag' ) );
369
370 /** Other Slugs *******************************************************/
371
372 $this->user_slug = apply_filters( 'bbp_user_slug', $prefix . get_option( '_bbp_user_slug', 'user' ) );
373 $this->view_slug = apply_filters( 'bbp_view_slug', $prefix . get_option( '_bbp_view_slug', 'view' ) );
374
375 /** Queries ***********************************************************/
376
377 $this->forum_query = new stdClass;
378 $this->topic_query = new stdClass;
379 $this->reply_query = new stdClass;
380
381 /** Misc **************************************************************/
382
383 // Errors
384 $this->errors = new WP_Error();
385
386 // Views
387 $this->views = array();
388
389 // Tab Index
390 $this->tab_index = apply_filters( 'bbp_default_tab_index', 100 );
391
392 /** Cache *************************************************************/
393
394 // Add bbPress to global cache groups
395 wp_cache_add_global_groups( 'bbpress' );
396 }
397
398 /**
399 * Include required files
400 *
401 * @since bbPress (r2626)
402 * @access private
403 *
404 * @uses is_admin() If in WordPress admin, load additional file
405 */
406 private function includes() {
407
408 /** Core **************************************************************/
409
410 require( $this->plugin_dir . 'bbp-includes/bbp-core-hooks.php' ); // All filters and actions
411 require( $this->plugin_dir . 'bbp-includes/bbp-core-options.php' ); // Configuration Options
412 require( $this->plugin_dir . 'bbp-includes/bbp-core-caps.php' ); // Roles and capabilities
413 require( $this->plugin_dir . 'bbp-includes/bbp-core-classes.php' ); // Common classes
414 require( $this->plugin_dir . 'bbp-includes/bbp-core-widgets.php' ); // Sidebar widgets
415 require( $this->plugin_dir . 'bbp-includes/bbp-core-shortcodes.php' ); // Shortcodes for use with pages and posts
416 require( $this->plugin_dir . 'bbp-includes/bbp-core-compatibility.php' ); // Theme compatibility for existing themes
417 require( $this->plugin_dir . 'bbp-includes/bbp-core-update.php' ); // Database updater
418
419 /** Extensions ********************************************************/
420
421 require( $this->plugin_dir . 'bbp-includes/bbp-extend-akismet.php' ); // Spam prevention for topics and replies
422 require( $this->plugin_dir . 'bbp-includes/bbp-extend-buddypress.php' ); // Social network integration
423
424 /** Components ********************************************************/
425
426 require( $this->plugin_dir . 'bbp-includes/bbp-common-functions.php' ); // Common functions
427 require( $this->plugin_dir . 'bbp-includes/bbp-common-template.php' ); // Common template tags
428
429 require( $this->plugin_dir . 'bbp-includes/bbp-forum-functions.php' ); // Forum functions
430 require( $this->plugin_dir . 'bbp-includes/bbp-forum-template.php' ); // Forum template tags
431
432 require( $this->plugin_dir . 'bbp-includes/bbp-topic-functions.php' ); // Topic functions
433 require( $this->plugin_dir . 'bbp-includes/bbp-topic-template.php' ); // Topic template tags
434
435 require( $this->plugin_dir . 'bbp-includes/bbp-reply-functions.php' ); // Reply functions
436 require( $this->plugin_dir . 'bbp-includes/bbp-reply-template.php' ); // Reply template tags
437
438 require( $this->plugin_dir . 'bbp-includes/bbp-user-functions.php' ); // User functions
439 require( $this->plugin_dir . 'bbp-includes/bbp-user-template.php' ); // User template tags
440
441 /** Admin *************************************************************/
442
443 // Quick admin check and load if needed
444 if ( is_admin() )
445 require( $this->plugin_dir . 'bbp-admin/bbp-admin.php' );
446 }
447
448 /**
449 * Setup the default hooks and actions
450 *
451 * @since bbPress (r2644)
452 * @access private
453 *
454 * @uses register_activation_hook() To register the activation hook
455 * @uses register_deactivation_hook() To register the deactivation hook
456 * @uses add_action() To add various actions
457 */
458 private function setup_actions() {
459
460 // Add actions to plugin activation and deactivation hooks
461 add_action( 'activate_' . $this->basename, 'bbp_activation' );
462 add_action( 'deactivate_' . $this->basename, 'bbp_deactivation' );
463
464 // If bbPress is being deactivated, do not add any actions
465 if ( bbp_is_deactivation( $this->basename ) )
466 return;
467
468 // Array of bbPress core actions
469 $actions = array(
470 'setup_current_user', // Setup currently logged in user
471 'register_post_types', // Register post types (forum|topic|reply)
472 'register_post_statuses', // Register post statuses (closed|spam|orphan|hidden)
473 'register_taxonomies', // Register taxonomies (topic-tag)
474 'register_views', // Register the views (no-replies)
475 'register_theme_directory', // Register the theme directory (bbp-themes)
476 'load_textdomain', // Load textdomain (bbpress)
477 'add_rewrite_tags', // Add rewrite tags (view|user|edit)
478 'generate_rewrite_rules' // Generate rewrite rules (view|edit)
479 );
480
481 // Add the actions
482 foreach( $actions as $class_action )
483 add_action( 'bbp_' . $class_action, array( $this, $class_action ), 5 );
484 }
485
486 /**
487 * Load the translation file for current language. Checks the languages
488 * folder inside the bbPress plugin first, and then the default WordPress
489 * languages folder.
490 *
491 * Note that custom translation files inside the bbPress plugin folder
492 * will be removed on bbPress updates. If you're creating custom
493 * translation files, please use the global language folder.
494 *
495 * @since bbPress (r2596)
496 *
497 * @uses apply_filters() Calls 'bbpress_locale' with the
498 * {@link get_locale()} value
499 * @uses load_textdomain() To load the textdomain
500 * @return bool True on success, false on failure
501 */
502 public function load_textdomain() {
503
504 // Allow locale to be filtered
505 $locale = apply_filters( 'bbpress_locale', get_locale() );
506
507 // Get mo file name
508 $mofile = sprintf( 'bbpress-%s.mo', $locale );
509
510 // Setup paths to current locale file
511 $mofile_local = $this->lang_dir . '/' . $mofile;
512 $mofile_global = WP_LANG_DIR . '/bbpress/' . $mofile;
513
514 // Look in local /wp-content/plugins/bbpress/bbp-languages/ folder
515 if ( file_exists( $mofile_local ) )
516 return load_textdomain( 'bbpress', $mofile_local );
517
518 // Look in global /wp-content/languages/ folder
519 elseif ( file_exists( $mofile_global ) )
520 return load_textdomain( 'bbpress', $mofile_global );
521
522 // Nothing found
523 return false;
524 }
525
526 /**
527 * Sets up the bbPress theme directory to use in WordPress
528 *
529 * @since bbPress (r2507)
530 *
531 * @uses register_theme_directory() To register the theme directory
532 * @return bool True on success, false on failure
533 */
534 public function register_theme_directory() {
535 return register_theme_directory( $this->themes_dir );
536 }
537
538 /**
539 * Setup the post types for forums, topics and replies
540 *
541 * @since bbPress (r2597)
542 *
543 * @uses register_post_type() To register the post types
544 * @uses apply_filters() Calls various filters to modify the arguments
545 * sent to register_post_type()
546 */
547 public function register_post_types() {
548
549 /** Forums ************************************************************/
550
551 // Forum labels
552 $forum['labels'] = array(
553 'name' => __( 'Forums', 'bbpress' ),
554 'menu_name' => __( 'Forums', 'bbpress' ),
555 'singular_name' => __( 'Forum', 'bbpress' ),
556 'all_items' => __( 'All Forums', 'bbpress' ),
557 'add_new' => __( 'New Forum', 'bbpress' ),
558 'add_new_item' => __( 'Create New Forum', 'bbpress' ),
559 'edit' => __( 'Edit', 'bbpress' ),
560 'edit_item' => __( 'Edit Forum', 'bbpress' ),
561 'new_item' => __( 'New Forum', 'bbpress' ),
562 'view' => __( 'View Forum', 'bbpress' ),
563 'view_item' => __( 'View Forum', 'bbpress' ),
564 'search_items' => __( 'Search Forums', 'bbpress' ),
565 'not_found' => __( 'No forums found', 'bbpress' ),
566 'not_found_in_trash' => __( 'No forums found in Trash', 'bbpress' ),
567 'parent_item_colon' => __( 'Parent Forum:', 'bbpress' )
568 );
569
570 // Forum rewrite
571 $forum['rewrite'] = array(
572 'slug' => $this->forum_slug,
573 'with_front' => false
574 );
575
576 // Forum supports
577 $forum['supports'] = array(
578 'title',
579 'editor',
580 'revisions'
581 );
582
583 // Forum filter
584 $bbp_cpt['forum'] = apply_filters( 'bbp_register_forum_post_type', array(
585 'labels' => $forum['labels'],
586 'rewrite' => $forum['rewrite'],
587 'supports' => $forum['supports'],
588 'description' => __( 'bbPress Forums', 'bbpress' ),
589 'capabilities' => bbp_get_forum_caps(),
590 'capability_type' => array( 'forum', 'forums' ),
591 'menu_position' => 56,
592 'has_archive' => $this->root_slug,
593 'exclude_from_search' => true,
594 'show_in_nav_menus' => true,
595 'public' => true,
596 'show_ui' => true,
597 'can_export' => true,
598 'hierarchical' => true,
599 'query_var' => true,
600 'menu_icon' => ''
601 ) );
602
603 // Register Forum content type
604 register_post_type( $this->forum_post_type, $bbp_cpt['forum'] );
605
606 /** Topics ************************************************************/
607
608 // Topic labels
609 $topic['labels'] = array(
610 'name' => __( 'Topics', 'bbpress' ),
611 'menu_name' => __( 'Topics', 'bbpress' ),
612 'singular_name' => __( 'Topic', 'bbpress' ),
613 'all_items' => __( 'All Topics', 'bbpress' ),
614 'add_new' => __( 'New Topic', 'bbpress' ),
615 'add_new_item' => __( 'Create New Topic', 'bbpress' ),
616 'edit' => __( 'Edit', 'bbpress' ),
617 'edit_item' => __( 'Edit Topic', 'bbpress' ),
618 'new_item' => __( 'New Topic', 'bbpress' ),
619 'view' => __( 'View Topic', 'bbpress' ),
620 'view_item' => __( 'View Topic', 'bbpress' ),
621 'search_items' => __( 'Search Topics', 'bbpress' ),
622 'not_found' => __( 'No topics found', 'bbpress' ),
623 'not_found_in_trash' => __( 'No topics found in Trash', 'bbpress' ),
624 'parent_item_colon' => __( 'Forum:', 'bbpress' )
625 );
626
627 // Topic rewrite
628 $topic['rewrite'] = array(
629 'slug' => $this->topic_slug,
630 'with_front' => false
631 );
632
633 // Topic supports
634 $topic['supports'] = array(
635 'title',
636 'editor',
637 'revisions'
638 );
639
640 // Topic Filter
641 $bbp_cpt['topic'] = apply_filters( 'bbp_register_topic_post_type', array(
642 'labels' => $topic['labels'],
643 'rewrite' => $topic['rewrite'],
644 'supports' => $topic['supports'],
645 'description' => __( 'bbPress Topics', 'bbpress' ),
646 'capabilities' => bbp_get_topic_caps(),
647 'capability_type' => array( 'topic', 'topics' ),
648 'menu_position' => 57,
649 'has_archive' => $this->topic_archive_slug,
650 'exclude_from_search' => true,
651 'show_in_nav_menus' => false,
652 'public' => true,
653 'show_ui' => true,
654 'can_export' => true,
655 'hierarchical' => false,
656 'query_var' => true,
657 'menu_icon' => ''
658 ) );
659
660 // Register Topic content type
661 register_post_type( $this->topic_post_type, $bbp_cpt['topic'] );
662
663 /** Replies ***********************************************************/
664
665 // Reply labels
666 $reply['labels'] = array(
667 'name' => __( 'Replies', 'bbpress' ),
668 'menu_name' => __( 'Replies', 'bbpress' ),
669 'singular_name' => __( 'Reply', 'bbpress' ),
670 'all_items' => __( 'All Replies', 'bbpress' ),
671 'add_new' => __( 'New Reply', 'bbpress' ),
672 'add_new_item' => __( 'Create New Reply', 'bbpress' ),
673 'edit' => __( 'Edit', 'bbpress' ),
674 'edit_item' => __( 'Edit Reply', 'bbpress' ),
675 'new_item' => __( 'New Reply', 'bbpress' ),
676 'view' => __( 'View Reply', 'bbpress' ),
677 'view_item' => __( 'View Reply', 'bbpress' ),
678 'search_items' => __( 'Search Replies', 'bbpress' ),
679 'not_found' => __( 'No replies found', 'bbpress' ),
680 'not_found_in_trash' => __( 'No replies found in Trash', 'bbpress' ),
681 'parent_item_colon' => __( 'Topic:', 'bbpress' )
682 );
683
684 // Reply rewrite
685 $reply['rewrite'] = array(
686 'slug' => $this->reply_slug,
687 'with_front' => false
688 );
689
690 // Reply supports
691 $reply['supports'] = array(
692 'title',
693 'editor',
694 'revisions'
695 );
696
697 // Reply filter
698 $bbp_cpt['reply'] = apply_filters( 'bbp_register_reply_post_type', array(
699 'labels' => $reply['labels'],
700 'rewrite' => $reply['rewrite'],
701 'supports' => $reply['supports'],
702 'description' => __( 'bbPress Replies', 'bbpress' ),
703 'capabilities' => bbp_get_reply_caps(),
704 'capability_type' => array( 'reply', 'replies' ),
705 'menu_position' => 58,
706 'exclude_from_search' => true,
707 'has_archive' => false,
708 'show_in_nav_menus' => false,
709 'public' => true,
710 'show_ui' => true,
711 'can_export' => true,
712 'hierarchical' => false,
713 'query_var' => true,
714 'menu_icon' => ''
715 ) );
716
717 // Register reply content type
718 register_post_type( $this->reply_post_type, $bbp_cpt['reply'] );
719 }
720
721 /**
722 * Register the post statuses
723 *
724 * @since bbPress (r2727)
725 *
726 * @uses register_post_status() To register post statuses
727 * @uses $wp_post_statuses To modify trash and private statuses
728 * @uses current_user_can() To check if the current user is capable &
729 * modify $wp_post_statuses accordingly
730 */
731 public function register_post_statuses() {
732 global $wp_post_statuses;
733
734 // Closed
735 $status = apply_filters( 'bbp_register_closed_post_status', array(
736 'label' => _x( 'Closed', 'post', 'bbpress' ),
737 'label_count' => _nx_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'bbpress' ),
738 'public' => true,
739 'show_in_admin_all' => true
740 ) );
741 register_post_status( $this->closed_status_id, $status );
742
743 // Spam
744 $status = apply_filters( 'bbp_register_spam_post_status', array(
745 'label' => _x( 'Spam', 'post', 'bbpress' ),
746 'label_count' => _nx_noop( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'bbpress' ),
747 'protected' => true,
748 'exclude_from_search' => true,
749 'show_in_admin_status_list' => true,
750 'show_in_admin_all_list' => false
751 ) );
752 register_post_status( $this->spam_status_id, $status );
753
754 // Orphan
755 $status = apply_filters( 'bbp_register_orphan_post_status', array(
756 'label' => _x( 'Orphan', 'post', 'bbpress' ),
757 'label_count' => _nx_noop( 'Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'bbpress' ),
758 'protected' => true,
759 'exclude_from_search' => true,
760 'show_in_admin_status_list' => true,
761 'show_in_admin_all_list' => false
762 ) );
763 register_post_status( $this->orphan_status_id, $status );
764
765 // Hidden
766 $status = apply_filters( 'bbp_register_hidden_post_status', array(
767 'label' => _x( 'Hidden', 'post', 'bbpress' ),
768 'label_count' => _nx_noop( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'bbpress' ),
769 'protected' => true,
770 'exclude_from_search' => true,
771 'show_in_admin_status_list' => true,
772 'show_in_admin_all_list' => true
773 ) );
774 register_post_status( $this->hidden_status_id, $status );
775
776 /**
777 * Trash fix
778 *
779 * We need to remove the internal arg and change that to
780 * protected so that the users with 'view_trash' cap can view
781 * single trashed topics/replies in the front-end as wp_query
782 * doesn't allow any hack for the trashed topics to be viewed.
783 */
784 if ( !empty( $wp_post_statuses['trash'] ) ) {
785
786 // User can view trash so set internal to false
787 if ( current_user_can( 'view_trash' ) ) {
788 $wp_post_statuses['trash']->internal = false;
789 $wp_post_statuses['trash']->protected = true;
790
791 // User cannot view trash so set internal to true
792 } elseif ( !current_user_can( 'view_trash' ) ) {
793 $wp_post_statuses['trash']->internal = true;
794 }
795 }
796 }
797
798 /**
799 * Register the topic tag taxonomy
800 *
801 * @since bbPress (r2464)
802 *
803 * @uses register_taxonomy() To register the taxonomy
804 */
805 public function register_taxonomies() {
806
807 // Topic tag labels
808 $topic_tag['labels'] = array(
809 'name' => __( 'Topic Tags', 'bbpress' ),
810 'singular_name' => __( 'Topic Tag', 'bbpress' ),
811 'search_items' => __( 'Search Tags', 'bbpress' ),
812 'popular_items' => __( 'Popular Tags', 'bbpress' ),
813 'all_items' => __( 'All Tags', 'bbpress' ),
814 'edit_item' => __( 'Edit Tag', 'bbpress' ),
815 'update_item' => __( 'Update Tag', 'bbpress' ),
816 'add_new_item' => __( 'Add New Tag', 'bbpress' ),
817 'new_item_name' => __( 'New Tag Name', 'bbpress' ),
818 'view_item' => __( 'View Topic Tag', 'bbpress' )
819 );
820
821 // Topic tag rewrite
822 $topic_tag['rewrite'] = array(
823 'slug' => $this->topic_tag_slug,
824 'with_front' => false
825 );
826
827 // Topic tag filter
828 $bbp_tt = apply_filters( 'bbp_register_topic_taxonomy', array(
829 'labels' => $topic_tag['labels'],
830 'rewrite' => $topic_tag['rewrite'],
831 'capabilities' => bbp_get_topic_tag_caps(),
832 'update_count_callback' => '_update_post_term_count',
833 'query_var' => true,
834 'show_tagcloud' => true,
835 'hierarchical' => false,
836 'public' => true,
837 'show_ui' => true
838 ) );
839
840 // Register the topic tag taxonomy
841 register_taxonomy(
842 $this->topic_tag_tax_id, // The topic tag id
843 $this->topic_post_type, // The topic post type
844 $bbp_tt
845 );
846 }
847
848 /**
849 * Register the bbPress views
850 *
851 * @since bbPress (r2789)
852 *
853 * @uses bbp_register_view() To register the views
854 */
855 public function register_views() {
856
857 // Topics with no replies
858 $no_replies = apply_filters( 'bbp_register_view_no_replies', array(
859 'meta_key' => '_bbp_reply_count',
860 'meta_value' => 1,
861 'meta_compare' => '<',
862 'orderby' => ''
863 ) );
864
865 bbp_register_view( 'no-replies', __( 'Topics with no replies', 'bbpress' ), $no_replies );
866 }
867
868 /**
869 * Setup the currently logged-in user
870 *
871 * Do not to call this prematurely, I.E. before the 'init' action has
872 * started. This function is naturally hooked into 'init' to ensure proper
873 * execution. get_currentuserinfo() is used to check for XMLRPC_REQUEST to
874 * avoid xmlrpc errors.
875 *
876 * @since bbPress (r2697)
877 *
878 * @uses wp_get_current_user()
879 */
880 public function setup_current_user() {
881 $this->current_user = &wp_get_current_user();
882 }
883
884 /**
885 * Add the bbPress-specific rewrite tags
886 *
887 * @since bbPress (r2753)
888 *
889 * @uses add_rewrite_tag() To add the rewrite tags
890 */
891 public function add_rewrite_tags() {
892
893 // Pad attributes
894 $pad = 2;
895 $wrapper = '%';
896
897 // Setup the tags
898 $bbp_user = str_pad( $this->user_id, strlen( $this->user_id ) + $pad, $wrapper, STR_PAD_BOTH );
899 $bbp_view = str_pad( $this->view_id, strlen( $this->view_id ) + $pad, $wrapper, STR_PAD_BOTH );
900 $bbp_edit = str_pad( $this->edit_id, strlen( $this->edit_id ) + $pad, $wrapper, STR_PAD_BOTH );
901
902 // User Profile tag
903 add_rewrite_tag( $bbp_user, '([^/]+)' );
904
905 // View Page tag
906 add_rewrite_tag( $bbp_view, '([^/]+)' );
907
908 // Edit Page tag
909 add_rewrite_tag( $bbp_edit, '([1]{1,})' );
910 }
911
912 /**
913 * Register bbPress-specific rewrite rules
914 *
915 * @since bbPress (r2688)
916 *
917 * @param WP_Rewrite $wp_rewrite bbPress-sepecific rules are appended in
918 * $wp_rewrite->rules
919 */
920 public function generate_rewrite_rules( $wp_rewrite ) {
921
922 // New rules to merge with existing
923 $bbp_rules = array(
924
925 // Edit Topic/Reply
926 $this->topic_slug . '/([^/]+)/edit/?$' => 'index.php?' . $this->topic_post_type . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
927 $this->reply_slug . '/([^/]+)/edit/?$' => 'index.php?' . $this->reply_post_type . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
928
929 // Edit Topic Tag
930 $this->topic_tag_slug . '/([^/]+)/edit/?$' => 'index.php?' . $this->topic_tag_tax_id . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
931
932 // Profile Page
933 $this->user_slug . '/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?' . $this->user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
934 $this->user_slug . '/([^/]+)/?$' => 'index.php?' . $this->user_id . '=' . $wp_rewrite->preg_index( 1 ),
935 $this->user_slug . '/([^/]+)/edit/?$' => 'index.php?' . $this->user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
936
937 // View Page
938 $this->view_slug . '/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?' . $this->view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
939 $this->view_slug . '/([^/]+)/?$' => 'index.php?' . $this->view_id . '=' . $wp_rewrite->preg_index( 1 )
940 );
941
942 // Merge bbPress rules with existing
943 $wp_rewrite->rules = array_merge( $bbp_rules, $wp_rewrite->rules );
944
945 // Return merged rules
946 return $wp_rewrite;
947 }
948 }
949
950 // "And now here's something we hope you'll really like!"
951 $GLOBALS['bbp'] = new bbPress();
952
953 endif; // class_exists check
954
955 ?>
956