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

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