PluginProbe
bbPress / 2.0-rc-4
bbPress v2.0-rc-4
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-4, at bbpress.php

963 lines 30.6 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-4
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-4';
40
41 /**
42 * @public string bbPress DB version
43 */
44 public $db_version = '165';
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 /** Option Overload *******************************************************/
279
280 /**
281 * @var array Optional Overloads default options retrieved from get_option()
282 */
283 public $options = array();
284
285 /** Functions *************************************************************/
286
287 /**
288 * The main bbPress loader (PHP4 compat)
289 *
290 * @since bbPress (r2464)
291 *
292 * @uses bbPress::__construct() Setup the globals needed
293 */
294 public function bbPress() {
295 $this->__construct();
296 }
297
298 /**
299 * The main bbPress loader
300 *
301 * @since bbPress (r2464)
302 *
303 * @uses bbPress::setup_globals() Setup the globals needed
304 * @uses bbPress::includes() Include the required files
305 * @uses bbPress::setup_actions() Setup the hooks and actions
306 */
307 public function __construct() {
308 $this->setup_globals();
309 $this->includes();
310 $this->setup_actions();
311 }
312
313 /**
314 * Component global variables
315 *
316 * @since bbPress (r2626)
317 * @access private
318 *
319 * @uses plugin_dir_path() To generate bbPress plugin path
320 * @uses plugin_dir_url() To generate bbPress plugin url
321 * @uses apply_filters() Calls various filters
322 */
323 private function setup_globals() {
324
325 /** Paths *************************************************************/
326
327 // bbPress root directory
328 $this->file = __FILE__;
329 $this->basename = plugin_basename( $this->file );
330 $this->plugin_dir = plugin_dir_path( $this->file );
331 $this->plugin_url = plugin_dir_url ( $this->file );
332
333 // Themes
334 $this->themes_dir = $this->plugin_dir . 'bbp-themes';
335 $this->themes_url = $this->plugin_url . 'bbp-themes';
336
337 // Languages
338 $this->lang_dir = $this->plugin_dir . 'bbp-languages';
339
340 /** Identifiers *******************************************************/
341
342 // Post type identifiers
343 $this->forum_post_type = apply_filters( 'bbp_forum_post_type', 'forum' );
344 $this->topic_post_type = apply_filters( 'bbp_topic_post_type', 'topic' );
345 $this->reply_post_type = apply_filters( 'bbp_reply_post_type', 'reply' );
346 $this->topic_tag_tax_id = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' );
347
348 // Status identifiers
349 $this->spam_status_id = apply_filters( 'bbp_spam_post_status', 'spam' );
350 $this->closed_status_id = apply_filters( 'bbp_closed_post_status', 'closed' );
351 $this->orphan_status_id = apply_filters( 'bbp_orphan_post_status', 'orphan' );
352 $this->hidden_status_id = apply_filters( 'bbp_hidden_post_status', 'hidden' );
353 $this->trash_status_id = 'trash';
354
355 // Other identifiers
356 $this->user_id = apply_filters( 'bbp_user_id', 'bbp_user' );
357 $this->view_id = apply_filters( 'bbp_view_id', 'bbp_view' );
358 $this->edit_id = apply_filters( 'bbp_edit_id', 'edit' );
359
360 /** Slugs *************************************************************/
361
362 // Root forum slug
363 $this->root_slug = apply_filters( 'bbp_root_slug', get_option( '_bbp_root_slug', 'forums' ) );
364 $this->topic_archive_slug = apply_filters( 'bbp_topic_archive_slug', get_option( '_bbp_topic_archive_slug', 'topics' ) );
365
366 // Should we include the root slug in front of component slugs
367 $prefix = !empty( $this->root_slug ) && get_option( '_bbp_include_root', true ) ? trailingslashit( $this->root_slug ) : '';
368
369 // Component slugs
370 $this->forum_slug = apply_filters( 'bbp_forum_slug', $prefix . get_option( '_bbp_forum_slug', 'forum' ) );
371 $this->topic_slug = apply_filters( 'bbp_topic_slug', $prefix . get_option( '_bbp_topic_slug', 'topic' ) );
372 $this->reply_slug = apply_filters( 'bbp_reply_slug', $prefix . get_option( '_bbp_reply_slug', 'reply' ) );
373
374 // Taxonomy slugs
375 $this->topic_tag_slug = apply_filters( 'bbp_topic_tag_slug', $prefix . get_option( '_bbp_topic_tag_slug', 'topic-tag' ) );
376
377 /** Other Slugs *******************************************************/
378
379 $this->user_slug = apply_filters( 'bbp_user_slug', $prefix . get_option( '_bbp_user_slug', 'user' ) );
380 $this->view_slug = apply_filters( 'bbp_view_slug', $prefix . get_option( '_bbp_view_slug', 'view' ) );
381
382 /** Queries ***********************************************************/
383
384 $this->forum_query = new stdClass;
385 $this->topic_query = new stdClass;
386 $this->reply_query = new stdClass;
387
388 /** Misc **************************************************************/
389
390 // Errors
391 $this->errors = new WP_Error();
392
393 // Views
394 $this->views = array();
395
396 // Tab Index
397 $this->tab_index = apply_filters( 'bbp_default_tab_index', 100 );
398
399 /** Cache *************************************************************/
400
401 // Add bbPress to global cache groups
402 wp_cache_add_global_groups( 'bbpress' );
403 }
404
405 /**
406 * Include required files
407 *
408 * @since bbPress (r2626)
409 * @access private
410 *
411 * @uses is_admin() If in WordPress admin, load additional file
412 */
413 private function includes() {
414
415 /** Core **************************************************************/
416
417 require( $this->plugin_dir . 'bbp-includes/bbp-core-hooks.php' ); // All filters and actions
418 require( $this->plugin_dir . 'bbp-includes/bbp-core-options.php' ); // Configuration Options
419 require( $this->plugin_dir . 'bbp-includes/bbp-core-caps.php' ); // Roles and capabilities
420 require( $this->plugin_dir . 'bbp-includes/bbp-core-classes.php' ); // Common classes
421 require( $this->plugin_dir . 'bbp-includes/bbp-core-widgets.php' ); // Sidebar widgets
422 require( $this->plugin_dir . 'bbp-includes/bbp-core-shortcodes.php' ); // Shortcodes for use with pages and posts
423 require( $this->plugin_dir . 'bbp-includes/bbp-core-compatibility.php' ); // Theme compatibility for existing themes
424 require( $this->plugin_dir . 'bbp-includes/bbp-core-update.php' ); // Database updater
425
426 /** Extensions ********************************************************/
427
428 require( $this->plugin_dir . 'bbp-includes/bbp-extend-akismet.php' ); // Spam prevention for topics and replies
429 require( $this->plugin_dir . 'bbp-includes/bbp-extend-buddypress.php' ); // Social network integration
430
431 /** Components ********************************************************/
432
433 require( $this->plugin_dir . 'bbp-includes/bbp-common-functions.php' ); // Common functions
434 require( $this->plugin_dir . 'bbp-includes/bbp-common-template.php' ); // Common template tags
435
436 require( $this->plugin_dir . 'bbp-includes/bbp-forum-functions.php' ); // Forum functions
437 require( $this->plugin_dir . 'bbp-includes/bbp-forum-template.php' ); // Forum template tags
438
439 require( $this->plugin_dir . 'bbp-includes/bbp-topic-functions.php' ); // Topic functions
440 require( $this->plugin_dir . 'bbp-includes/bbp-topic-template.php' ); // Topic template tags
441
442 require( $this->plugin_dir . 'bbp-includes/bbp-reply-functions.php' ); // Reply functions
443 require( $this->plugin_dir . 'bbp-includes/bbp-reply-template.php' ); // Reply template tags
444
445 require( $this->plugin_dir . 'bbp-includes/bbp-user-functions.php' ); // User functions
446 require( $this->plugin_dir . 'bbp-includes/bbp-user-template.php' ); // User template tags
447
448 /** Admin *************************************************************/
449
450 // Quick admin check and load if needed
451 if ( is_admin() )
452 require( $this->plugin_dir . 'bbp-admin/bbp-admin.php' );
453 }
454
455 /**
456 * Setup the default hooks and actions
457 *
458 * @since bbPress (r2644)
459 * @access private
460 *
461 * @uses register_activation_hook() To register the activation hook
462 * @uses register_deactivation_hook() To register the deactivation hook
463 * @uses add_action() To add various actions
464 */
465 private function setup_actions() {
466
467 // Add actions to plugin activation and deactivation hooks
468 add_action( 'activate_' . $this->basename, 'bbp_activation' );
469 add_action( 'deactivate_' . $this->basename, 'bbp_deactivation' );
470
471 // If bbPress is being deactivated, do not add any actions
472 if ( bbp_is_deactivation( $this->basename ) )
473 return;
474
475 // Array of bbPress core actions
476 $actions = array(
477 'setup_current_user', // Setup currently logged in user
478 'register_post_types', // Register post types (forum|topic|reply)
479 'register_post_statuses', // Register post statuses (closed|spam|orphan|hidden)
480 'register_taxonomies', // Register taxonomies (topic-tag)
481 'register_views', // Register the views (no-replies)
482 'register_theme_directory', // Register the theme directory (bbp-themes)
483 'load_textdomain', // Load textdomain (bbpress)
484 'add_rewrite_tags', // Add rewrite tags (view|user|edit)
485 'generate_rewrite_rules' // Generate rewrite rules (view|edit)
486 );
487
488 // Add the actions
489 foreach( $actions as $class_action )
490 add_action( 'bbp_' . $class_action, array( $this, $class_action ), 5 );
491 }
492
493 /**
494 * Load the translation file for current language. Checks the languages
495 * folder inside the bbPress plugin first, and then the default WordPress
496 * languages folder.
497 *
498 * Note that custom translation files inside the bbPress plugin folder
499 * will be removed on bbPress updates. If you're creating custom
500 * translation files, please use the global language folder.
501 *
502 * @since bbPress (r2596)
503 *
504 * @uses apply_filters() Calls 'bbpress_locale' with the
505 * {@link get_locale()} value
506 * @uses load_textdomain() To load the textdomain
507 * @return bool True on success, false on failure
508 */
509 public function load_textdomain() {
510
511 // Allow locale to be filtered
512 $locale = apply_filters( 'bbpress_locale', get_locale() );
513
514 // Get mo file name
515 $mofile = sprintf( 'bbpress-%s.mo', $locale );
516
517 // Setup paths to current locale file
518 $mofile_local = $this->lang_dir . '/' . $mofile;
519 $mofile_global = WP_LANG_DIR . '/bbpress/' . $mofile;
520
521 // Look in local /wp-content/plugins/bbpress/bbp-languages/ folder
522 if ( file_exists( $mofile_local ) )
523 return load_textdomain( 'bbpress', $mofile_local );
524
525 // Look in global /wp-content/languages/ folder
526 elseif ( file_exists( $mofile_global ) )
527 return load_textdomain( 'bbpress', $mofile_global );
528
529 // Nothing found
530 return false;
531 }
532
533 /**
534 * Sets up the bbPress theme directory to use in WordPress
535 *
536 * @since bbPress (r2507)
537 *
538 * @uses register_theme_directory() To register the theme directory
539 * @return bool True on success, false on failure
540 */
541 public function register_theme_directory() {
542 return register_theme_directory( $this->themes_dir );
543 }
544
545 /**
546 * Setup the post types for forums, topics and replies
547 *
548 * @since bbPress (r2597)
549 *
550 * @uses register_post_type() To register the post types
551 * @uses apply_filters() Calls various filters to modify the arguments
552 * sent to register_post_type()
553 */
554 public function register_post_types() {
555
556 /** Forums ************************************************************/
557
558 // Forum labels
559 $forum['labels'] = array(
560 'name' => __( 'Forums', 'bbpress' ),
561 'menu_name' => __( 'Forums', 'bbpress' ),
562 'singular_name' => __( 'Forum', 'bbpress' ),
563 'all_items' => __( 'All Forums', 'bbpress' ),
564 'add_new' => __( 'New Forum', 'bbpress' ),
565 'add_new_item' => __( 'Create New Forum', 'bbpress' ),
566 'edit' => __( 'Edit', 'bbpress' ),
567 'edit_item' => __( 'Edit Forum', 'bbpress' ),
568 'new_item' => __( 'New Forum', 'bbpress' ),
569 'view' => __( 'View Forum', 'bbpress' ),
570 'view_item' => __( 'View Forum', 'bbpress' ),
571 'search_items' => __( 'Search Forums', 'bbpress' ),
572 'not_found' => __( 'No forums found', 'bbpress' ),
573 'not_found_in_trash' => __( 'No forums found in Trash', 'bbpress' ),
574 'parent_item_colon' => __( 'Parent Forum:', 'bbpress' )
575 );
576
577 // Forum rewrite
578 $forum['rewrite'] = array(
579 'slug' => $this->forum_slug,
580 'with_front' => false
581 );
582
583 // Forum supports
584 $forum['supports'] = array(
585 'title',
586 'editor',
587 'revisions'
588 );
589
590 // Forum filter
591 $bbp_cpt['forum'] = apply_filters( 'bbp_register_forum_post_type', array(
592 'labels' => $forum['labels'],
593 'rewrite' => $forum['rewrite'],
594 'supports' => $forum['supports'],
595 'description' => __( 'bbPress Forums', 'bbpress' ),
596 'capabilities' => bbp_get_forum_caps(),
597 'capability_type' => array( 'forum', 'forums' ),
598 'menu_position' => 56,
599 'has_archive' => $this->root_slug,
600 'exclude_from_search' => true,
601 'show_in_nav_menus' => true,
602 'public' => true,
603 'show_ui' => true,
604 'can_export' => true,
605 'hierarchical' => true,
606 'query_var' => true,
607 'menu_icon' => ''
608 ) );
609
610 // Register Forum content type
611 register_post_type( $this->forum_post_type, $bbp_cpt['forum'] );
612
613 /** Topics ************************************************************/
614
615 // Topic labels
616 $topic['labels'] = array(
617 'name' => __( 'Topics', 'bbpress' ),
618 'menu_name' => __( 'Topics', 'bbpress' ),
619 'singular_name' => __( 'Topic', 'bbpress' ),
620 'all_items' => __( 'All Topics', 'bbpress' ),
621 'add_new' => __( 'New Topic', 'bbpress' ),
622 'add_new_item' => __( 'Create New Topic', 'bbpress' ),
623 'edit' => __( 'Edit', 'bbpress' ),
624 'edit_item' => __( 'Edit Topic', 'bbpress' ),
625 'new_item' => __( 'New Topic', 'bbpress' ),
626 'view' => __( 'View Topic', 'bbpress' ),
627 'view_item' => __( 'View Topic', 'bbpress' ),
628 'search_items' => __( 'Search Topics', 'bbpress' ),
629 'not_found' => __( 'No topics found', 'bbpress' ),
630 'not_found_in_trash' => __( 'No topics found in Trash', 'bbpress' ),
631 'parent_item_colon' => __( 'Forum:', 'bbpress' )
632 );
633
634 // Topic rewrite
635 $topic['rewrite'] = array(
636 'slug' => $this->topic_slug,
637 'with_front' => false
638 );
639
640 // Topic supports
641 $topic['supports'] = array(
642 'title',
643 'editor',
644 'revisions'
645 );
646
647 // Topic Filter
648 $bbp_cpt['topic'] = apply_filters( 'bbp_register_topic_post_type', array(
649 'labels' => $topic['labels'],
650 'rewrite' => $topic['rewrite'],
651 'supports' => $topic['supports'],
652 'description' => __( 'bbPress Topics', 'bbpress' ),
653 'capabilities' => bbp_get_topic_caps(),
654 'capability_type' => array( 'topic', 'topics' ),
655 'menu_position' => 57,
656 'has_archive' => $this->topic_archive_slug,
657 'exclude_from_search' => true,
658 'show_in_nav_menus' => false,
659 'public' => true,
660 'show_ui' => true,
661 'can_export' => true,
662 'hierarchical' => false,
663 'query_var' => true,
664 'menu_icon' => ''
665 ) );
666
667 // Register Topic content type
668 register_post_type( $this->topic_post_type, $bbp_cpt['topic'] );
669
670 /** Replies ***********************************************************/
671
672 // Reply labels
673 $reply['labels'] = array(
674 'name' => __( 'Replies', 'bbpress' ),
675 'menu_name' => __( 'Replies', 'bbpress' ),
676 'singular_name' => __( 'Reply', 'bbpress' ),
677 'all_items' => __( 'All Replies', 'bbpress' ),
678 'add_new' => __( 'New Reply', 'bbpress' ),
679 'add_new_item' => __( 'Create New Reply', 'bbpress' ),
680 'edit' => __( 'Edit', 'bbpress' ),
681 'edit_item' => __( 'Edit Reply', 'bbpress' ),
682 'new_item' => __( 'New Reply', 'bbpress' ),
683 'view' => __( 'View Reply', 'bbpress' ),
684 'view_item' => __( 'View Reply', 'bbpress' ),
685 'search_items' => __( 'Search Replies', 'bbpress' ),
686 'not_found' => __( 'No replies found', 'bbpress' ),
687 'not_found_in_trash' => __( 'No replies found in Trash', 'bbpress' ),
688 'parent_item_colon' => __( 'Topic:', 'bbpress' )
689 );
690
691 // Reply rewrite
692 $reply['rewrite'] = array(
693 'slug' => $this->reply_slug,
694 'with_front' => false
695 );
696
697 // Reply supports
698 $reply['supports'] = array(
699 'title',
700 'editor',
701 'revisions'
702 );
703
704 // Reply filter
705 $bbp_cpt['reply'] = apply_filters( 'bbp_register_reply_post_type', array(
706 'labels' => $reply['labels'],
707 'rewrite' => $reply['rewrite'],
708 'supports' => $reply['supports'],
709 'description' => __( 'bbPress Replies', 'bbpress' ),
710 'capabilities' => bbp_get_reply_caps(),
711 'capability_type' => array( 'reply', 'replies' ),
712 'menu_position' => 58,
713 'exclude_from_search' => true,
714 'has_archive' => false,
715 'show_in_nav_menus' => false,
716 'public' => true,
717 'show_ui' => true,
718 'can_export' => true,
719 'hierarchical' => false,
720 'query_var' => true,
721 'menu_icon' => ''
722 ) );
723
724 // Register reply content type
725 register_post_type( $this->reply_post_type, $bbp_cpt['reply'] );
726 }
727
728 /**
729 * Register the post statuses
730 *
731 * @since bbPress (r2727)
732 *
733 * @uses register_post_status() To register post statuses
734 * @uses $wp_post_statuses To modify trash and private statuses
735 * @uses current_user_can() To check if the current user is capable &
736 * modify $wp_post_statuses accordingly
737 */
738 public function register_post_statuses() {
739 global $wp_post_statuses;
740
741 // Closed
742 $status = apply_filters( 'bbp_register_closed_post_status', array(
743 'label' => _x( 'Closed', 'post', 'bbpress' ),
744 'label_count' => _nx_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'bbpress' ),
745 'public' => true,
746 'show_in_admin_all' => true
747 ) );
748 register_post_status( $this->closed_status_id, $status );
749
750 // Spam
751 $status = apply_filters( 'bbp_register_spam_post_status', array(
752 'label' => _x( 'Spam', 'post', 'bbpress' ),
753 'label_count' => _nx_noop( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'bbpress' ),
754 'protected' => true,
755 'exclude_from_search' => true,
756 'show_in_admin_status_list' => true,
757 'show_in_admin_all_list' => false
758 ) );
759 register_post_status( $this->spam_status_id, $status );
760
761 // Orphan
762 $status = apply_filters( 'bbp_register_orphan_post_status', array(
763 'label' => _x( 'Orphan', 'post', 'bbpress' ),
764 'label_count' => _nx_noop( 'Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'bbpress' ),
765 'protected' => true,
766 'exclude_from_search' => true,
767 'show_in_admin_status_list' => true,
768 'show_in_admin_all_list' => false
769 ) );
770 register_post_status( $this->orphan_status_id, $status );
771
772 // Hidden
773 $status = apply_filters( 'bbp_register_hidden_post_status', array(
774 'label' => _x( 'Hidden', 'post', 'bbpress' ),
775 'label_count' => _nx_noop( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'bbpress' ),
776 'private' => true,
777 'exclude_from_search' => true,
778 'show_in_admin_status_list' => true,
779 'show_in_admin_all_list' => true
780 ) );
781 register_post_status( $this->hidden_status_id, $status );
782
783 /**
784 * Trash fix
785 *
786 * We need to remove the internal arg and change that to
787 * protected so that the users with 'view_trash' cap can view
788 * single trashed topics/replies in the front-end as wp_query
789 * doesn't allow any hack for the trashed topics to be viewed.
790 */
791 if ( !empty( $wp_post_statuses['trash'] ) ) {
792
793 // User can view trash so set internal to false
794 if ( current_user_can( 'view_trash' ) ) {
795 $wp_post_statuses['trash']->internal = false;
796 $wp_post_statuses['trash']->protected = true;
797
798 // User cannot view trash so set internal to true
799 } elseif ( !current_user_can( 'view_trash' ) ) {
800 $wp_post_statuses['trash']->internal = true;
801 }
802 }
803 }
804
805 /**
806 * Register the topic tag taxonomy
807 *
808 * @since bbPress (r2464)
809 *
810 * @uses register_taxonomy() To register the taxonomy
811 */
812 public function register_taxonomies() {
813
814 // Topic tag labels
815 $topic_tag['labels'] = array(
816 'name' => __( 'Topic Tags', 'bbpress' ),
817 'singular_name' => __( 'Topic Tag', 'bbpress' ),
818 'search_items' => __( 'Search Tags', 'bbpress' ),
819 'popular_items' => __( 'Popular Tags', 'bbpress' ),
820 'all_items' => __( 'All Tags', 'bbpress' ),
821 'edit_item' => __( 'Edit Tag', 'bbpress' ),
822 'update_item' => __( 'Update Tag', 'bbpress' ),
823 'add_new_item' => __( 'Add New Tag', 'bbpress' ),
824 'new_item_name' => __( 'New Tag Name', 'bbpress' ),
825 'view_item' => __( 'View Topic Tag', 'bbpress' )
826 );
827
828 // Topic tag rewrite
829 $topic_tag['rewrite'] = array(
830 'slug' => $this->topic_tag_slug,
831 'with_front' => false
832 );
833
834 // Topic tag filter
835 $bbp_tt = apply_filters( 'bbp_register_topic_taxonomy', array(
836 'labels' => $topic_tag['labels'],
837 'rewrite' => $topic_tag['rewrite'],
838 'capabilities' => bbp_get_topic_tag_caps(),
839 'update_count_callback' => '_update_post_term_count',
840 'query_var' => true,
841 'show_tagcloud' => true,
842 'hierarchical' => false,
843 'public' => true,
844 'show_ui' => true
845 ) );
846
847 // Register the topic tag taxonomy
848 register_taxonomy(
849 $this->topic_tag_tax_id, // The topic tag id
850 $this->topic_post_type, // The topic post type
851 $bbp_tt
852 );
853 }
854
855 /**
856 * Register the bbPress views
857 *
858 * @since bbPress (r2789)
859 *
860 * @uses bbp_register_view() To register the views
861 */
862 public function register_views() {
863
864 // Topics with no replies
865 $no_replies = apply_filters( 'bbp_register_view_no_replies', array(
866 'meta_key' => '_bbp_reply_count',
867 'meta_value' => 1,
868 'meta_compare' => '<',
869 'orderby' => ''
870 ) );
871
872 bbp_register_view( 'no-replies', __( 'Topics with no replies', 'bbpress' ), $no_replies );
873 }
874
875 /**
876 * Setup the currently logged-in user
877 *
878 * Do not to call this prematurely, I.E. before the 'init' action has
879 * started. This function is naturally hooked into 'init' to ensure proper
880 * execution. get_currentuserinfo() is used to check for XMLRPC_REQUEST to
881 * avoid xmlrpc errors.
882 *
883 * @since bbPress (r2697)
884 *
885 * @uses wp_get_current_user()
886 */
887 public function setup_current_user() {
888 $this->current_user = &wp_get_current_user();
889 }
890
891 /**
892 * Add the bbPress-specific rewrite tags
893 *
894 * @since bbPress (r2753)
895 *
896 * @uses add_rewrite_tag() To add the rewrite tags
897 */
898 public function add_rewrite_tags() {
899
900 // Pad attributes
901 $pad = 2;
902 $wrapper = '%';
903
904 // Setup the tags
905 $bbp_user = str_pad( $this->user_id, strlen( $this->user_id ) + $pad, $wrapper, STR_PAD_BOTH );
906 $bbp_view = str_pad( $this->view_id, strlen( $this->view_id ) + $pad, $wrapper, STR_PAD_BOTH );
907 $bbp_edit = str_pad( $this->edit_id, strlen( $this->edit_id ) + $pad, $wrapper, STR_PAD_BOTH );
908
909 // User Profile tag
910 add_rewrite_tag( $bbp_user, '([^/]+)' );
911
912 // View Page tag
913 add_rewrite_tag( $bbp_view, '([^/]+)' );
914
915 // Edit Page tag
916 add_rewrite_tag( $bbp_edit, '([1]{1,})' );
917 }
918
919 /**
920 * Register bbPress-specific rewrite rules
921 *
922 * @since bbPress (r2688)
923 *
924 * @param WP_Rewrite $wp_rewrite bbPress-sepecific rules are appended in
925 * $wp_rewrite->rules
926 */
927 public function generate_rewrite_rules( $wp_rewrite ) {
928
929 // New rules to merge with existing
930 $bbp_rules = array(
931
932 // Edit Topic/Reply
933 $this->topic_slug . '/([^/]+)/edit/?$' => 'index.php?' . $this->topic_post_type . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
934 $this->reply_slug . '/([^/]+)/edit/?$' => 'index.php?' . $this->reply_post_type . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
935
936 // Edit Topic Tag
937 $this->topic_tag_slug . '/([^/]+)/edit/?$' => 'index.php?' . $this->topic_tag_tax_id . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
938
939 // Profile Page
940 $this->user_slug . '/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?' . $this->user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
941 $this->user_slug . '/([^/]+)/?$' => 'index.php?' . $this->user_id . '=' . $wp_rewrite->preg_index( 1 ),
942 $this->user_slug . '/([^/]+)/edit/?$' => 'index.php?' . $this->user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
943
944 // View Page
945 $this->view_slug . '/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?' . $this->view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
946 $this->view_slug . '/([^/]+)/?$' => 'index.php?' . $this->view_id . '=' . $wp_rewrite->preg_index( 1 )
947 );
948
949 // Merge bbPress rules with existing
950 $wp_rewrite->rules = array_merge( $bbp_rules, $wp_rewrite->rules );
951
952 // Return merged rules
953 return $wp_rewrite;
954 }
955 }
956
957 // "And now here's something we hope you'll really like!"
958 $GLOBALS['bbp'] = new bbPress();
959
960 endif; // class_exists check
961
962 ?>
963