PluginProbe
bbPress / 2.1-rc2
bbPress v2.1-rc2
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 2.2.2 All 71 releases
bbpress / bbpress.php

bbpress.php in bbPress 2.1-rc2, at bbpress.php

917 lines 33.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 * $Id: bbpress.php 4021 2012-06-27 21:28:12Z johnjamesjacoby $
9 *
10 * @package bbPress
11 * @subpackage Main
12 */
13
14 /**
15 * Plugin Name: bbPress
16 * Plugin URI: http://bbpress.org
17 * Description: bbPress is forum software with a twist from the creators of WordPress.
18 * Author: The bbPress Community
19 * Author URI: http://bbpress.org
20 * Version: 2.1-rc2
21 * Text Domain: bbpress
22 * Domain Path: /bbp-languages/
23 */
24
25 // Exit if accessed directly
26 if ( !defined( 'ABSPATH' ) ) exit;
27
28 if ( !class_exists( 'bbPress' ) ) :
29 /**
30 * Main bbPress Class
31 *
32 * Tap tap tap... Is this thing on?
33 *
34 * @since bbPress (r2464)
35 */
36 final class bbPress {
37
38 /** Magic *****************************************************************/
39
40 /**
41 * bbPress uses many variables, most of which can be filtered to customize
42 * the way that it works. To prevent unauthorized access, these variables
43 * are stored in a private array that is magically updated using PHP 5.2+
44 * methods. This is to prevent third party plugins from tampering with
45 * essential information indirectly, which would cause issues later.
46 *
47 * @see bbPress::setup_globals()
48 * @var array
49 */
50 private $data;
51
52 /** Not Magic *************************************************************/
53
54 /**
55 * @var mixed False when not logged in; WP_User object when logged in
56 */
57 public $current_user = false;
58
59 /**
60 * @var obj Add-ons append to this (Akismet, BuddyPress, etc...)
61 */
62 public $extend;
63
64 /**
65 * @var array Topic views
66 */
67 public $views = array();
68
69 /**
70 * @var array Overloads get_option()
71 */
72 public $options = array();
73
74 /**
75 * @var array Overloads get_user_meta()
76 */
77 public $user_options = array();
78
79 /** Singleton *************************************************************/
80
81 /**
82 * @var bbPress The one true bbPress
83 */
84 private static $instance;
85
86 /**
87 * Main bbPress Instance
88 *
89 * bbPress is fun
90 * Please load it only one time
91 * For this, we thank you
92 *
93 * Insures that only one instance of bbPress exists in memory at any one
94 * time. Also prevents needing to define globals all over the place.
95 *
96 * @since bbPress (r3757)
97 * @staticvar array $instance
98 * @uses bbPress::setup_globals() Setup the globals needed
99 * @uses bbPress::includes() Include the required files
100 * @uses bbPress::setup_actions() Setup the hooks and actions
101 * @see bbpress()
102 * @return The one true bbPress
103 */
104 public static function instance() {
105 if ( ! isset( self::$instance ) ) {
106 self::$instance = new bbPress;
107 self::$instance->setup_globals();
108 self::$instance->includes();
109 self::$instance->setup_actions();
110 }
111 return self::$instance;
112 }
113
114 /** Magic Methods *********************************************************/
115
116 /**
117 * A dummy constructor to prevent bbPress from being loaded more than once.
118 *
119 * @since bbPress (r2464)
120 * @see bbPress::instance()
121 * @see bbpress();
122 */
123 private function __construct() { /* Do nothing here */ }
124
125 /**
126 * A dummy magic method to prevent bbPress from being cloned
127 *
128 * @since bbPress (r2464)
129 */
130 public function __clone() { wp_die( __( 'Cheatin&#8217; huh?', 'bbpress' ) ); }
131
132 /**
133 * A dummy magic method to prevent bbPress from being unserialized
134 *
135 * @since bbPress (r2464)
136 */
137 public function __wakeup() { wp_die( __( 'Cheatin&#8217; huh?', 'bbpress' ) ); }
138
139 /**
140 * Magic method for checking the existence of a certain custom field
141 *
142 * @since bbPress (r3951)
143 */
144 public function __isset( $key ) { return isset( $this->data[$key] ); }
145
146 /**
147 * Magic method for getting bbPress varibles
148 *
149 * @since bbPress (r3951)
150 */
151 public function __get( $key ) { return isset( $this->data[$key] ) ? $this->data[$key] : null; }
152
153 /**
154 * Magic method for setting bbPress varibles
155 *
156 * @since bbPress (r3951)
157 */
158 public function __set( $key, $value ) { $this->data[$key] = $value; }
159
160 /** Private Methods *******************************************************/
161
162 /**
163 * Set some smart defaults to class variables. Allow some of them to be
164 * filtered to allow for early overriding.
165 *
166 * @since bbPress (r2626)
167 * @access private
168 * @uses plugin_dir_path() To generate bbPress plugin path
169 * @uses plugin_dir_url() To generate bbPress plugin url
170 * @uses apply_filters() Calls various filters
171 */
172 private function setup_globals() {
173
174 /** Versions **********************************************************/
175
176 $this->version = '2.1-rc2'; // bbPress version
177 $this->db_version = '203'; // bbPress DB version
178
179 /** Paths *************************************************************/
180
181 // Setup some base path and URL information
182 $this->file = __FILE__;
183 $this->basename = apply_filters( 'bbp_plugin_basenname', plugin_basename( $this->file ) );
184 $this->plugin_dir = apply_filters( 'bbp_plugin_dir_path', plugin_dir_path( $this->file ) );
185 $this->plugin_url = apply_filters( 'bbp_plugin_dir_url', plugin_dir_url ( $this->file ) );
186
187 // Themes
188 $this->themes_dir = apply_filters( 'bbp_themes_dir', trailingslashit( $this->plugin_dir . 'bbp-themes' ) );
189 $this->themes_url = apply_filters( 'bbp_themes_url', trailingslashit( $this->plugin_url . 'bbp-themes' ) );
190
191 // Languages
192 $this->lang_dir = apply_filters( 'bbp_lang_dir', trailingslashit( $this->plugin_dir . 'bbp-languages' ) );
193
194 /** Identifiers *******************************************************/
195
196 // Post type identifiers
197 $this->forum_post_type = apply_filters( 'bbp_forum_post_type', 'forum' );
198 $this->topic_post_type = apply_filters( 'bbp_topic_post_type', 'topic' );
199 $this->reply_post_type = apply_filters( 'bbp_reply_post_type', 'reply' );
200 $this->topic_tag_tax_id = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' );
201
202 // Status identifiers
203 $this->spam_status_id = apply_filters( 'bbp_spam_post_status', 'spam' );
204 $this->closed_status_id = apply_filters( 'bbp_closed_post_status', 'closed' );
205 $this->orphan_status_id = apply_filters( 'bbp_orphan_post_status', 'orphan' );
206 $this->public_status_id = apply_filters( 'bbp_public_post_status', 'publish' );
207 $this->pending_status_id = apply_filters( 'bbp_pending_post_status', 'pending' );
208 $this->private_status_id = apply_filters( 'bbp_private_post_status', 'private' );
209 $this->hidden_status_id = apply_filters( 'bbp_hidden_post_status', 'hidden' );
210 $this->trash_status_id = apply_filters( 'bbp_trash_post_status', 'trash' );
211
212 // Other identifiers
213 $this->user_id = apply_filters( 'bbp_user_id', 'bbp_user' );
214 $this->view_id = apply_filters( 'bbp_view_id', 'bbp_view' );
215 $this->edit_id = apply_filters( 'bbp_edit_id', 'edit' );
216
217 /** Queries ***********************************************************/
218
219 $this->current_forum_id = 0; // Current forum id
220 $this->current_topic_id = 0; // Current topic id
221 $this->current_reply_id = 0; // Current reply id
222 $this->current_topic_tag_id = 0; // Current topic tag id
223
224 $this->forum_query = new stdClass; // Main forum query
225 $this->topic_query = new stdClass; // Main topic query
226 $this->reply_query = new stdClass; // Main reply query
227
228 /** Theme Compat ******************************************************/
229
230 $this->theme_compat = new stdClass(); // Base theme compatibility class
231 $this->filters = new stdClass(); // Used when adding/removing filters
232
233 /** Users *************************************************************/
234
235 $this->current_user = new stdClass(); // Currently logged in user
236 $this->displayed_user = new stdClass(); // Currently displayed user
237
238 /** Misc **************************************************************/
239
240 $this->extend = new stdClass(); // Plugins add data here
241 $this->errors = new WP_Error(); // Feedback
242 $this->tab_index = apply_filters( 'bbp_default_tab_index', 100 );
243
244 /** Cache *************************************************************/
245
246 // Add bbPress to global cache groups
247 wp_cache_add_global_groups( 'bbpress' );
248 }
249
250 /**
251 * Include required files
252 *
253 * @since bbPress (r2626)
254 * @access private
255 * @todo Be smarter about conditionally loading code
256 * @uses is_admin() If in WordPress admin, load additional file
257 */
258 private function includes() {
259
260 /** Core **************************************************************/
261
262 require( $this->plugin_dir . 'bbp-includes/bbp-core-cache.php' ); // Cache helpers
263 require( $this->plugin_dir . 'bbp-includes/bbp-core-actions.php' ); // All actions
264 require( $this->plugin_dir . 'bbp-includes/bbp-core-filters.php' ); // All filters
265 require( $this->plugin_dir . 'bbp-includes/bbp-core-functions.php' ); // Core functions
266 require( $this->plugin_dir . 'bbp-includes/bbp-core-options.php' ); // Configuration options
267 require( $this->plugin_dir . 'bbp-includes/bbp-core-caps.php' ); // Roles and capabilities
268 require( $this->plugin_dir . 'bbp-includes/bbp-core-classes.php' ); // Common classes
269 require( $this->plugin_dir . 'bbp-includes/bbp-core-widgets.php' ); // Sidebar widgets
270 require( $this->plugin_dir . 'bbp-includes/bbp-core-shortcodes.php' ); // Shortcodes for use with pages and posts
271 require( $this->plugin_dir . 'bbp-includes/bbp-core-update.php' ); // Database updater
272
273 /** Templates *********************************************************/
274
275 require( $this->plugin_dir . 'bbp-includes/bbp-template-functions.php' ); // Template functions
276 require( $this->plugin_dir . 'bbp-includes/bbp-template-loader.php' ); // Template loader
277 require( $this->plugin_dir . 'bbp-includes/bbp-theme-compatibility.php' ); // Theme compatibility for existing themes
278
279 /** Extensions ********************************************************/
280
281 require( $this->plugin_dir . 'bbp-includes/bbp-extend-akismet.php' ); // Spam prevention for topics and replies
282
283 /**
284 * BuddyPress extension is loaded in bbp-core-hooks.php
285 *
286 * @since bbPress (r3559)
287 */
288
289 /** Components ********************************************************/
290
291 require( $this->plugin_dir . 'bbp-includes/bbp-common-functions.php' ); // Common functions
292 require( $this->plugin_dir . 'bbp-includes/bbp-common-template.php' ); // Common template tags
293
294 require( $this->plugin_dir . 'bbp-includes/bbp-forum-functions.php' ); // Forum functions
295 require( $this->plugin_dir . 'bbp-includes/bbp-forum-template.php' ); // Forum template tags
296
297 require( $this->plugin_dir . 'bbp-includes/bbp-topic-functions.php' ); // Topic functions
298 require( $this->plugin_dir . 'bbp-includes/bbp-topic-template.php' ); // Topic template tags
299
300 require( $this->plugin_dir . 'bbp-includes/bbp-reply-functions.php' ); // Reply functions
301 require( $this->plugin_dir . 'bbp-includes/bbp-reply-template.php' ); // Reply template tags
302
303 require( $this->plugin_dir . 'bbp-includes/bbp-user-functions.php' ); // User functions
304 require( $this->plugin_dir . 'bbp-includes/bbp-user-template.php' ); // User template tags
305 require( $this->plugin_dir . 'bbp-includes/bbp-user-options.php' ); // User options
306
307 /** Admin *************************************************************/
308
309 // Quick admin check and load if needed
310 if ( is_admin() ) {
311 require( $this->plugin_dir . 'bbp-admin/bbp-admin.php' );
312 require( $this->plugin_dir . 'bbp-admin/bbp-actions.php' );
313 }
314 }
315
316 /**
317 * Setup the default hooks and actions
318 *
319 * @since bbPress (r2644)
320 * @access private
321 * @todo Not use bbp_is_deactivation()
322 * @uses register_activation_hook() To register the activation hook
323 * @uses register_deactivation_hook() To register the deactivation hook
324 * @uses add_action() To add various actions
325 */
326 private function setup_actions() {
327
328 // Add actions to plugin activation and deactivation hooks
329 add_action( 'activate_' . $this->basename, 'bbp_activation' );
330 add_action( 'deactivate_' . $this->basename, 'bbp_deactivation' );
331
332 // If bbPress is being deactivated, do not add any actions
333 if ( bbp_is_deactivation( $this->basename ) )
334 return;
335
336 // Array of bbPress core actions
337 $actions = array(
338 'setup_theme', // Setup the default theme compat
339 'setup_current_user', // Setup currently logged in user
340 'register_post_types', // Register post types (forum|topic|reply)
341 'register_post_statuses', // Register post statuses (closed|spam|orphan|hidden)
342 'register_taxonomies', // Register taxonomies (topic-tag)
343 'register_views', // Register the views (no-replies)
344 'register_theme_directory', // Register the theme directory (bbp-themes)
345 'register_theme_packages', // Register bundled theme packages (bbp-theme-compat/bbp-themes)
346 'load_textdomain', // Load textdomain (bbpress)
347 'add_rewrite_tags', // Add rewrite tags (view|user|edit)
348 'generate_rewrite_rules' // Generate rewrite rules (view|edit)
349 );
350
351 // Add the actions
352 foreach( $actions as $class_action )
353 add_action( 'bbp_' . $class_action, array( $this, $class_action ), 5 );
354
355 // All bbPress actions are setup (includes bbp-core-hooks.php)
356 do_action_ref_array( 'bbp_after_setup_actions', array( &$this ) );
357 }
358
359 /** Public Methods ********************************************************/
360
361 /**
362 * Register bundled theme packages
363 *
364 * Note that since we currently have complete control over bbp-themes and
365 * the bbp-theme-compat folders, it's fine to hardcode these here. If at a
366 * later date we need to automate this, and API will need to be built.
367 *
368 * @since bbPress (r3829)
369 */
370 public function register_theme_packages() {
371
372 /** Default Theme *****************************************************/
373
374 bbp_register_theme_package( array(
375 'id' => 'default',
376 'name' => __( 'bbPress Default', 'bbpress' ),
377 'version' => bbp_get_version(),
378 'dir' => trailingslashit( $this->plugin_dir . 'bbp-theme-compat' ),
379 'url' => trailingslashit( $this->plugin_url . 'bbp-theme-compat' )
380 ) );
381
382 /** Twenty Ten ********************************************************/
383
384 bbp_register_theme_package( array(
385 'id' => 'bbp-twentyten',
386 'name' => __( 'Twenty Ten (bbPress)', 'bbpress' ),
387 'version' => bbp_get_version(),
388 'dir' => trailingslashit( $this->themes_dir . 'bbp-twentyten' ),
389 'url' => trailingslashit( $this->themes_url . 'bbp-twentyten' )
390 ) );
391 }
392
393 /**
394 * Setup the default bbPress theme compatability location.
395 *
396 * @since bbPress (r3778)
397 */
398 public function setup_theme() {
399
400 // Bail if something already has this under control
401 if ( ! empty( $this->theme_compat->theme ) )
402 return;
403
404 // Setup the theme package to use for compatibility
405 bbp_setup_theme_compat( bbp_get_theme_package_id() );
406 }
407
408 /**
409 * Load the translation file for current language. Checks the languages
410 * folder inside the bbPress plugin first, and then the default WordPress
411 * languages folder.
412 *
413 * Note that custom translation files inside the bbPress plugin folder
414 * will be removed on bbPress updates. If you're creating custom
415 * translation files, please use the global language folder.
416 *
417 * @since bbPress (r2596)
418 *
419 * @uses apply_filters() Calls 'bbpress_locale' with the
420 * {@link get_locale()} value
421 * @uses load_textdomain() To load the textdomain
422 * @return bool True on success, false on failure
423 */
424 public function load_textdomain() {
425 $locale = get_locale(); // Default locale
426 $locale = apply_filters( 'plugin_locale', $locale, 'bbpress' ); // Traditional WordPress plugin locale filter
427 $locale = apply_filters( 'bbpress_locale', $locale ); // bbPress specific locale filter
428 $mofile = sprintf( 'bbpress-%s.mo', $locale ); // Get mo file name
429
430 // Setup paths to current locale file
431 $mofile_local = $this->lang_dir . $mofile;
432 $mofile_global = WP_LANG_DIR . '/bbpress/' . $mofile;
433
434 // Look in local /wp-content/plugins/bbpress/bbp-languages/ folder
435 if ( file_exists( $mofile_local ) ) {
436 return load_textdomain( 'bbpress', $mofile_local );
437
438 // Look in global /wp-content/languages/bbpress folder
439 } elseif ( file_exists( $mofile_global ) ) {
440 return load_textdomain( 'bbpress', $mofile_global );
441 }
442
443 // Nothing found
444 return false;
445 }
446
447 /**
448 * Sets up the bbPress theme directory to use in WordPress
449 *
450 * @since bbPress (r2507)
451 * @uses register_theme_directory() To register the theme directory
452 * @return bool True on success, false on failure
453 */
454 public function register_theme_directory() {
455 return register_theme_directory( $this->themes_dir );
456 }
457
458 /**
459 * Setup the post types for forums, topics and replies
460 *
461 * @since bbPress (r2597)
462 * @uses register_post_type() To register the post types
463 * @uses apply_filters() Calls various filters to modify the arguments
464 * sent to register_post_type()
465 */
466 public static function register_post_types() {
467
468 // Define local variable(s)
469 $post_type = array();
470
471 /** Forums ************************************************************/
472
473 // Forum labels
474 $post_type['labels'] = array(
475 'name' => __( 'Forums', 'bbpress' ),
476 'menu_name' => __( 'Forums', 'bbpress' ),
477 'singular_name' => __( 'Forum', 'bbpress' ),
478 'all_items' => __( 'All Forums', 'bbpress' ),
479 'add_new' => __( 'New Forum', 'bbpress' ),
480 'add_new_item' => __( 'Create New Forum', 'bbpress' ),
481 'edit' => __( 'Edit', 'bbpress' ),
482 'edit_item' => __( 'Edit Forum', 'bbpress' ),
483 'new_item' => __( 'New Forum', 'bbpress' ),
484 'view' => __( 'View Forum', 'bbpress' ),
485 'view_item' => __( 'View Forum', 'bbpress' ),
486 'search_items' => __( 'Search Forums', 'bbpress' ),
487 'not_found' => __( 'No forums found', 'bbpress' ),
488 'not_found_in_trash' => __( 'No forums found in Trash', 'bbpress' ),
489 'parent_item_colon' => __( 'Parent Forum:', 'bbpress' )
490 );
491
492 // Forum rewrite
493 $post_type['rewrite'] = array(
494 'slug' => bbp_get_forum_slug(),
495 'with_front' => false
496 );
497
498 // Forum supports
499 $post_type['supports'] = array(
500 'title',
501 'editor',
502 'revisions'
503 );
504
505 // Register Forum content type
506 register_post_type(
507 bbp_get_forum_post_type(),
508 apply_filters( 'bbp_register_forum_post_type', array(
509 'labels' => $post_type['labels'],
510 'rewrite' => $post_type['rewrite'],
511 'supports' => $post_type['supports'],
512 'description' => __( 'bbPress Forums', 'bbpress' ),
513 'capabilities' => bbp_get_forum_caps(),
514 'capability_type' => array( 'forum', 'forums' ),
515 'menu_position' => 56,
516 'has_archive' => bbp_get_root_slug(),
517 'exclude_from_search' => true,
518 'show_in_nav_menus' => true,
519 'public' => true,
520 'show_ui' => bbp_current_user_can_see( bbp_get_forum_post_type() ),
521 'can_export' => true,
522 'hierarchical' => true,
523 'query_var' => true,
524 'menu_icon' => ''
525 ) )
526 );
527
528 /** Topics ************************************************************/
529
530 // Topic labels
531 $post_type['labels'] = array(
532 'name' => __( 'Topics', 'bbpress' ),
533 'menu_name' => __( 'Topics', 'bbpress' ),
534 'singular_name' => __( 'Topic', 'bbpress' ),
535 'all_items' => __( 'All Topics', 'bbpress' ),
536 'add_new' => __( 'New Topic', 'bbpress' ),
537 'add_new_item' => __( 'Create New Topic', 'bbpress' ),
538 'edit' => __( 'Edit', 'bbpress' ),
539 'edit_item' => __( 'Edit Topic', 'bbpress' ),
540 'new_item' => __( 'New Topic', 'bbpress' ),
541 'view' => __( 'View Topic', 'bbpress' ),
542 'view_item' => __( 'View Topic', 'bbpress' ),
543 'search_items' => __( 'Search Topics', 'bbpress' ),
544 'not_found' => __( 'No topics found', 'bbpress' ),
545 'not_found_in_trash' => __( 'No topics found in Trash', 'bbpress' ),
546 'parent_item_colon' => __( 'Forum:', 'bbpress' )
547 );
548
549 // Topic rewrite
550 $post_type['rewrite'] = array(
551 'slug' => bbp_get_topic_slug(),
552 'with_front' => false
553 );
554
555 // Topic supports
556 $post_type['supports'] = array(
557 'title',
558 'editor',
559 'revisions'
560 );
561
562 // Register Topic content type
563 register_post_type(
564 bbp_get_topic_post_type(),
565 apply_filters( 'bbp_register_topic_post_type', array(
566 'labels' => $post_type['labels'],
567 'rewrite' => $post_type['rewrite'],
568 'supports' => $post_type['supports'],
569 'description' => __( 'bbPress Topics', 'bbpress' ),
570 'capabilities' => bbp_get_topic_caps(),
571 'capability_type' => array( 'topic', 'topics' ),
572 'menu_position' => 57,
573 'has_archive' => bbp_get_topic_archive_slug(),
574 'exclude_from_search' => true,
575 'show_in_nav_menus' => false,
576 'public' => true,
577 'show_ui' => bbp_current_user_can_see( bbp_get_topic_post_type() ),
578 'can_export' => true,
579 'hierarchical' => false,
580 'query_var' => true,
581 'menu_icon' => ''
582 )
583 ) );
584
585 /** Replies ***********************************************************/
586
587 // Reply labels
588 $post_type['labels'] = array(
589 'name' => __( 'Replies', 'bbpress' ),
590 'menu_name' => __( 'Replies', 'bbpress' ),
591 'singular_name' => __( 'Reply', 'bbpress' ),
592 'all_items' => __( 'All Replies', 'bbpress' ),
593 'add_new' => __( 'New Reply', 'bbpress' ),
594 'add_new_item' => __( 'Create New Reply', 'bbpress' ),
595 'edit' => __( 'Edit', 'bbpress' ),
596 'edit_item' => __( 'Edit Reply', 'bbpress' ),
597 'new_item' => __( 'New Reply', 'bbpress' ),
598 'view' => __( 'View Reply', 'bbpress' ),
599 'view_item' => __( 'View Reply', 'bbpress' ),
600 'search_items' => __( 'Search Replies', 'bbpress' ),
601 'not_found' => __( 'No replies found', 'bbpress' ),
602 'not_found_in_trash' => __( 'No replies found in Trash', 'bbpress' ),
603 'parent_item_colon' => __( 'Topic:', 'bbpress' )
604 );
605
606 // Reply rewrite
607 $post_type['rewrite'] = array(
608 'slug' => bbp_get_reply_slug(),
609 'with_front' => false
610 );
611
612 // Reply supports
613 $post_type['supports'] = array(
614 'title',
615 'editor',
616 'revisions'
617 );
618
619 // Register reply content type
620 register_post_type(
621 bbp_get_reply_post_type(),
622 apply_filters( 'bbp_register_reply_post_type', array(
623 'labels' => $post_type['labels'],
624 'rewrite' => $post_type['rewrite'],
625 'supports' => $post_type['supports'],
626 'description' => __( 'bbPress Replies', 'bbpress' ),
627 'capabilities' => bbp_get_reply_caps(),
628 'capability_type' => array( 'reply', 'replies' ),
629 'menu_position' => 58,
630 'exclude_from_search' => true,
631 'has_archive' => false,
632 'show_in_nav_menus' => false,
633 'public' => true,
634 'show_ui' => bbp_current_user_can_see( bbp_get_reply_post_type() ),
635 'can_export' => true,
636 'hierarchical' => false,
637 'query_var' => true,
638 'menu_icon' => ''
639 ) )
640 );
641 }
642
643 /**
644 * Register the post statuses used by bbPress
645 *
646 * We do some manipulation of the 'trash' status so trashed topics and
647 * replies can be viewed from within the theme.
648 *
649 * @since bbPress (r2727)
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 public static function register_post_statuses() {
656
657 // Closed
658 register_post_status(
659 bbp_get_closed_status_id(),
660 apply_filters( 'bbp_register_closed_post_status', array(
661 'label' => _x( 'Closed', 'post', 'bbpress' ),
662 'label_count' => _nx_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'bbpress' ),
663 'public' => true,
664 'show_in_admin_all' => true
665 ) )
666 );
667
668 // Spam
669 register_post_status(
670 bbp_get_spam_status_id(),
671 apply_filters( 'bbp_register_spam_post_status', array(
672 'label' => _x( 'Spam', 'post', 'bbpress' ),
673 'label_count' => _nx_noop( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'bbpress' ),
674 'protected' => true,
675 'exclude_from_search' => true,
676 'show_in_admin_status_list' => true,
677 'show_in_admin_all_list' => false
678 ) )
679 );
680
681 // Orphan
682 register_post_status(
683 bbp_get_orphan_status_id(),
684 apply_filters( 'bbp_register_orphan_post_status', array(
685 'label' => _x( 'Orphan', 'post', 'bbpress' ),
686 'label_count' => _nx_noop( 'Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'bbpress' ),
687 'protected' => true,
688 'exclude_from_search' => true,
689 'show_in_admin_status_list' => true,
690 'show_in_admin_all_list' => false
691 ) )
692 );
693
694 // Hidden
695 register_post_status(
696 bbp_get_hidden_status_id(),
697 apply_filters( 'bbp_register_hidden_post_status', array(
698 'label' => _x( 'Hidden', 'post', 'bbpress' ),
699 'label_count' => _nx_noop( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'bbpress' ),
700 'private' => true,
701 'exclude_from_search' => true,
702 'show_in_admin_status_list' => true,
703 'show_in_admin_all_list' => true
704 ) )
705 );
706
707 /**
708 * Trash fix
709 *
710 * We need to remove the internal arg and change that to
711 * protected so that the users with 'view_trash' cap can view
712 * single trashed topics/replies in the front-end as wp_query
713 * doesn't allow any hack for the trashed topics to be viewed.
714 */
715 global $wp_post_statuses;
716
717 if ( !empty( $wp_post_statuses['trash'] ) ) {
718
719 // User can view trash so set internal to false
720 if ( current_user_can( 'view_trash' ) ) {
721 $wp_post_statuses['trash']->internal = false;
722 $wp_post_statuses['trash']->protected = true;
723
724 // User cannot view trash so set internal to true
725 } elseif ( !current_user_can( 'view_trash' ) ) {
726 $wp_post_statuses['trash']->internal = true;
727 }
728 }
729 }
730
731 /**
732 * Register the topic tag taxonomy
733 *
734 * @since bbPress (r2464)
735 * @uses register_taxonomy() To register the taxonomy
736 */
737 public static function register_taxonomies() {
738
739 // Define local variable(s)
740 $topic_tag = array();
741
742 // Topic tag labels
743 $topic_tag['labels'] = array(
744 'name' => __( 'Topic Tags', 'bbpress' ),
745 'singular_name' => __( 'Topic Tag', 'bbpress' ),
746 'search_items' => __( 'Search Tags', 'bbpress' ),
747 'popular_items' => __( 'Popular Tags', 'bbpress' ),
748 'all_items' => __( 'All Tags', 'bbpress' ),
749 'edit_item' => __( 'Edit Tag', 'bbpress' ),
750 'update_item' => __( 'Update Tag', 'bbpress' ),
751 'add_new_item' => __( 'Add New Tag', 'bbpress' ),
752 'new_item_name' => __( 'New Tag Name', 'bbpress' ),
753 'view_item' => __( 'View Topic Tag', 'bbpress' )
754 );
755
756 // Topic tag rewrite
757 $topic_tag['rewrite'] = array(
758 'slug' => bbp_get_topic_tag_tax_slug(),
759 'with_front' => false
760 );
761
762 // Register the topic tag taxonomy
763 register_taxonomy(
764 bbp_get_topic_tag_tax_id(),
765 bbp_get_topic_post_type(),
766 apply_filters( 'bbp_register_topic_taxonomy', array(
767 'labels' => $topic_tag['labels'],
768 'rewrite' => $topic_tag['rewrite'],
769 'capabilities' => bbp_get_topic_tag_caps(),
770 'update_count_callback' => '_update_post_term_count',
771 'query_var' => true,
772 'show_tagcloud' => true,
773 'hierarchical' => false,
774 'public' => true,
775 'show_ui' => bbp_current_user_can_see( bbp_get_topic_tag_tax_id() )
776 )
777 ) );
778 }
779
780 /**
781 * Register the bbPress views
782 *
783 * @since bbPress (r2789)
784 * @uses bbp_register_view() To register the views
785 */
786 public static function register_views() {
787
788 // Topics with no replies
789 bbp_register_view(
790 'no-replies',
791 __( 'Topics with no replies', 'bbpress' ),
792 apply_filters( 'bbp_register_view_no_replies', array(
793 'meta_key' => '_bbp_reply_count',
794 'meta_value' => 1,
795 'meta_compare' => '<',
796 'orderby' => ''
797 )
798 ) );
799 }
800
801 /**
802 * Setup the currently logged-in user
803 *
804 * Do not to call this prematurely, I.E. before the 'init' action has
805 * started. This function is naturally hooked into 'init' to ensure proper
806 * execution. get_currentuserinfo() is used to check for XMLRPC_REQUEST to
807 * avoid xmlrpc errors.
808 *
809 * @since bbPress (r2697)
810 * @uses wp_get_current_user()
811 */
812 public function setup_current_user() {
813 $this->current_user = &wp_get_current_user();
814 }
815
816 /** Custom Rewrite Rules **************************************************/
817
818 /**
819 * Add the bbPress-specific rewrite tags
820 *
821 * @since bbPress (r2753)
822 * @uses add_rewrite_tag() To add the rewrite tags
823 */
824 public static function add_rewrite_tags() {
825 add_rewrite_tag( '%%' . bbp_get_user_rewrite_id() . '%%', '([^/]+)' ); // User Profile tag
826 add_rewrite_tag( '%%' . bbp_get_view_rewrite_id() . '%%', '([^/]+)' ); // View Page tag
827 add_rewrite_tag( '%%' . bbp_get_edit_rewrite_id() . '%%', '([1]{1,})' ); // Edit Page tag
828 }
829
830 /**
831 * Register bbPress-specific rewrite rules for uri's that are not
832 * setup for us by way of custom post types or taxonomies. This includes:
833 * - Front-end editing
834 * - Topic views
835 * - User profiles
836 *
837 * @since bbPress (r2688)
838 * @param WP_Rewrite $wp_rewrite bbPress-sepecific rules are appended in
839 * $wp_rewrite->rules
840 */
841 public static function generate_rewrite_rules( $wp_rewrite ) {
842
843 // Slugs
844 $user_slug = bbp_get_user_slug();
845 $view_slug = bbp_get_view_slug();
846
847 // Unique rewrite ID's
848 $user_id = bbp_get_user_rewrite_id();
849 $view_id = bbp_get_view_rewrite_id();
850 $edit_id = bbp_get_edit_rewrite_id();
851
852 // Rewrite rule matches used repeatedly below
853 $root_rule = '/([^/]+)/?$';
854 $edit_rule = '/([^/]+)/edit/?$';
855 $feed_rule = '/([^/]+)/feed/?$';
856 $page_rule = '/([^/]+)/page/?([0-9]{1,})/?$';
857
858 // New bbPress specific rules to merge with existing that are not
859 // handled automatically by custom post types or taxonomy types
860 $bbp_rules = array(
861
862 // Edit Forum|Topic|Reply|Topic-tag
863 bbp_get_forum_slug() . $edit_rule => 'index.php?' . bbp_get_forum_post_type() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
864 bbp_get_topic_slug() . $edit_rule => 'index.php?' . bbp_get_topic_post_type() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
865 bbp_get_reply_slug() . $edit_rule => 'index.php?' . bbp_get_reply_post_type() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
866 bbp_get_topic_tag_tax_slug() . $edit_rule => 'index.php?' . bbp_get_topic_tag_tax_id() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
867
868 // User Pagination|Edit|View
869 $user_slug . $page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
870 $user_slug . $edit_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
871 $user_slug . $root_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ),
872
873 // Topic-View Pagination|Feed|View
874 $view_slug . $page_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
875 $view_slug . $feed_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&feed=' . $wp_rewrite->preg_index( 2 ),
876 $view_slug . $root_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ),
877 );
878
879 // Merge bbPress rules with existing
880 $wp_rewrite->rules = array_merge( $bbp_rules, $wp_rewrite->rules );
881
882 // Return merged rules
883 return $wp_rewrite;
884 }
885 }
886
887 /**
888 * The main function responsible for returning the one true bbPress Instance
889 * to functions everywhere.
890 *
891 * Use this function like you would a global variable, except without needing
892 * to declare the global.
893 *
894 * Example: <?php $bbp = bbpress(); ?>
895 *
896 * @return The one true bbPress Instance
897 */
898 function bbpress() {
899 return bbpress::instance();
900 }
901
902 /**
903 * Hook bbPress early onto the 'plugins_loaded' action.
904 *
905 * This gives all other plugins the chance to load before bbPress, to get their
906 * actions, filters, and overrides setup without bbPress being in the way.
907 */
908 if ( defined( 'BBPRESS_LATE_LOAD' ) ) {
909 add_action( 'plugins_loaded', 'bbpress', (int) BBPRESS_LATE_LOAD );
910
911 // "And now here's something we hope you'll really like!"
912 } else {
913 bbpress();
914 }
915
916 endif; // class_exists check
917