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