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

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