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

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