PluginProbe
bbPress / 2.0-beta-3
bbPress v2.0-beta-3
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
bbpress / bbpress.php

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

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