web/wp-content/plugins/bbpress/bbpress.php
changeset 196 5e8dcbe22c24
child 204 09a1c134465b
equal deleted inserted replaced
195:c7c0fbc09788 196:5e8dcbe22c24
       
     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 4471 2012-11-23 11:24:58Z 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.2.2
       
    21  * Text Domain: bbpress
       
    22  * Domain Path: /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() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bbpress' ), '2.1' ); }
       
   131 
       
   132 	/**
       
   133 	 * A dummy magic method to prevent bbPress from being unserialized
       
   134 	 *
       
   135 	 * @since bbPress (r2464)
       
   136 	 */
       
   137 	public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bbpress' ), '2.1' ); }
       
   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 	/**
       
   161 	 * Magic method to prevent notices and errors from invalid method calls
       
   162 	 *
       
   163 	 * @since bbPress (r4252)
       
   164 	 */
       
   165 	public function __call( $name = '', $args = array() ) { unset( $name, $args ); return null; }
       
   166 
       
   167 	/** Private Methods *******************************************************/
       
   168 
       
   169 	/**
       
   170 	 * Set some smart defaults to class variables. Allow some of them to be
       
   171 	 * filtered to allow for early overriding.
       
   172 	 *
       
   173 	 * @since bbPress (r2626)
       
   174 	 * @access private
       
   175 	 * @uses plugin_dir_path() To generate bbPress plugin path
       
   176 	 * @uses plugin_dir_url() To generate bbPress plugin url
       
   177 	 * @uses apply_filters() Calls various filters
       
   178 	 */
       
   179 	private function setup_globals() {
       
   180 
       
   181 		/** Versions **********************************************************/
       
   182 
       
   183 		$this->version    = '2.2.2';
       
   184 		$this->db_version = '220';
       
   185 
       
   186 		/** Paths *************************************************************/
       
   187 
       
   188 		// Setup some base path and URL information
       
   189 		$this->file       = __FILE__;
       
   190 		$this->basename   = apply_filters( 'bbp_plugin_basenname', plugin_basename( $this->file ) );
       
   191 		$this->plugin_dir = apply_filters( 'bbp_plugin_dir_path',  plugin_dir_path( $this->file ) );
       
   192 		$this->plugin_url = apply_filters( 'bbp_plugin_dir_url',   plugin_dir_url ( $this->file ) );
       
   193 
       
   194 		// Includes
       
   195 		$this->includes_dir = apply_filters( 'bbp_includes_dir', trailingslashit( $this->plugin_dir . 'includes'  ) );
       
   196 		$this->includes_url = apply_filters( 'bbp_includes_url', trailingslashit( $this->plugin_url . 'includes'  ) );
       
   197 
       
   198 		// Languages
       
   199 		$this->lang_dir     = apply_filters( 'bbp_lang_dir',     trailingslashit( $this->plugin_dir . 'languages' ) );
       
   200 
       
   201 		// Templates
       
   202 		$this->themes_dir   = apply_filters( 'bbp_themes_dir',   trailingslashit( $this->plugin_dir . 'templates' ) );
       
   203 		$this->themes_url   = apply_filters( 'bbp_themes_url',   trailingslashit( $this->plugin_url . 'templates' ) );
       
   204 
       
   205 		/** Identifiers *******************************************************/
       
   206 
       
   207 		// Post type identifiers
       
   208 		$this->forum_post_type   = apply_filters( 'bbp_forum_post_type',  'forum'     );
       
   209 		$this->topic_post_type   = apply_filters( 'bbp_topic_post_type',  'topic'     );
       
   210 		$this->reply_post_type   = apply_filters( 'bbp_reply_post_type',  'reply'     );
       
   211 		$this->topic_tag_tax_id  = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' );
       
   212 
       
   213 		// Status identifiers
       
   214 		$this->spam_status_id    = apply_filters( 'bbp_spam_post_status',    'spam'    );
       
   215 		$this->closed_status_id  = apply_filters( 'bbp_closed_post_status',  'closed'  );
       
   216 		$this->orphan_status_id  = apply_filters( 'bbp_orphan_post_status',  'orphan'  );
       
   217 		$this->public_status_id  = apply_filters( 'bbp_public_post_status',  'publish' );
       
   218 		$this->pending_status_id = apply_filters( 'bbp_pending_post_status', 'pending' );
       
   219 		$this->private_status_id = apply_filters( 'bbp_private_post_status', 'private' );
       
   220 		$this->hidden_status_id  = apply_filters( 'bbp_hidden_post_status',  'hidden'  );
       
   221 		$this->trash_status_id   = apply_filters( 'bbp_trash_post_status',   'trash'   );
       
   222 
       
   223 		// Other identifiers
       
   224 		$this->user_id           = apply_filters( 'bbp_user_id', 'bbp_user' );
       
   225 		$this->tops_id           = apply_filters( 'bbp_tops_id', 'bbp_tops' );
       
   226 		$this->reps_id           = apply_filters( 'bbp_reps_id', 'bbp_reps' );
       
   227 		$this->favs_id           = apply_filters( 'bbp_favs_id', 'bbp_favs' );
       
   228 		$this->subs_id           = apply_filters( 'bbp_subs_id', 'bbp_subs' );
       
   229 		$this->view_id           = apply_filters( 'bbp_view_id', 'bbp_view' );
       
   230 		$this->edit_id           = apply_filters( 'bbp_edit_id', 'edit'     );
       
   231 
       
   232 		/** Queries ***********************************************************/
       
   233 
       
   234 		$this->current_forum_id     = 0; // Current forum id
       
   235 		$this->current_topic_id     = 0; // Current topic id
       
   236 		$this->current_reply_id     = 0; // Current reply id
       
   237 		$this->current_topic_tag_id = 0; // Current topic tag id
       
   238 
       
   239 		$this->forum_query    = new stdClass(); // Main forum query
       
   240 		$this->topic_query    = new stdClass(); // Main topic query
       
   241 		$this->reply_query    = new stdClass(); // Main reply query
       
   242 
       
   243 		/** Theme Compat ******************************************************/
       
   244 
       
   245 		$this->theme_compat   = new stdClass(); // Base theme compatibility class
       
   246 		$this->filters        = new stdClass(); // Used when adding/removing filters
       
   247 
       
   248 		/** Users *************************************************************/
       
   249 
       
   250 		$this->current_user   = new stdClass(); // Currently logged in user
       
   251 		$this->displayed_user = new stdClass(); // Currently displayed user
       
   252 
       
   253 		/** Misc **************************************************************/
       
   254 
       
   255 		$this->domain         = 'bbpress';      // Unique identifier for retrieving translated strings
       
   256 		$this->extend         = new stdClass(); // Plugins add data here
       
   257 		$this->errors         = new WP_Error(); // Feedback
       
   258 		$this->tab_index      = apply_filters( 'bbp_default_tab_index', 100 );
       
   259 
       
   260 		/** Cache *************************************************************/
       
   261 
       
   262 		// Add bbPress to global cache groups
       
   263 		wp_cache_add_global_groups( 'bbpress' );
       
   264 	}
       
   265 
       
   266 	/**
       
   267 	 * Include required files
       
   268 	 *
       
   269 	 * @since bbPress (r2626)
       
   270 	 * @access private
       
   271 	 * @uses is_admin() If in WordPress admin, load additional file
       
   272 	 */
       
   273 	private function includes() {
       
   274 
       
   275 		/** Core **************************************************************/
       
   276 
       
   277 		require( $this->includes_dir . 'core/sub-actions.php'        );
       
   278 		require( $this->includes_dir . 'core/functions.php'          );
       
   279 		require( $this->includes_dir . 'core/cache.php'              );
       
   280 		require( $this->includes_dir . 'core/options.php'            );
       
   281 		require( $this->includes_dir . 'core/capabilities.php'       );
       
   282 		require( $this->includes_dir . 'core/update.php'             );
       
   283 		require( $this->includes_dir . 'core/template-functions.php' );
       
   284 		require( $this->includes_dir . 'core/template-loader.php'    );
       
   285 		require( $this->includes_dir . 'core/theme-compat.php'       );
       
   286 
       
   287 		/** Components ********************************************************/
       
   288 
       
   289 		// Common
       
   290 		require( $this->includes_dir . 'common/classes.php'        );
       
   291 		require( $this->includes_dir . 'common/functions.php'      );
       
   292 		require( $this->includes_dir . 'common/template-tags.php'  );
       
   293 		require( $this->includes_dir . 'common/widgets.php'        );
       
   294 		require( $this->includes_dir . 'common/shortcodes.php'     );
       
   295 
       
   296 		// Forums
       
   297 		require( $this->includes_dir . 'forums/capabilities.php'   );
       
   298 		require( $this->includes_dir . 'forums/functions.php'      );
       
   299 		require( $this->includes_dir . 'forums/template-tags.php'  );
       
   300 
       
   301 		// Topics
       
   302 		require( $this->includes_dir . 'topics/capabilities.php'   );
       
   303 		require( $this->includes_dir . 'topics/functions.php'      );
       
   304 		require( $this->includes_dir . 'topics/template-tags.php'  );
       
   305 
       
   306 		// Replies
       
   307 		require( $this->includes_dir . 'replies/capabilities.php'  );
       
   308 		require( $this->includes_dir . 'replies/functions.php'     );
       
   309 		require( $this->includes_dir . 'replies/template-tags.php' );
       
   310 
       
   311 		// Users
       
   312 		require( $this->includes_dir . 'users/capabilities.php'    );
       
   313 		require( $this->includes_dir . 'users/functions.php'       );
       
   314 		require( $this->includes_dir . 'users/template-tags.php'   );
       
   315 		require( $this->includes_dir . 'users/options.php'         );
       
   316 
       
   317 		/** Hooks *************************************************************/
       
   318 
       
   319 		require( $this->includes_dir . 'core/extend.php'  );
       
   320 		require( $this->includes_dir . 'core/actions.php' );
       
   321 		require( $this->includes_dir . 'core/filters.php' );
       
   322 
       
   323 		/** Admin *************************************************************/
       
   324 
       
   325 		// Quick admin check and load if needed
       
   326 		if ( is_admin() ) {
       
   327 			require( $this->includes_dir . 'admin/admin.php'   );
       
   328 			require( $this->includes_dir . 'admin/actions.php' );
       
   329 		}
       
   330 	}
       
   331 
       
   332 	/**
       
   333 	 * Setup the default hooks and actions
       
   334 	 *
       
   335 	 * @since bbPress (r2644)
       
   336 	 * @access private
       
   337 	 * @uses add_action() To add various actions
       
   338 	 */
       
   339 	private function setup_actions() {
       
   340 
       
   341 		// Add actions to plugin activation and deactivation hooks
       
   342 		add_action( 'activate_'   . $this->basename, 'bbp_activation'   );
       
   343 		add_action( 'deactivate_' . $this->basename, 'bbp_deactivation' );
       
   344 
       
   345 		// If bbPress is being deactivated, do not add any actions
       
   346 		if ( bbp_is_deactivation( $this->basename ) )
       
   347 			return;
       
   348 
       
   349 		// Array of bbPress core actions
       
   350 		$actions = array(
       
   351 			'setup_theme',              // Setup the default theme compat
       
   352 			'setup_current_user',       // Setup currently logged in user
       
   353 			'register_post_types',      // Register post types (forum|topic|reply)
       
   354 			'register_post_statuses',   // Register post statuses (closed|spam|orphan|hidden)
       
   355 			'register_taxonomies',      // Register taxonomies (topic-tag)
       
   356 			'register_shortcodes',      // Register shortcodes (bbp-login)
       
   357 			'register_views',           // Register the views (no-replies)
       
   358 			'register_theme_packages',  // Register bundled theme packages (bbp-theme-compat/bbp-themes)
       
   359 			'load_textdomain',          // Load textdomain (bbpress)
       
   360 			'add_rewrite_tags',         // Add rewrite tags (view|user|edit)
       
   361 			'generate_rewrite_rules'    // Generate rewrite rules (view|edit)
       
   362 		);
       
   363 
       
   364 		// Add the actions
       
   365 		foreach( $actions as $class_action )
       
   366 			add_action( 'bbp_' . $class_action, array( $this, $class_action ), 5 );
       
   367 
       
   368 		// All bbPress actions are setup (includes bbp-core-hooks.php)
       
   369 		do_action_ref_array( 'bbp_after_setup_actions', array( &$this ) );
       
   370 	}
       
   371 
       
   372 	/** Public Methods ********************************************************/
       
   373 
       
   374 	/**
       
   375 	 * Register bundled theme packages
       
   376 	 *
       
   377 	 * Note that since we currently have complete control over bbp-themes and
       
   378 	 * the bbp-theme-compat folders, it's fine to hardcode these here. If at a
       
   379 	 * later date we need to automate this, and API will need to be built.
       
   380 	 *
       
   381 	 * @since bbPress (r3829)
       
   382 	 */
       
   383 	public function register_theme_packages() {
       
   384 
       
   385 		// Register the default theme compatibility package
       
   386 		bbp_register_theme_package( array(
       
   387 			'id'      => 'default',
       
   388 			'name'    => __( 'bbPress Default', 'bbpress' ),
       
   389 			'version' => bbp_get_version(),
       
   390 			'dir'     => trailingslashit( $this->themes_dir . 'default' ),
       
   391 			'url'     => trailingslashit( $this->themes_url . 'default' )
       
   392 		) );
       
   393 
       
   394 		// Register the basic theme stack. This is really dope.
       
   395 		bbp_register_template_stack( 'get_stylesheet_directory', 10 );
       
   396 		bbp_register_template_stack( 'get_template_directory',   12 );
       
   397 		bbp_register_template_stack( 'bbp_get_theme_compat_dir', 14 );
       
   398 	}
       
   399 
       
   400 	/**
       
   401 	 * Setup the default bbPress theme compatability location.
       
   402 	 *
       
   403 	 * @since bbPress (r3778)
       
   404 	 */
       
   405 	public function setup_theme() {
       
   406 
       
   407 		// Bail if something already has this under control
       
   408 		if ( ! empty( $this->theme_compat->theme ) )
       
   409 			return;
       
   410 
       
   411 		// Setup the theme package to use for compatibility
       
   412 		bbp_setup_theme_compat( bbp_get_theme_package_id() );
       
   413 	}
       
   414 
       
   415 	/**
       
   416 	 * Load the translation file for current language. Checks the languages
       
   417 	 * folder inside the bbPress plugin first, and then the default WordPress
       
   418 	 * languages folder.
       
   419 	 *
       
   420 	 * Note that custom translation files inside the bbPress plugin folder
       
   421 	 * will be removed on bbPress updates. If you're creating custom
       
   422 	 * translation files, please use the global language folder.
       
   423 	 *
       
   424 	 * @since bbPress (r2596)
       
   425 	 *
       
   426 	 * @uses apply_filters() Calls 'bbpress_locale' with the
       
   427 	 *                        {@link get_locale()} value
       
   428 	 * @uses load_textdomain() To load the textdomain
       
   429 	 * @return bool True on success, false on failure
       
   430 	 */
       
   431 	public function load_textdomain() {
       
   432 
       
   433 		// Traditional WordPress plugin locale filter
       
   434 		$locale        = apply_filters( 'plugin_locale',  get_locale(), $this->domain );
       
   435 		$mofile        = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
       
   436 
       
   437 		// Setup paths to current locale file
       
   438 		$mofile_local  = $this->lang_dir . $mofile;
       
   439 		$mofile_global = WP_LANG_DIR . '/bbpress/' . $mofile;
       
   440 
       
   441 		// Look in global /wp-content/languages/bbpress folder
       
   442 		if ( file_exists( $mofile_global ) ) {
       
   443 			return load_textdomain( $this->domain, $mofile_global );
       
   444 
       
   445 		// Look in local /wp-content/plugins/bbpress/bbp-languages/ folder
       
   446 		} elseif ( file_exists( $mofile_local ) ) {
       
   447 			return load_textdomain( $this->domain, $mofile_local );
       
   448 		}
       
   449 
       
   450 		// Nothing found
       
   451 		return false;
       
   452 	}
       
   453 
       
   454 	/**
       
   455 	 * Setup the post types for forums, topics and replies
       
   456 	 *
       
   457 	 * @since bbPress (r2597)
       
   458 	 * @uses register_post_type() To register the post types
       
   459 	 * @uses apply_filters() Calls various filters to modify the arguments
       
   460 	 *                        sent to register_post_type()
       
   461 	 */
       
   462 	public static function register_post_types() {
       
   463 
       
   464 		// Define local variable(s)
       
   465 		$post_type = array();
       
   466 
       
   467 		/** Forums ************************************************************/
       
   468 
       
   469 		// Forum labels
       
   470 		$post_type['labels'] = array(
       
   471 			'name'               => __( 'Forums',                   'bbpress' ),
       
   472 			'menu_name'          => __( 'Forums',                   'bbpress' ),
       
   473 			'singular_name'      => __( 'Forum',                    'bbpress' ),
       
   474 			'all_items'          => __( 'All Forums',               'bbpress' ),
       
   475 			'add_new'            => __( 'New Forum',                'bbpress' ),
       
   476 			'add_new_item'       => __( 'Create New Forum',         'bbpress' ),
       
   477 			'edit'               => __( 'Edit',                     'bbpress' ),
       
   478 			'edit_item'          => __( 'Edit Forum',               'bbpress' ),
       
   479 			'new_item'           => __( 'New Forum',                'bbpress' ),
       
   480 			'view'               => __( 'View Forum',               'bbpress' ),
       
   481 			'view_item'          => __( 'View Forum',               'bbpress' ),
       
   482 			'search_items'       => __( 'Search Forums',            'bbpress' ),
       
   483 			'not_found'          => __( 'No forums found',          'bbpress' ),
       
   484 			'not_found_in_trash' => __( 'No forums found in Trash', 'bbpress' ),
       
   485 			'parent_item_colon'  => __( 'Parent Forum:',            'bbpress' )
       
   486 		);
       
   487 
       
   488 		// Forum rewrite
       
   489 		$post_type['rewrite'] = array(
       
   490 			'slug'       => bbp_get_forum_slug(),
       
   491 			'with_front' => false
       
   492 		);
       
   493 
       
   494 		// Forum supports
       
   495 		$post_type['supports'] = array(
       
   496 			'title',
       
   497 			'editor',
       
   498 			'revisions'
       
   499 		);
       
   500 
       
   501 		// Register Forum content type
       
   502 		register_post_type(
       
   503 			bbp_get_forum_post_type(),
       
   504 			apply_filters( 'bbp_register_forum_post_type', array(
       
   505 				'labels'              => $post_type['labels'],
       
   506 				'rewrite'             => $post_type['rewrite'],
       
   507 				'supports'            => $post_type['supports'],
       
   508 				'description'         => __( 'bbPress Forums', 'bbpress' ),
       
   509 				'capabilities'        => bbp_get_forum_caps(),
       
   510 				'capability_type'     => array( 'forum', 'forums' ),
       
   511 				'menu_position'       => 555555,
       
   512 				'has_archive'         => bbp_get_root_slug(),
       
   513 				'exclude_from_search' => true,
       
   514 				'show_in_nav_menus'   => true,
       
   515 				'public'              => true,
       
   516 				'show_ui'             => current_user_can( 'bbp_forums_admin' ),
       
   517 				'can_export'          => true,
       
   518 				'hierarchical'        => true,
       
   519 				'query_var'           => true,
       
   520 				'menu_icon'           => ''
       
   521 			) )
       
   522 		);
       
   523 
       
   524 		/** Topics ************************************************************/
       
   525 
       
   526 		// Topic labels
       
   527 		$post_type['labels'] = array(
       
   528 			'name'               => __( 'Topics',                   'bbpress' ),
       
   529 			'menu_name'          => __( 'Topics',                   'bbpress' ),
       
   530 			'singular_name'      => __( 'Topic',                    'bbpress' ),
       
   531 			'all_items'          => __( 'All Topics',               'bbpress' ),
       
   532 			'add_new'            => __( 'New Topic',                'bbpress' ),
       
   533 			'add_new_item'       => __( 'Create New Topic',         'bbpress' ),
       
   534 			'edit'               => __( 'Edit',                     'bbpress' ),
       
   535 			'edit_item'          => __( 'Edit Topic',               'bbpress' ),
       
   536 			'new_item'           => __( 'New Topic',                'bbpress' ),
       
   537 			'view'               => __( 'View Topic',               'bbpress' ),
       
   538 			'view_item'          => __( 'View Topic',               'bbpress' ),
       
   539 			'search_items'       => __( 'Search Topics',            'bbpress' ),
       
   540 			'not_found'          => __( 'No topics found',          'bbpress' ),
       
   541 			'not_found_in_trash' => __( 'No topics found in Trash', 'bbpress' ),
       
   542 			'parent_item_colon'  => __( 'Forum:',                   'bbpress' )
       
   543 		);
       
   544 
       
   545 		// Topic rewrite
       
   546 		$post_type['rewrite'] = array(
       
   547 			'slug'       => bbp_get_topic_slug(),
       
   548 			'with_front' => false
       
   549 		);
       
   550 
       
   551 		// Topic supports
       
   552 		$post_type['supports'] = array(
       
   553 			'title',
       
   554 			'editor',
       
   555 			'revisions'
       
   556 		);
       
   557 
       
   558 		// Register Topic content type
       
   559 		register_post_type(
       
   560 			bbp_get_topic_post_type(),
       
   561 			apply_filters( 'bbp_register_topic_post_type', array(
       
   562 				'labels'              => $post_type['labels'],
       
   563 				'rewrite'             => $post_type['rewrite'],
       
   564 				'supports'            => $post_type['supports'],
       
   565 				'description'         => __( 'bbPress Topics', 'bbpress' ),
       
   566 				'capabilities'        => bbp_get_topic_caps(),
       
   567 				'capability_type'     => array( 'topic', 'topics' ),
       
   568 				'menu_position'       => 555555,
       
   569 				'has_archive'         => bbp_get_topic_archive_slug(),
       
   570 				'exclude_from_search' => true,
       
   571 				'show_in_nav_menus'   => false,
       
   572 				'public'              => true,
       
   573 				'show_ui'             => current_user_can( 'bbp_topics_admin' ),
       
   574 				'can_export'          => true,
       
   575 				'hierarchical'        => false,
       
   576 				'query_var'           => true,
       
   577 				'menu_icon'           => ''
       
   578 			)
       
   579 		) );
       
   580 
       
   581 		/** Replies ***********************************************************/
       
   582 
       
   583 		// Reply labels
       
   584 		$post_type['labels'] = array(
       
   585 			'name'               => __( 'Replies',                   'bbpress' ),
       
   586 			'menu_name'          => __( 'Replies',                   'bbpress' ),
       
   587 			'singular_name'      => __( 'Reply',                     'bbpress' ),
       
   588 			'all_items'          => __( 'All Replies',               'bbpress' ),
       
   589 			'add_new'            => __( 'New Reply',                 'bbpress' ),
       
   590 			'add_new_item'       => __( 'Create New Reply',          'bbpress' ),
       
   591 			'edit'               => __( 'Edit',                      'bbpress' ),
       
   592 			'edit_item'          => __( 'Edit Reply',                'bbpress' ),
       
   593 			'new_item'           => __( 'New Reply',                 'bbpress' ),
       
   594 			'view'               => __( 'View Reply',                'bbpress' ),
       
   595 			'view_item'          => __( 'View Reply',                'bbpress' ),
       
   596 			'search_items'       => __( 'Search Replies',            'bbpress' ),
       
   597 			'not_found'          => __( 'No replies found',          'bbpress' ),
       
   598 			'not_found_in_trash' => __( 'No replies found in Trash', 'bbpress' ),
       
   599 			'parent_item_colon'  => __( 'Topic:',                    'bbpress' )
       
   600 		);
       
   601 
       
   602 		// Reply rewrite
       
   603 		$post_type['rewrite'] = array(
       
   604 			'slug'       => bbp_get_reply_slug(),
       
   605 			'with_front' => false
       
   606 		);
       
   607 
       
   608 		// Reply supports
       
   609 		$post_type['supports'] = array(
       
   610 			'title',
       
   611 			'editor',
       
   612 			'revisions'
       
   613 		);
       
   614 
       
   615 		// Register reply content type
       
   616 		register_post_type(
       
   617 			bbp_get_reply_post_type(),
       
   618 			apply_filters( 'bbp_register_reply_post_type', array(
       
   619 				'labels'              => $post_type['labels'],
       
   620 				'rewrite'             => $post_type['rewrite'],
       
   621 				'supports'            => $post_type['supports'],
       
   622 				'description'         => __( 'bbPress Replies', 'bbpress' ),
       
   623 				'capabilities'        => bbp_get_reply_caps(),
       
   624 				'capability_type'     => array( 'reply', 'replies' ),
       
   625 				'menu_position'       => 555555,
       
   626 				'exclude_from_search' => true,
       
   627 				'has_archive'         => false,
       
   628 				'show_in_nav_menus'   => false,
       
   629 				'public'              => true,
       
   630 				'show_ui'             => current_user_can( 'bbp_replies_admin' ),
       
   631 				'can_export'          => true,
       
   632 				'hierarchical'        => false,
       
   633 				'query_var'           => true,
       
   634 				'menu_icon'           => ''
       
   635 			) )
       
   636 		);
       
   637 	}
       
   638 
       
   639 	/**
       
   640 	 * Register the post statuses used by bbPress
       
   641 	 *
       
   642 	 * We do some manipulation of the 'trash' status so trashed topics and
       
   643 	 * replies can be viewed from within the theme.
       
   644 	 *
       
   645 	 * @since bbPress (r2727)
       
   646 	 * @uses register_post_status() To register post statuses
       
   647 	 * @uses $wp_post_statuses To modify trash and private statuses
       
   648 	 * @uses current_user_can() To check if the current user is capable &
       
   649 	 *                           modify $wp_post_statuses accordingly
       
   650 	 */
       
   651 	public static function register_post_statuses() {
       
   652 
       
   653 		// Closed
       
   654 		register_post_status(
       
   655 			bbp_get_closed_status_id(),
       
   656 			apply_filters( 'bbp_register_closed_post_status', array(
       
   657 				'label'             => _x( 'Closed', 'post', 'bbpress' ),
       
   658 				'label_count'       => _nx_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'bbpress' ),
       
   659 				'public'            => true,
       
   660 				'show_in_admin_all' => true
       
   661 			) )
       
   662 		);
       
   663 
       
   664 		// Spam
       
   665 		register_post_status(
       
   666 			bbp_get_spam_status_id(),
       
   667 			apply_filters( 'bbp_register_spam_post_status', array(
       
   668 				'label'                     => _x( 'Spam', 'post', 'bbpress' ),
       
   669 				'label_count'               => _nx_noop( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'bbpress' ),
       
   670 				'protected'                 => true,
       
   671 				'exclude_from_search'       => true,
       
   672 				'show_in_admin_status_list' => true,
       
   673 				'show_in_admin_all_list'    => false
       
   674 			) )
       
   675 		 );
       
   676 
       
   677 		// Orphan
       
   678 		register_post_status(
       
   679 			bbp_get_orphan_status_id(),
       
   680 			apply_filters( 'bbp_register_orphan_post_status', array(
       
   681 				'label'                     => _x( 'Orphan', 'post', 'bbpress' ),
       
   682 				'label_count'               => _nx_noop( 'Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'bbpress' ),
       
   683 				'protected'                 => true,
       
   684 				'exclude_from_search'       => true,
       
   685 				'show_in_admin_status_list' => true,
       
   686 				'show_in_admin_all_list'    => false
       
   687 			) )
       
   688 		);
       
   689 
       
   690 		// Hidden
       
   691 		register_post_status(
       
   692 			bbp_get_hidden_status_id(),
       
   693 			apply_filters( 'bbp_register_hidden_post_status', array(
       
   694 				'label'                     => _x( 'Hidden', 'post', 'bbpress' ),
       
   695 				'label_count'               => _nx_noop( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'bbpress' ),
       
   696 				'private'                   => true,
       
   697 				'exclude_from_search'       => true,
       
   698 				'show_in_admin_status_list' => true,
       
   699 				'show_in_admin_all_list'    => true
       
   700 			) )
       
   701 		);
       
   702 
       
   703 		/**
       
   704 		 * Trash fix
       
   705 		 *
       
   706 		 * We need to remove the internal arg and change that to
       
   707 		 * protected so that the users with 'view_trash' cap can view
       
   708 		 * single trashed topics/replies in the front-end as wp_query
       
   709 		 * doesn't allow any hack for the trashed topics to be viewed.
       
   710 		 */
       
   711 		global $wp_post_statuses;
       
   712 
       
   713 		if ( !empty( $wp_post_statuses['trash'] ) ) {
       
   714 
       
   715 			// User can view trash so set internal to false
       
   716 			if ( current_user_can( 'view_trash' ) ) {
       
   717 				$wp_post_statuses['trash']->internal  = false;
       
   718 				$wp_post_statuses['trash']->protected = true;
       
   719 
       
   720 			// User cannot view trash so set internal to true
       
   721 			} elseif ( !current_user_can( 'view_trash' ) ) {
       
   722 				$wp_post_statuses['trash']->internal = true;
       
   723 			}
       
   724 		}
       
   725 	}
       
   726 
       
   727 	/**
       
   728 	 * Register the topic tag taxonomy
       
   729 	 *
       
   730 	 * @since bbPress (r2464)
       
   731 	 * @uses register_taxonomy() To register the taxonomy
       
   732 	 */
       
   733 	public static function register_taxonomies() {
       
   734 
       
   735 		// Define local variable(s)
       
   736 		$topic_tag = array();
       
   737 
       
   738 		// Topic tag labels
       
   739 		$topic_tag['labels'] = array(
       
   740 			'name'          => __( 'Topic Tags',     'bbpress' ),
       
   741 			'singular_name' => __( 'Topic Tag',      'bbpress' ),
       
   742 			'search_items'  => __( 'Search Tags',    'bbpress' ),
       
   743 			'popular_items' => __( 'Popular Tags',   'bbpress' ),
       
   744 			'all_items'     => __( 'All Tags',       'bbpress' ),
       
   745 			'edit_item'     => __( 'Edit Tag',       'bbpress' ),
       
   746 			'update_item'   => __( 'Update Tag',     'bbpress' ),
       
   747 			'add_new_item'  => __( 'Add New Tag',    'bbpress' ),
       
   748 			'new_item_name' => __( 'New Tag Name',   'bbpress' ),
       
   749 			'view_item'     => __( 'View Topic Tag', 'bbpress' )
       
   750 		);
       
   751 
       
   752 		// Topic tag rewrite
       
   753 		$topic_tag['rewrite'] = array(
       
   754 			'slug'       => bbp_get_topic_tag_tax_slug(),
       
   755 			'with_front' => false
       
   756 		);
       
   757 
       
   758 		// Register the topic tag taxonomy
       
   759 		register_taxonomy(
       
   760 			bbp_get_topic_tag_tax_id(),
       
   761 			bbp_get_topic_post_type(),
       
   762 			apply_filters( 'bbp_register_topic_taxonomy', array(
       
   763 				'labels'                => $topic_tag['labels'],
       
   764 				'rewrite'               => $topic_tag['rewrite'],
       
   765 				'capabilities'          => bbp_get_topic_tag_caps(),
       
   766 				'update_count_callback' => '_update_post_term_count',
       
   767 				'query_var'             => true,
       
   768 				'show_tagcloud'         => true,
       
   769 				'hierarchical'          => false,
       
   770 				'public'                => true,
       
   771 				'show_ui'               => bbp_allow_topic_tags() && current_user_can( 'bbp_topic_tags_admin' )
       
   772 			)
       
   773 		) );
       
   774 	}
       
   775 
       
   776 	/**
       
   777 	 * Register the bbPress views
       
   778 	 *
       
   779 	 * @since bbPress (r2789)
       
   780 	 * @uses bbp_register_view() To register the views
       
   781 	 */
       
   782 	public static function register_views() {
       
   783 
       
   784 		// Topics with no replies
       
   785 		bbp_register_view(
       
   786 			'no-replies',
       
   787 			__( 'Topics with no replies', 'bbpress' ),
       
   788 			apply_filters( 'bbp_register_view_no_replies', array(
       
   789 				'meta_key'     => '_bbp_reply_count',
       
   790 				'meta_value'   => 1,
       
   791 				'meta_compare' => '<',
       
   792 				'orderby'      => ''
       
   793 			)
       
   794 		) );
       
   795 	}
       
   796 
       
   797 	/**
       
   798 	 * Register the bbPress shortcodes
       
   799 	 *
       
   800 	 * @since bbPress (r3031)
       
   801 	 *
       
   802 	 * @uses BBP_Shortcodes
       
   803 	 */
       
   804 	public function register_shortcodes() {
       
   805 		$this->shortcodes = new BBP_Shortcodes();
       
   806 	}
       
   807 
       
   808 	/**
       
   809 	 * Setup the currently logged-in user
       
   810 	 *
       
   811 	 * Do not to call this prematurely, I.E. before the 'init' action has
       
   812 	 * started. This function is naturally hooked into 'init' to ensure proper
       
   813 	 * execution. get_currentuserinfo() is used to check for XMLRPC_REQUEST to
       
   814 	 * avoid xmlrpc errors.
       
   815 	 *
       
   816 	 * @since bbPress (r2697)
       
   817 	 * @uses wp_get_current_user()
       
   818 	 */
       
   819 	public function setup_current_user() {
       
   820 		$this->current_user = &wp_get_current_user();
       
   821 	}
       
   822 
       
   823 	/** Custom Rewrite Rules **************************************************/
       
   824 
       
   825 	/**
       
   826 	 * Add the bbPress-specific rewrite tags
       
   827 	 *
       
   828 	 * @since bbPress (r2753)
       
   829 	 * @uses add_rewrite_tag() To add the rewrite tags
       
   830 	 */
       
   831 	public static function add_rewrite_tags() {
       
   832 		add_rewrite_tag( '%%' . bbp_get_view_rewrite_id()               . '%%', '([^/]+)'   ); // View Page tag
       
   833 		add_rewrite_tag( '%%' . bbp_get_edit_rewrite_id()               . '%%', '([1]{1,})' ); // Edit Page tag
       
   834 		add_rewrite_tag( '%%' . bbp_get_user_rewrite_id()               . '%%', '([^/]+)'   ); // User Profile tag
       
   835 		add_rewrite_tag( '%%' . bbp_get_user_favorites_rewrite_id()     . '%%', '([1]{1,})' ); // User Favorites tag
       
   836 		add_rewrite_tag( '%%' . bbp_get_user_subscriptions_rewrite_id() . '%%', '([1]{1,})' ); // User Subscriptions tag
       
   837 		add_rewrite_tag( '%%' . bbp_get_user_topics_rewrite_id()        . '%%', '([1]{1,})' ); // User Topics Tag
       
   838 		add_rewrite_tag( '%%' . bbp_get_user_replies_rewrite_id()       . '%%', '([1]{1,})' ); // User Replies Tag
       
   839 	}
       
   840 
       
   841 	/**
       
   842 	 * Register bbPress-specific rewrite rules for uri's that are not
       
   843 	 * setup for us by way of custom post types or taxonomies. This includes:
       
   844 	 * - Front-end editing
       
   845 	 * - Topic views
       
   846 	 * - User profiles
       
   847 	 *
       
   848 	 * @since bbPress (r2688)
       
   849 	 * @param WP_Rewrite $wp_rewrite bbPress-sepecific rules are appended in
       
   850 	 *                                $wp_rewrite->rules
       
   851 	 */
       
   852 	public static function generate_rewrite_rules( $wp_rewrite ) {
       
   853 
       
   854 		// Slugs
       
   855 		$view_slug = bbp_get_view_slug();
       
   856 		$user_slug = bbp_get_user_slug();
       
   857 
       
   858 		// Unique rewrite ID's
       
   859 		$edit_id = bbp_get_edit_rewrite_id();
       
   860 		$view_id = bbp_get_view_rewrite_id();
       
   861 		$user_id = bbp_get_user_rewrite_id();
       
   862 		$favs_id = bbp_get_user_favorites_rewrite_id();
       
   863 		$subs_id = bbp_get_user_subscriptions_rewrite_id();
       
   864 		$tops_id = bbp_get_user_topics_rewrite_id();
       
   865 		$reps_id = bbp_get_user_replies_rewrite_id();
       
   866 
       
   867 		// Rewrite rule matches used repeatedly below
       
   868 		$root_rule = '/([^/]+)/?$';
       
   869 		$edit_rule = '/([^/]+)/edit/?$';
       
   870 		$feed_rule = '/([^/]+)/feed/?$';
       
   871 		$page_rule = '/([^/]+)/page/?([0-9]{1,})/?$';
       
   872 
       
   873 		// User profile rules
       
   874 		$tops_rule      = '/([^/]+)/topics/?$';
       
   875 		$reps_rule      = '/([^/]+)/replies/?$';
       
   876 		$favs_rule      = '/([^/]+)/' . bbp_get_user_favorites_slug()     . '/?$';
       
   877 		$subs_rule      = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/?$';
       
   878 		$tops_page_rule = '/([^/]+)/topics/page/?([0-9]{1,})/?$';
       
   879 		$reps_page_rule = '/([^/]+)/replies/page/?([0-9]{1,})/?$';
       
   880 		$favs_page_rule = '/([^/]+)/' . bbp_get_user_favorites_slug()     . '/page/?([0-9]{1,})/?$';
       
   881 		$subs_page_rule = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/page/?([0-9]{1,})/?$';
       
   882 
       
   883 		// New bbPress specific rules to merge with existing that are not
       
   884 		// handled automatically by custom post types or taxonomy types
       
   885 		$bbp_rules = array(
       
   886 
       
   887 			// Edit Forum|Topic|Reply|Topic-tag
       
   888 			bbp_get_forum_slug()         . $edit_rule => 'index.php?' . bbp_get_forum_post_type()  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
       
   889 			bbp_get_topic_slug()         . $edit_rule => 'index.php?' . bbp_get_topic_post_type()  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
       
   890 			bbp_get_reply_slug()         . $edit_rule => 'index.php?' . bbp_get_reply_post_type()  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
       
   891 			bbp_get_topic_tag_tax_slug() . $edit_rule => 'index.php?' . bbp_get_topic_tag_tax_id() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
       
   892 
       
   893 			// User Pagination|Edit|View
       
   894 			$user_slug . $tops_page_rule => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $tops_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ),
       
   895 			$user_slug . $reps_page_rule => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $reps_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ),
       
   896 			$user_slug . $favs_page_rule => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $favs_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ),
       
   897 			$user_slug . $subs_page_rule => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $subs_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ),
       
   898 			$user_slug . $tops_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $tops_id . '=1',
       
   899 			$user_slug . $reps_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $reps_id . '=1',
       
   900 			$user_slug . $favs_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $favs_id . '=1',
       
   901 			$user_slug . $subs_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $subs_id . '=1',
       
   902 			$user_slug . $edit_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
       
   903 			$user_slug . $root_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ),
       
   904 
       
   905 			// Topic-View Pagination|Feed|View
       
   906 			$view_slug . $page_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
       
   907 			$view_slug . $feed_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&feed='  . $wp_rewrite->preg_index( 2 ),
       
   908 			$view_slug . $root_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ),
       
   909 		);
       
   910 
       
   911 		// Merge bbPress rules with existing
       
   912 		$wp_rewrite->rules = array_merge( $bbp_rules, $wp_rewrite->rules );
       
   913 
       
   914 		// Return merged rules
       
   915 		return $wp_rewrite;
       
   916 	}
       
   917 }
       
   918 
       
   919 /**
       
   920  * The main function responsible for returning the one true bbPress Instance
       
   921  * to functions everywhere.
       
   922  *
       
   923  * Use this function like you would a global variable, except without needing
       
   924  * to declare the global.
       
   925  *
       
   926  * Example: <?php $bbp = bbpress(); ?>
       
   927  *
       
   928  * @return The one true bbPress Instance
       
   929  */
       
   930 function bbpress() {
       
   931 	return bbpress::instance();
       
   932 }
       
   933 
       
   934 /**
       
   935  * Hook bbPress early onto the 'plugins_loaded' action.
       
   936  *
       
   937  * This gives all other plugins the chance to load before bbPress, to get their
       
   938  * actions, filters, and overrides setup without bbPress being in the way.
       
   939  */
       
   940 if ( defined( 'BBPRESS_LATE_LOAD' ) ) {
       
   941 	add_action( 'plugins_loaded', 'bbpress', (int) BBPRESS_LATE_LOAD );
       
   942 
       
   943 // "And now here's something we hope you'll really like!"
       
   944 } else {
       
   945 	bbpress();
       
   946 }
       
   947 
       
   948 endif; // class_exists check