bbPress

Main bbPress Class.

Defined (1)

The class is defined in the following location(s).

/bbpress.php  
  1. final class bbPress { 
  2.  
  3. /** Magic *****************************************************************/ 
  4.  
  5. /** 
  6. * bbPress uses many variables, several of which can be filtered to 
  7. * customize the way it operates. Most of these variables are stored in a 
  8. * private array that gets updated with the help of PHP magic methods. 
  9. * This is a precautionary measure, to avoid potential errors produced by 
  10. * unanticipated direct manipulation of bbPress's run-time data. 
  11. * @see bbPress::setup_globals() 
  12. * @var array 
  13. */ 
  14. private $data; 
  15.  
  16. /** Not Magic *************************************************************/ 
  17.  
  18. /** 
  19. * @var mixed False when not logged in; WP_User object when logged in 
  20. */ 
  21. public $current_user = false; 
  22.  
  23. /** 
  24. * @var obj Add-ons append to this (Akismet, BuddyPress, etc...) 
  25. */ 
  26. public $extend; 
  27.  
  28. /** 
  29. * @var array Topic views 
  30. */ 
  31. public $views = array(); 
  32.  
  33. /** 
  34. * @var array Overloads get_option() 
  35. */ 
  36. public $options = array(); 
  37.  
  38. /** 
  39. * @var array Overloads get_user_meta() 
  40. */ 
  41. public $user_options = array(); 
  42.  
  43. /** Singleton *************************************************************/ 
  44.  
  45. /** 
  46. * Main bbPress Instance 
  47. * bbPress is fun 
  48. * Please load it only one time 
  49. * For this, we thank you 
  50. * Insures that only one instance of bbPress exists in memory at any one 
  51. * time. Also prevents needing to define globals all over the place. 
  52. * @since bbPress (r3757) 
  53. * @staticvar object $instance 
  54. * @uses bbPress::setup_globals() Setup the globals needed 
  55. * @uses bbPress::includes() Include the required files 
  56. * @uses bbPress::setup_actions() Setup the hooks and actions 
  57. * @see bbpress() 
  58. * @return The one true bbPress 
  59. */ 
  60. public static function instance() { 
  61.  
  62. // Store the instance locally to avoid private static replication 
  63. static $instance = null; 
  64.  
  65. // Only run these methods if they haven't been ran previously 
  66. if ( null === $instance ) { 
  67. $instance = new bbPress; 
  68. $instance->setup_globals(); 
  69. $instance->includes(); 
  70. $instance->setup_actions(); 
  71.  
  72. // Always return the instance 
  73. return $instance; 
  74.  
  75. /** Magic Methods *********************************************************/ 
  76.  
  77. /** 
  78. * A dummy constructor to prevent bbPress from being loaded more than once. 
  79. * @since bbPress (r2464) 
  80. * @see bbPress::instance() 
  81. * @see bbpress(); 
  82. */ 
  83. private function __construct() { /** Do nothing here */ } 
  84.  
  85. /** 
  86. * A dummy magic method to prevent bbPress from being cloned 
  87. * @since bbPress (r2464) 
  88. */ 
  89. public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bbpress' ), '2.1' ); } 
  90.  
  91. /** 
  92. * A dummy magic method to prevent bbPress from being unserialized 
  93. * @since bbPress (r2464) 
  94. */ 
  95. public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bbpress' ), '2.1' ); } 
  96.  
  97. /** 
  98. * Magic method for checking the existence of a certain custom field 
  99. * @since bbPress (r3951) 
  100. */ 
  101. public function __isset( $key ) { return isset( $this->data[$key] ); } 
  102.  
  103. /** 
  104. * Magic method for getting bbPress variables 
  105. * @since bbPress (r3951) 
  106. */ 
  107. public function __get( $key ) { return isset( $this->data[$key] ) ? $this->data[$key] : null; } 
  108.  
  109. /** 
  110. * Magic method for setting bbPress variables 
  111. * @since bbPress (r3951) 
  112. */ 
  113. public function __set( $key, $value ) { $this->data[$key] = $value; } 
  114.  
  115. /** 
  116. * Magic method for unsetting bbPress variables 
  117. * @since bbPress (r4628) 
  118. */ 
  119. public function __unset( $key ) { if ( isset( $this->data[$key] ) ) unset( $this->data[$key] ); } 
  120.  
  121. /** 
  122. * Magic method to prevent notices and errors from invalid method calls 
  123. * @since bbPress (r4252) 
  124. */ 
  125. public function __call( $name = '', $args = array() ) { unset( $name, $args ); return null; } 
  126.  
  127. /** Private Methods *******************************************************/ 
  128.  
  129. /** 
  130. * Set some smart defaults to class variables. Allow some of them to be 
  131. * filtered to allow for early overriding. 
  132. * @since bbPress (r2626) 
  133. * @access private 
  134. * @uses plugin_dir_path() To generate bbPress plugin path 
  135. * @uses plugin_dir_url() To generate bbPress plugin url 
  136. * @uses apply_filters() Calls various filters 
  137. */ 
  138. private function setup_globals() { 
  139.  
  140. /** Versions **********************************************************/ 
  141.  
  142. $this->version = '2.5.9-6017'; 
  143. $this->db_version = '250'; 
  144.  
  145. /** Paths *************************************************************/ 
  146.  
  147. // Setup some base path and URL information 
  148. $this->file = __FILE__; 
  149. $this->basename = apply_filters( 'bbp_plugin_basenname', plugin_basename( $this->file ) ); 
  150. $this->plugin_dir = apply_filters( 'bbp_plugin_dir_path', plugin_dir_path( $this->file ) ); 
  151. $this->plugin_url = apply_filters( 'bbp_plugin_dir_url', plugin_dir_url ( $this->file ) ); 
  152.  
  153. // Includes 
  154. $this->includes_dir = apply_filters( 'bbp_includes_dir', trailingslashit( $this->plugin_dir . 'includes' ) ); 
  155. $this->includes_url = apply_filters( 'bbp_includes_url', trailingslashit( $this->plugin_url . 'includes' ) ); 
  156.  
  157. // Languages 
  158. $this->lang_dir = apply_filters( 'bbp_lang_dir', trailingslashit( $this->plugin_dir . 'languages' ) ); 
  159.  
  160. // Templates 
  161. $this->themes_dir = apply_filters( 'bbp_themes_dir', trailingslashit( $this->plugin_dir . 'templates' ) ); 
  162. $this->themes_url = apply_filters( 'bbp_themes_url', trailingslashit( $this->plugin_url . 'templates' ) ); 
  163.  
  164. /** Identifiers *******************************************************/ 
  165.  
  166. // Post type identifiers 
  167. $this->forum_post_type = apply_filters( 'bbp_forum_post_type', 'forum' ); 
  168. $this->topic_post_type = apply_filters( 'bbp_topic_post_type', 'topic' ); 
  169. $this->reply_post_type = apply_filters( 'bbp_reply_post_type', 'reply' ); 
  170. $this->topic_tag_tax_id = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' ); 
  171.  
  172. // Status identifiers 
  173. $this->spam_status_id = apply_filters( 'bbp_spam_post_status', 'spam' ); 
  174. $this->closed_status_id = apply_filters( 'bbp_closed_post_status', 'closed' ); 
  175. $this->orphan_status_id = apply_filters( 'bbp_orphan_post_status', 'orphan' ); 
  176. $this->public_status_id = apply_filters( 'bbp_public_post_status', 'publish' ); 
  177. $this->pending_status_id = apply_filters( 'bbp_pending_post_status', 'pending' ); 
  178. $this->private_status_id = apply_filters( 'bbp_private_post_status', 'private' ); 
  179. $this->hidden_status_id = apply_filters( 'bbp_hidden_post_status', 'hidden' ); 
  180. $this->trash_status_id = apply_filters( 'bbp_trash_post_status', 'trash' ); 
  181.  
  182. // Other identifiers 
  183. $this->user_id = apply_filters( 'bbp_user_id', 'bbp_user' ); 
  184. $this->tops_id = apply_filters( 'bbp_tops_id', 'bbp_tops' ); 
  185. $this->reps_id = apply_filters( 'bbp_reps_id', 'bbp_reps' ); 
  186. $this->favs_id = apply_filters( 'bbp_favs_id', 'bbp_favs' ); 
  187. $this->subs_id = apply_filters( 'bbp_subs_id', 'bbp_subs' ); 
  188. $this->view_id = apply_filters( 'bbp_view_id', 'bbp_view' ); 
  189. $this->edit_id = apply_filters( 'bbp_edit_id', 'edit' ); 
  190. $this->paged_id = apply_filters( 'bbp_paged_id', 'paged' ); 
  191. $this->search_id = apply_filters( 'bbp_search_id', 'bbp_search' ); 
  192.  
  193. /** Queries ***********************************************************/ 
  194.  
  195. $this->current_view_id = 0; // Current view id 
  196. $this->current_forum_id = 0; // Current forum id 
  197. $this->current_topic_id = 0; // Current topic id 
  198. $this->current_reply_id = 0; // Current reply id 
  199. $this->current_topic_tag_id = 0; // Current topic tag id 
  200.  
  201. $this->forum_query = new WP_Query(); // Main forum query 
  202. $this->topic_query = new WP_Query(); // Main topic query 
  203. $this->reply_query = new WP_Query(); // Main reply query 
  204. $this->search_query = new WP_Query(); // Main search query 
  205.  
  206. /** Theme Compat ******************************************************/ 
  207.  
  208. $this->theme_compat = new stdClass(); // Base theme compatibility class 
  209. $this->filters = new stdClass(); // Used when adding/removing filters 
  210.  
  211. /** Users *************************************************************/ 
  212.  
  213. $this->current_user = new WP_User(); // Currently logged in user 
  214. $this->displayed_user = new WP_User(); // Currently displayed user 
  215.  
  216. /** Misc **************************************************************/ 
  217.  
  218. $this->domain = 'bbpress'; // Unique identifier for retrieving translated strings 
  219. $this->extend = new stdClass(); // Plugins add data here 
  220. $this->errors = new WP_Error(); // Feedback 
  221. $this->tab_index = apply_filters( 'bbp_default_tab_index', 100 ); 
  222.  
  223. /** 
  224. * Include required files 
  225. * @since bbPress (r2626) 
  226. * @access private 
  227. * @uses is_admin() If in WordPress admin, load additional file 
  228. */ 
  229. private function includes() { 
  230.  
  231. /** Core **************************************************************/ 
  232.  
  233. require( $this->includes_dir . 'core/sub-actions.php' ); 
  234. require( $this->includes_dir . 'core/functions.php' ); 
  235. require( $this->includes_dir . 'core/cache.php' ); 
  236. require( $this->includes_dir . 'core/options.php' ); 
  237. require( $this->includes_dir . 'core/capabilities.php' ); 
  238. require( $this->includes_dir . 'core/update.php' ); 
  239. require( $this->includes_dir . 'core/template-functions.php' ); 
  240. require( $this->includes_dir . 'core/template-loader.php' ); 
  241. require( $this->includes_dir . 'core/theme-compat.php' ); 
  242.  
  243. /** Components ********************************************************/ 
  244.  
  245. // Common 
  246. require( $this->includes_dir . 'common/ajax.php' ); 
  247. require( $this->includes_dir . 'common/classes.php' ); 
  248. require( $this->includes_dir . 'common/functions.php' ); 
  249. require( $this->includes_dir . 'common/formatting.php' ); 
  250. require( $this->includes_dir . 'common/template.php' ); 
  251. require( $this->includes_dir . 'common/widgets.php' ); 
  252. require( $this->includes_dir . 'common/shortcodes.php' ); 
  253.  
  254. // Forums 
  255. require( $this->includes_dir . 'forums/capabilities.php' ); 
  256. require( $this->includes_dir . 'forums/functions.php' ); 
  257. require( $this->includes_dir . 'forums/template.php' ); 
  258.  
  259. // Topics 
  260. require( $this->includes_dir . 'topics/capabilities.php' ); 
  261. require( $this->includes_dir . 'topics/functions.php' ); 
  262. require( $this->includes_dir . 'topics/template.php' ); 
  263.  
  264. // Replies 
  265. require( $this->includes_dir . 'replies/capabilities.php' ); 
  266. require( $this->includes_dir . 'replies/functions.php' ); 
  267. require( $this->includes_dir . 'replies/template.php' ); 
  268.  
  269. // Search 
  270. require( $this->includes_dir . 'search/functions.php' ); 
  271. require( $this->includes_dir . 'search/template.php' ); 
  272.  
  273. // Users 
  274. require( $this->includes_dir . 'users/capabilities.php' ); 
  275. require( $this->includes_dir . 'users/functions.php' ); 
  276. require( $this->includes_dir . 'users/template.php' ); 
  277. require( $this->includes_dir . 'users/options.php' ); 
  278.  
  279. /** Hooks *************************************************************/ 
  280.  
  281. require( $this->includes_dir . 'core/extend.php' ); 
  282. require( $this->includes_dir . 'core/actions.php' ); 
  283. require( $this->includes_dir . 'core/filters.php' ); 
  284.  
  285. /** Admin *************************************************************/ 
  286.  
  287. // Quick admin check and load if needed 
  288. if ( is_admin() ) { 
  289. require( $this->includes_dir . 'admin/admin.php' ); 
  290. require( $this->includes_dir . 'admin/actions.php' ); 
  291.  
  292. /** 
  293. * Setup the default hooks and actions 
  294. * @since bbPress (r2644) 
  295. * @access private 
  296. * @uses add_action() To add various actions 
  297. */ 
  298. private function setup_actions() { 
  299.  
  300. // Add actions to plugin activation and deactivation hooks 
  301. add_action( 'activate_' . $this->basename, 'bbp_activation' ); 
  302. add_action( 'deactivate_' . $this->basename, 'bbp_deactivation' ); 
  303.  
  304. // If bbPress is being deactivated, do not add any actions 
  305. if ( bbp_is_deactivation( $this->basename ) ) 
  306. return; 
  307.  
  308. // Array of bbPress core actions 
  309. $actions = array( 
  310. 'setup_theme', // Setup the default theme compat 
  311. 'setup_current_user', // Setup currently logged in user 
  312. 'register_post_types', // Register post types (forum|topic|reply) 
  313. 'register_post_statuses', // Register post statuses (closed|spam|orphan|hidden) 
  314. 'register_taxonomies', // Register taxonomies (topic-tag) 
  315. 'register_shortcodes', // Register shortcodes (bbp-login) 
  316. 'register_views', // Register the views (no-replies) 
  317. 'register_theme_packages', // Register bundled theme packages (bbp-theme-compat/bbp-themes) 
  318. 'load_textdomain', // Load textdomain (bbpress) 
  319. 'add_rewrite_tags', // Add rewrite tags (view|user|edit|search) 
  320. 'add_rewrite_rules', // Generate rewrite rules (view|edit|paged|search) 
  321. 'add_permastructs' // Add permalink structures (view|user|search) 
  322. ); 
  323.  
  324. // Add the actions 
  325. foreach ( $actions as $class_action ) 
  326. add_action( 'bbp_' . $class_action, array( $this, $class_action ), 5 ); 
  327.  
  328. // All bbPress actions are setup (includes bbp-core-hooks.php) 
  329. do_action_ref_array( 'bbp_after_setup_actions', array( &$this ) ); 
  330.  
  331. /** Public Methods ********************************************************/ 
  332.  
  333. /** 
  334. * Register bundled theme packages 
  335. * Note that since we currently have complete control over bbp-themes and 
  336. * the bbp-theme-compat folders, it's fine to hardcode these here. If at a 
  337. * later date we need to automate this, and API will need to be built. 
  338. * @since bbPress (r3829) 
  339. */ 
  340. public function register_theme_packages() { 
  341.  
  342. // Register the default theme compatibility package 
  343. bbp_register_theme_package( array( 
  344. 'id' => 'default',  
  345. 'name' => __( 'bbPress Default', 'bbpress' ),  
  346. 'version' => bbp_get_version(),  
  347. 'dir' => trailingslashit( $this->themes_dir . 'default' ),  
  348. 'url' => trailingslashit( $this->themes_url . 'default' ) 
  349. ) ); 
  350.  
  351. // Register the basic theme stack. This is really dope. 
  352. bbp_register_template_stack( 'get_stylesheet_directory', 10 ); 
  353. bbp_register_template_stack( 'get_template_directory', 12 ); 
  354. bbp_register_template_stack( 'bbp_get_theme_compat_dir', 14 ); 
  355.  
  356. /** 
  357. * Setup the default bbPress theme compatibility location. 
  358. * @since bbPress (r3778) 
  359. */ 
  360. public function setup_theme() { 
  361.  
  362. // Bail if something already has this under control 
  363. if ( ! empty( $this->theme_compat->theme ) ) 
  364. return; 
  365.  
  366. // Setup the theme package to use for compatibility 
  367. bbp_setup_theme_compat( bbp_get_theme_package_id() ); 
  368.  
  369. /** 
  370. * Load the translation file for current language. Checks the languages 
  371. * folder inside the bbPress plugin first, and then the default WordPress 
  372. * languages folder. 
  373. * Note that custom translation files inside the bbPress plugin folder 
  374. * will be removed on bbPress updates. If you're creating custom 
  375. * translation files, please use the global language folder. 
  376. * @since bbPress (r2596) 
  377. * @uses apply_filters() Calls 'plugin_locale' with {@link get_locale()} value 
  378. * @uses load_textdomain() To load the textdomain 
  379. */ 
  380. public function load_textdomain() { 
  381.  
  382. // Traditional WordPress plugin locale filter 
  383. $locale = apply_filters( 'plugin_locale', get_locale(), $this->domain ); 
  384. $mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale ); 
  385.  
  386. // Setup paths to current locale file 
  387. $mofile_local = $this->lang_dir . $mofile; 
  388. $mofile_global = WP_LANG_DIR . '/bbpress/' . $mofile; 
  389.  
  390. // Look in global /wp-content/languages/bbpress folder 
  391. load_textdomain( $this->domain, $mofile_global ); 
  392.  
  393. // Look in local /wp-content/plugins/bbpress/bbp-languages/ folder 
  394. load_textdomain( $this->domain, $mofile_local ); 
  395.  
  396. // Look in global /wp-content/languages/plugins/ 
  397. load_plugin_textdomain( $this->domain ); 
  398.  
  399. /** 
  400. * Setup the post types for forums, topics and replies 
  401. * @since bbPress (r2597) 
  402. * @uses register_post_type() To register the post types 
  403. * @uses apply_filters() Calls various filters to modify the arguments 
  404. * sent to register_post_type() 
  405. */ 
  406. public static function register_post_types() { 
  407.  
  408. /** Forums ************************************************************/ 
  409.  
  410. // Register Forum content type 
  411. register_post_type( 
  412. bbp_get_forum_post_type(),  
  413. apply_filters( 'bbp_register_forum_post_type', array( 
  414. 'labels' => bbp_get_forum_post_type_labels(),  
  415. 'rewrite' => bbp_get_forum_post_type_rewrite(),  
  416. 'supports' => bbp_get_forum_post_type_supports(),  
  417. 'description' => __( 'bbPress Forums', 'bbpress' ),  
  418. 'capabilities' => bbp_get_forum_caps(),  
  419. 'capability_type' => array( 'forum', 'forums' ),  
  420. 'menu_position' => 555555,  
  421. 'has_archive' => bbp_get_root_slug(),  
  422. 'exclude_from_search' => true,  
  423. 'show_in_nav_menus' => true,  
  424. 'public' => true,  
  425. 'show_ui' => current_user_can( 'bbp_forums_admin' ),  
  426. 'can_export' => true,  
  427. 'hierarchical' => true,  
  428. 'query_var' => true,  
  429. 'menu_icon' => '' 
  430. ) ) 
  431. ); 
  432.  
  433. /** Topics ************************************************************/ 
  434.  
  435. // Register Topic content type 
  436. register_post_type( 
  437. bbp_get_topic_post_type(),  
  438. apply_filters( 'bbp_register_topic_post_type', array( 
  439. 'labels' => bbp_get_topic_post_type_labels(),  
  440. 'rewrite' => bbp_get_topic_post_type_rewrite(),  
  441. 'supports' => bbp_get_topic_post_type_supports(),  
  442. 'description' => __( 'bbPress Topics', 'bbpress' ),  
  443. 'capabilities' => bbp_get_topic_caps(),  
  444. 'capability_type' => array( 'topic', 'topics' ),  
  445. 'menu_position' => 555555,  
  446. 'has_archive' => ( 'forums' === bbp_show_on_root() ) ? bbp_get_topic_archive_slug() : false,  
  447. 'exclude_from_search' => true,  
  448. 'show_in_nav_menus' => false,  
  449. 'public' => true,  
  450. 'show_ui' => current_user_can( 'bbp_topics_admin' ),  
  451. 'can_export' => true,  
  452. 'hierarchical' => false,  
  453. 'query_var' => true,  
  454. 'menu_icon' => '' 
  455. ) ); 
  456.  
  457. /** Replies ***********************************************************/ 
  458.  
  459. // Register reply content type 
  460. register_post_type( 
  461. bbp_get_reply_post_type(),  
  462. apply_filters( 'bbp_register_reply_post_type', array( 
  463. 'labels' => bbp_get_reply_post_type_labels(),  
  464. 'rewrite' => bbp_get_reply_post_type_rewrite(),  
  465. 'supports' => bbp_get_reply_post_type_supports(),  
  466. 'description' => __( 'bbPress Replies', 'bbpress' ),  
  467. 'capabilities' => bbp_get_reply_caps(),  
  468. 'capability_type' => array( 'reply', 'replies' ),  
  469. 'menu_position' => 555555,  
  470. 'exclude_from_search' => true,  
  471. 'has_archive' => false,  
  472. 'show_in_nav_menus' => false,  
  473. 'public' => true,  
  474. 'show_ui' => current_user_can( 'bbp_replies_admin' ),  
  475. 'can_export' => true,  
  476. 'hierarchical' => false,  
  477. 'query_var' => true,  
  478. 'menu_icon' => '' 
  479. ) ) 
  480. ); 
  481.  
  482. /** 
  483. * Register the post statuses used by bbPress 
  484. * We do some manipulation of the 'trash' status so trashed topics and 
  485. * replies can be viewed from within the theme. 
  486. * @since bbPress (r2727) 
  487. * @uses register_post_status() To register post statuses 
  488. * @uses $wp_post_statuses To modify trash and private statuses 
  489. * @uses current_user_can() To check if the current user is capable & 
  490. * modify $wp_post_statuses accordingly 
  491. */ 
  492. public static function register_post_statuses() { 
  493.  
  494. // Closed 
  495. register_post_status( 
  496. bbp_get_closed_status_id(),  
  497. apply_filters( 'bbp_register_closed_post_status', array( 
  498. 'label' => _x( 'Closed', 'post', 'bbpress' ),  
  499. 'label_count' => _nx_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'post', 'bbpress' ),  
  500. 'public' => true,  
  501. 'show_in_admin_all' => true 
  502. ) ) 
  503. ); 
  504.  
  505. // Spam 
  506. register_post_status( 
  507. bbp_get_spam_status_id(),  
  508. apply_filters( 'bbp_register_spam_post_status', array( 
  509. 'label' => _x( 'Spam', 'post', 'bbpress' ),  
  510. 'label_count' => _nx_noop( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'post', 'bbpress' ),  
  511. 'protected' => true,  
  512. 'exclude_from_search' => true,  
  513. 'show_in_admin_status_list' => true,  
  514. 'show_in_admin_all_list' => false 
  515. ) ) 
  516. ); 
  517.  
  518. // Orphan 
  519. register_post_status( 
  520. bbp_get_orphan_status_id(),  
  521. apply_filters( 'bbp_register_orphan_post_status', array( 
  522. 'label' => _x( 'Orphan', 'post', 'bbpress' ),  
  523. 'label_count' => _nx_noop( 'Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'post', 'bbpress' ),  
  524. 'protected' => true,  
  525. 'exclude_from_search' => true,  
  526. 'show_in_admin_status_list' => true,  
  527. 'show_in_admin_all_list' => false 
  528. ) ) 
  529. ); 
  530.  
  531. // Hidden 
  532. register_post_status( 
  533. bbp_get_hidden_status_id(),  
  534. apply_filters( 'bbp_register_hidden_post_status', array( 
  535. 'label' => _x( 'Hidden', 'post', 'bbpress' ),  
  536. 'label_count' => _nx_noop( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'post', 'bbpress' ),  
  537. 'private' => true,  
  538. 'exclude_from_search' => true,  
  539. 'show_in_admin_status_list' => true,  
  540. 'show_in_admin_all_list' => true 
  541. ) ) 
  542. ); 
  543.  
  544. /** 
  545. * Trash fix 
  546. * We need to remove the internal arg and change that to 
  547. * protected so that the users with 'view_trash' cap can view 
  548. * single trashed topics/replies in the front-end as wp_query 
  549. * doesn't allow any hack for the trashed topics to be viewed. 
  550. */ 
  551. global $wp_post_statuses; 
  552.  
  553. if ( !empty( $wp_post_statuses['trash'] ) ) { 
  554.  
  555. // User can view trash so set internal to false 
  556. if ( current_user_can( 'view_trash' ) ) { 
  557. $wp_post_statuses['trash']->internal = false; 
  558. $wp_post_statuses['trash']->protected = true; 
  559.  
  560. // User cannot view trash so set internal to true 
  561. } else { 
  562. $wp_post_statuses['trash']->internal = true; 
  563.  
  564. /** 
  565. * Register the topic tag taxonomy 
  566. * @since bbPress (r2464) 
  567. * @uses register_taxonomy() To register the taxonomy 
  568. */ 
  569. public static function register_taxonomies() { 
  570.  
  571. // Register the topic-tag taxonomy 
  572. register_taxonomy( 
  573. bbp_get_topic_tag_tax_id(),  
  574. bbp_get_topic_post_type(),  
  575. apply_filters( 'bbp_register_topic_taxonomy', array( 
  576. 'labels' => bbp_get_topic_tag_tax_labels(),  
  577. 'rewrite' => bbp_get_topic_tag_tax_rewrite(),  
  578. 'capabilities' => bbp_get_topic_tag_caps(),  
  579. 'update_count_callback' => '_update_post_term_count',  
  580. 'query_var' => true,  
  581. 'show_tagcloud' => true,  
  582. 'hierarchical' => false,  
  583. 'show_in_nav_menus' => false,  
  584. 'public' => true,  
  585. 'show_ui' => bbp_allow_topic_tags() && current_user_can( 'bbp_topic_tags_admin' ) 
  586. ) ); 
  587.  
  588. /** 
  589. * Register the bbPress views 
  590. * @since bbPress (r2789) 
  591. * @uses bbp_register_view() To register the views 
  592. */ 
  593. public static function register_views() { 
  594.  
  595. // Popular topics 
  596. bbp_register_view( 
  597. 'popular',  
  598. __( 'Most popular topics', 'bbpress' ),  
  599. apply_filters( 'bbp_register_view_popular', array( 
  600. 'meta_key' => '_bbp_reply_count',  
  601. 'max_num_pages' => 1,  
  602. 'orderby' => 'meta_value_num',  
  603. 'show_stickies' => false 
  604. ) ); 
  605.  
  606. // Topics with no replies 
  607. bbp_register_view( 
  608. 'no-replies',  
  609. __( 'Topics with no replies', 'bbpress' ),  
  610. apply_filters( 'bbp_register_view_no_replies', array( 
  611. 'meta_key' => '_bbp_reply_count',  
  612. 'meta_value' => 1,  
  613. 'meta_compare' => '<',  
  614. 'orderby' => '',  
  615. 'show_stickies' => false 
  616. ) ); 
  617.  
  618. /** 
  619. * Register the bbPress shortcodes 
  620. * @since bbPress (r3031) 
  621. * @uses BBP_Shortcodes 
  622. */ 
  623. public function register_shortcodes() { 
  624. $this->shortcodes = new BBP_Shortcodes(); 
  625.  
  626. /** 
  627. * Setup the currently logged-in user 
  628. * Do not to call this prematurely, I.E. before the 'init' action has 
  629. * started. This function is naturally hooked into 'init' to ensure proper 
  630. * execution. get_currentuserinfo() is used to check for XMLRPC_REQUEST to 
  631. * avoid xmlrpc errors. 
  632. * @since bbPress (r2697) 
  633. * @uses wp_get_current_user() 
  634. */ 
  635. public function setup_current_user() { 
  636. $this->current_user = wp_get_current_user(); 
  637.  
  638. /** Custom Rewrite Rules **************************************************/ 
  639.  
  640. /** 
  641. * Add the bbPress-specific rewrite tags 
  642. * @since bbPress (r2753) 
  643. * @uses add_rewrite_tag() To add the rewrite tags 
  644. */ 
  645. public static function add_rewrite_tags() { 
  646. add_rewrite_tag( '%' . bbp_get_view_rewrite_id() . '%', '([^/]+)' ); // View Page tag 
  647. add_rewrite_tag( '%' . bbp_get_edit_rewrite_id() . '%', '([1]{1, })' ); // Edit Page tag 
  648. add_rewrite_tag( '%' . bbp_get_search_rewrite_id() . '%', '([^/]+)' ); // Search Results tag 
  649. add_rewrite_tag( '%' . bbp_get_user_rewrite_id() . '%', '([^/]+)' ); // User Profile tag 
  650. add_rewrite_tag( '%' . bbp_get_user_favorites_rewrite_id() . '%', '([1]{1, })' ); // User Favorites tag 
  651. add_rewrite_tag( '%' . bbp_get_user_subscriptions_rewrite_id() . '%', '([1]{1, })' ); // User Subscriptions tag 
  652. add_rewrite_tag( '%' . bbp_get_user_topics_rewrite_id() . '%', '([1]{1, })' ); // User Topics Tag 
  653. add_rewrite_tag( '%' . bbp_get_user_replies_rewrite_id() . '%', '([1]{1, })' ); // User Replies Tag 
  654.  
  655. /** 
  656. * Add bbPress-specific rewrite rules for uri's that are not 
  657. * setup for us by way of custom post types or taxonomies. This includes: 
  658. * - Front-end editing 
  659. * - Topic views 
  660. * - User profiles 
  661. * @since bbPress (r2688) 
  662. * @todo Extract into an API 
  663. */ 
  664. public static function add_rewrite_rules() { 
  665.  
  666. /** Setup *************************************************************/ 
  667.  
  668. // Add rules to top or bottom? 
  669. $priority = 'top'; 
  670.  
  671. // Single Slugs 
  672. $forum_slug = bbp_get_forum_slug(); 
  673. $topic_slug = bbp_get_topic_slug(); 
  674. $reply_slug = bbp_get_reply_slug(); 
  675. $ttag_slug = bbp_get_topic_tag_tax_slug(); 
  676.  
  677. // Archive Slugs 
  678. $user_slug = bbp_get_user_slug(); 
  679. $view_slug = bbp_get_view_slug(); 
  680. $search_slug = bbp_get_search_slug(); 
  681. $topic_archive_slug = bbp_get_topic_archive_slug(); 
  682. $reply_archive_slug = bbp_get_reply_archive_slug(); 
  683.  
  684. // Tertiary Slugs 
  685. $feed_slug = 'feed'; 
  686. $edit_slug = 'edit'; 
  687. $paged_slug = bbp_get_paged_slug(); 
  688. $user_favs_slug = bbp_get_user_favorites_slug(); 
  689. $user_subs_slug = bbp_get_user_subscriptions_slug(); 
  690.  
  691. // Unique rewrite ID's 
  692. $feed_id = 'feed'; 
  693. $edit_id = bbp_get_edit_rewrite_id(); 
  694. $view_id = bbp_get_view_rewrite_id(); 
  695. $paged_id = bbp_get_paged_rewrite_id(); 
  696. $search_id = bbp_get_search_rewrite_id(); 
  697. $user_id = bbp_get_user_rewrite_id(); 
  698. $user_favs_id = bbp_get_user_favorites_rewrite_id(); 
  699. $user_subs_id = bbp_get_user_subscriptions_rewrite_id(); 
  700. $user_tops_id = bbp_get_user_topics_rewrite_id(); 
  701. $user_reps_id = bbp_get_user_replies_rewrite_id(); 
  702.  
  703. // Rewrite rule matches used repeatedly below 
  704. $root_rule = '/([^/]+)/?$'; 
  705. $feed_rule = '/([^/]+)/' . $feed_slug . '/?$'; 
  706. $edit_rule = '/([^/]+)/' . $edit_slug . '/?$'; 
  707. $paged_rule = '/([^/]+)/' . $paged_slug . '/?([0-9]{1, })/?$'; 
  708.  
  709. // Search rules (without slug check) 
  710. $search_root_rule = '/?$'; 
  711. $search_paged_rule = '/' . $paged_slug . '/?([0-9]{1, })/?$'; 
  712.  
  713. /** Add ***************************************************************/ 
  714.  
  715. // User profile rules 
  716. $tops_rule = '/([^/]+)/' . $topic_archive_slug . '/?$'; 
  717. $reps_rule = '/([^/]+)/' . $reply_archive_slug . '/?$'; 
  718. $favs_rule = '/([^/]+)/' . $user_favs_slug . '/?$'; 
  719. $subs_rule = '/([^/]+)/' . $user_subs_slug . '/?$'; 
  720. $tops_paged_rule = '/([^/]+)/' . $topic_archive_slug . '/' . $paged_slug . '/?([0-9]{1, })/?$'; 
  721. $reps_paged_rule = '/([^/]+)/' . $reply_archive_slug . '/' . $paged_slug . '/?([0-9]{1, })/?$'; 
  722. $favs_paged_rule = '/([^/]+)/' . $user_favs_slug . '/' . $paged_slug . '/?([0-9]{1, })/?$'; 
  723. $subs_paged_rule = '/([^/]+)/' . $user_subs_slug . '/' . $paged_slug . '/?([0-9]{1, })/?$'; 
  724.  
  725. // Edit Forum|Topic|Reply|Topic-tag 
  726. add_rewrite_rule( $forum_slug . $edit_rule, 'index.php?' . bbp_get_forum_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority ); 
  727. add_rewrite_rule( $topic_slug . $edit_rule, 'index.php?' . bbp_get_topic_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority ); 
  728. add_rewrite_rule( $reply_slug . $edit_rule, 'index.php?' . bbp_get_reply_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority ); 
  729. add_rewrite_rule( $ttag_slug . $edit_rule, 'index.php?' . bbp_get_topic_tag_tax_id() . '=$matches[1]&' . $edit_id . '=1', $priority ); 
  730.  
  731. // User Pagination|Edit|View 
  732. add_rewrite_rule( $user_slug . $tops_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1&' . $paged_id . '=$matches[2]', $priority ); 
  733. add_rewrite_rule( $user_slug . $reps_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1&' . $paged_id . '=$matches[2]', $priority ); 
  734. add_rewrite_rule( $user_slug . $favs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1&' . $paged_id . '=$matches[2]', $priority ); 
  735. add_rewrite_rule( $user_slug . $subs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1&' . $paged_id . '=$matches[2]', $priority ); 
  736. add_rewrite_rule( $user_slug . $tops_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1', $priority ); 
  737. add_rewrite_rule( $user_slug . $reps_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1', $priority ); 
  738. add_rewrite_rule( $user_slug . $favs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1', $priority ); 
  739. add_rewrite_rule( $user_slug . $subs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1', $priority ); 
  740. add_rewrite_rule( $user_slug . $edit_rule, 'index.php?' . $user_id . '=$matches[1]&' . $edit_id . '=1', $priority ); 
  741. add_rewrite_rule( $user_slug . $root_rule, 'index.php?' . $user_id . '=$matches[1]', $priority ); 
  742.  
  743. // Topic-View Pagination|Feed|View 
  744. add_rewrite_rule( $view_slug . $paged_rule, 'index.php?' . $view_id . '=$matches[1]&' . $paged_id . '=$matches[2]', $priority ); 
  745. add_rewrite_rule( $view_slug . $feed_rule, 'index.php?' . $view_id . '=$matches[1]&' . $feed_id . '=$matches[2]', $priority ); 
  746. add_rewrite_rule( $view_slug . $root_rule, 'index.php?' . $view_id . '=$matches[1]', $priority ); 
  747.  
  748. // Search All 
  749. add_rewrite_rule( $search_slug . $search_paged_rule, 'index.php?' . $paged_id .'=$matches[1]', $priority ); 
  750. add_rewrite_rule( $search_slug . $search_root_rule, 'index.php?' . $search_id, $priority ); 
  751.  
  752. /** 
  753. * Add permalink structures for new archive-style destinations. 
  754. * - Users 
  755. * - Topic Views 
  756. * - Search 
  757. * @since bbPress (r4930) 
  758. */ 
  759. public static function add_permastructs() { 
  760.  
  761. // Get unique ID's 
  762. $user_id = bbp_get_user_rewrite_id(); 
  763. $view_id = bbp_get_view_rewrite_id(); 
  764. $search_id = bbp_get_search_rewrite_id(); 
  765.  
  766. // Get root slugs 
  767. $user_slug = bbp_get_user_slug(); 
  768. $view_slug = bbp_get_view_slug(); 
  769. $search_slug = bbp_get_search_slug(); 
  770.  
  771. // User Permastruct 
  772. add_permastruct( $user_id, $user_slug . '/%' . $user_id . '%', array( 
  773. 'with_front' => false,  
  774. 'ep_mask' => EP_NONE,  
  775. 'paged' => false,  
  776. 'feed' => false,  
  777. 'forcomments' => false,  
  778. 'walk_dirs' => true,  
  779. 'endpoints' => false,  
  780. ) ); 
  781.  
  782. // Topic View Permastruct 
  783. add_permastruct( $view_id, $view_slug . '/%' . $view_id . '%', array( 
  784. 'with_front' => false,  
  785. 'ep_mask' => EP_NONE,  
  786. 'paged' => false,  
  787. 'feed' => false,  
  788. 'forcomments' => false,  
  789. 'walk_dirs' => true,  
  790. 'endpoints' => false,  
  791. ) ); 
  792.  
  793. // Search Permastruct 
  794. add_permastruct( $user_id, $search_slug . '/%' . $search_id . '%', array( 
  795. 'with_front' => false,  
  796. 'ep_mask' => EP_NONE,  
  797. 'paged' => true,  
  798. 'feed' => false,  
  799. 'forcomments' => false,  
  800. 'walk_dirs' => true,  
  801. 'endpoints' => false,  
  802. ) );