PluginProbe
bbPress / 2.6.6
bbPress v2.6.6
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
← All changes | bbpress.php +774 -687 2.02.6.6 View file →
@@ -4,479 +4,391 @@
4 4 * The bbPress Plugin
5 5 *
6 6 * bbPress is forum software with a twist from the creators of WordPress.
7 7 *
8 + * $Id: bbpress.php 7161 2020-11-06 01:05:46Z johnjamesjacoby $
9 + *
8 10 * @package bbPress
9 11 * @subpackage Main
10 12 */
11 13
12 14 /**
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/
15 + * Plugin Name: bbPress
16 + * Plugin URI: https://bbpress.org
17 + * Description: bbPress is forum software with a twist from the creators of WordPress.
18 + * Author: The bbPress Contributors
19 + * Author URI: https://bbpress.org
20 + * Version: 2.6.6
21 + * Text Domain: bbpress
22 + * Domain Path: /languages/
23 + * License: GPLv2 or later (license.txt)
24 + * Requires PHP: 5.6.20
25 + * Requires at least: 5.0
21 26 */
22 27
23 28 // Exit if accessed directly
24 -if ( !defined( 'ABSPATH' ) ) exit;
29 +defined( 'ABSPATH' ) || exit;
25 30
26 -if ( !class_exists( 'bbPress' ) ) :
31 +if ( ! class_exists( 'bbPress' ) ) :
27 32 /**
28 33 * Main bbPress Class
29 34 *
30 - * Tap tap tap... Is this thing on?
35 + * "Word hard. Stay bumble."
31 36 *
32 - * @since bbPress (r2464)
37 + * @since 2.0.0 bbPress (r2464)
33 38 */
34 -class bbPress {
39 +final class bbPress {
35 40
41 + /** Magic *****************************************************************/
42 +
36 43 /**
37 - * Note to Plugin and Theme authors:
44 + * bbPress uses many variables, several of which can be filtered to
45 + * customize the way it operates. Most of these variables are stored in a
46 + * private array that gets updated with the help of PHP magic methods.
38 47 *
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.
48 + * This is a precautionary measure, to avoid potential errors produced by
49 + * unanticipated direct manipulation of run-time data.
41 50 *
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.
51 + * @see bbPress::setup_globals()
52 + * @var array
44 53 */
54 + private $data;
45 55
46 - /** Version ***************************************************************/
56 + /** Not Magic *************************************************************/
47 57
48 58 /**
49 - * @public string bbPress version
59 + * @var mixed False when not logged in; WP_User object when logged in
50 60 */
51 - public $version = '2.0';
61 + public $current_user = false;
52 62
53 63 /**
54 - * @public string bbPress DB version
64 + * @var stdClass Add-ons append to this (Akismet, BuddyPress, etc...)
55 65 */
56 - public $db_version = '200';
66 + public $extend;
57 67
58 - /** Post types ************************************************************/
59 -
60 68 /**
61 - * @public string Forum post type id
69 + * @var array Topic views
62 70 */
63 - public $forum_post_type = '';
71 + public $views = array();
64 72
65 73 /**
66 - * @public string Topic post type id
74 + * @var array Overloads get_option()
67 75 */
68 - public $topic_post_type = '';
76 + public $options = array();
69 77
70 78 /**
71 - * @ string Reply post type id
79 + * @var array Storage of options not in the database
72 80 */
73 - public $reply_post_type = '';
81 + public $not_options = array();
74 82
75 - /** Taxonomies ************************************************************/
76 -
77 83 /**
78 - * @public string Topic tag id
84 + * @var array Overloads get_user_meta()
79 85 */
80 - public $topic_tag_tax_id = '';
86 + public $user_options = array();
81 87
82 - /** Permastructs **********************************************************/
83 -
84 88 /**
85 - * @public string User struct
89 + * @var array Dynamically initialized user roles
86 90 */
87 - public $user_id = '';
91 + public $roles = array();
88 92
89 - /**
90 - * @public string View struct
91 - */
92 - public $view_id = '';
93 + /** Singleton *************************************************************/
93 94
94 95 /**
95 - * @public string Edit struct
96 + * Main bbPress Instance
97 + *
98 + * bbPress is fun
99 + * Please load it only one time
100 + * For this, we thank you
101 + *
102 + * Insures that only one instance of bbPress exists in memory at any one
103 + * time. Also prevents needing to define globals all over the place.
104 + *
105 + * @since 2.1.0 bbPress (r3757)
106 + *
107 + * @staticvar object $instance
108 + * @see bbpress()
109 + * @return bbPress The one true bbPress
96 110 */
97 - public $edit_id = '';
111 + public static function instance() {
98 112
99 - /** Post statuses *********************************************************/
113 + // Store the instance locally to avoid private static replication
114 + static $instance = null;
100 115
101 - /**
102 - * @public string Closed post status id. Used by topics.
103 - */
104 - public $closed_status_id = '';
116 + // Only run these methods if they haven't been ran previously
117 + if ( null === $instance ) {
118 + $instance = new bbPress();
119 + $instance->setup_environment();
120 + $instance->includes();
121 + $instance->setup_variables();
122 + $instance->setup_actions();
123 + }
105 124
106 - /**
107 - * @public string Spam post status id. Used by topics and replies.
108 - */
109 - public $spam_status_id = '';
125 + // Always return the instance
126 + return $instance;
127 + }
110 128
111 - /**
112 - * @public string Trash post status id. Used by topics and replies.
113 - */
114 - public $trash_status_id = '';
129 + /** Magic Methods *********************************************************/
115 130
116 131 /**
117 - * @public string Orphan post status id. Used by topics and replies.
132 + * A dummy constructor to prevent bbPress from being loaded more than once.
133 + *
134 + * @since 2.0.0 bbPress (r2464)
135 + *
136 + * @see bbPress::instance()
137 + * @see bbpress();
118 138 */
119 - public $orphan_status_id = '';
139 + private function __construct() { /* Do nothing here */ }
120 140
121 141 /**
122 - * @public string Hidden post status id. Used by forums.
142 + * A dummy magic method to prevent bbPress from being cloned
143 + *
144 + * @since 2.0.0 bbPress (r2464)
123 145 */
124 - public $hidden_status_id = '';
146 + public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bbpress' ), '2.1' ); }
125 147
126 - /** Slugs *****************************************************************/
127 -
128 148 /**
129 - * @public string Root slug
149 + * A dummy magic method to prevent bbPress from being unserialized
150 + *
151 + * @since 2.0.0 bbPress (r2464)
130 152 */
131 - public $root_slug = '';
153 + public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bbpress' ), '2.1' ); }
132 154
133 155 /**
134 - * @public string Forum slug
156 + * Magic method for checking the existence of a certain custom field
157 + *
158 + * @since 2.1.0 bbPress (r3951)
135 159 */
136 - public $forum_slug = '';
160 + public function __isset( $key ) { return isset( $this->data[ $key ] ); }
137 161
138 162 /**
139 - * @public string Topic slug
163 + * Magic method for getting bbPress variables
164 + *
165 + * @since 2.1.0 bbPress (r3951)
140 166 */
141 - public $topic_slug = '';
167 + public function __get( $key ) { return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null; }
142 168
143 169 /**
144 - * @public string Topic archive slug
170 + * Magic method for setting bbPress variables
171 + *
172 + * @since 2.1.0 bbPress (r3951)
145 173 */
146 - public $topic_archive_slug = '';
174 + public function __set( $key , $value ) { $this->data[ $key ] = $value; }
147 175
148 176 /**
149 - * @public string Reply slug
177 + * Magic method for unsetting bbPress variables
178 + *
179 + * @since 2.3.0 bbPress (r4628)
150 180 */
151 - public $reply_slug = '';
181 + public function __unset( $key ) {
182 + if ( isset( $this->data[ $key ] ) ) {
183 + unset( $this->data[ $key ] );
184 + }
185 + }
152 186
153 187 /**
154 - * @public string Topic tag slug
188 + * Magic method to prevent notices and errors from invalid method calls
189 + *
190 + * @since 2.2.0 bbPress (r4252)
155 191 */
156 - public $topic_tag_slug = '';
192 + public function __call( $name = '', $args = array() ) { unset( $name, $args ); return null; }
157 193
158 - /**
159 - * @public string User slug
160 - */
161 - public $user_slug = '';
194 + /** Private Methods *******************************************************/
162 195
163 196 /**
164 - * @public string View slug
197 + * Setup the environment variables to allow the rest of bbPress to function
198 + * more easily.
199 + *
200 + * @since 2.0.0 bbPress (r2626)
201 + *
202 + * @access private
165 203 */
166 - public $view_slug = '';
204 + private function setup_environment() {
167 205
168 - /** Paths *****************************************************************/
206 + /** Versions **********************************************************/
169 207
170 - /**
171 - * @public string Basename of the bbPress plugin directory
172 - */
173 - public $basename = '';
208 + $this->version = '2.6.6';
209 + $this->db_version = '263';
174 210
175 - /**
176 - * @public string Absolute path to the bbPress plugin directory
177 - */
178 - public $plugin_dir = '';
211 + /** Paths *************************************************************/
179 212
180 - /**
181 - * @public string Absolute path to the bbPress themes directory
182 - */
183 - public $themes_dir = '';
213 + // File & base
214 + $this->file = __FILE__;
215 + $this->basename = apply_filters( 'bbp_plugin_basename', str_replace( array( 'build/', 'src/' ), '', plugin_basename( $this->file ) ) );
216 + $this->basepath = apply_filters( 'bbp_plugin_basepath', trailingslashit( dirname( $this->basename ) ) );
184 217
185 - /**
186 - * @public string Absolute path to the bbPress language directory
187 - */
188 - public $lang_dir = '';
218 + // Path and URL
219 + $this->plugin_dir = apply_filters( 'bbp_plugin_dir_path', plugin_dir_path( $this->file ) );
220 + $this->plugin_url = apply_filters( 'bbp_plugin_dir_url', plugin_dir_url ( $this->file ) );
189 221
190 - /** URLs ******************************************************************/
222 + // Includes
223 + $this->includes_dir = apply_filters( 'bbp_includes_dir', trailingslashit( $this->plugin_dir . 'includes' ) );
224 + $this->includes_url = apply_filters( 'bbp_includes_url', trailingslashit( $this->plugin_url . 'includes' ) );
191 225
192 - /**
193 - * @public string URL to the bbPress plugin directory
194 - */
195 - public $plugin_url = '';
226 + // Languages
227 + $this->lang_base = apply_filters( 'bbp_lang_base', trailingslashit( $this->basepath . 'languages' ) );
228 + $this->lang_dir = apply_filters( 'bbp_lang_dir', trailingslashit( $this->plugin_dir . 'languages' ) );
196 229
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();
230 + // Templates
231 + $this->themes_dir = apply_filters( 'bbp_themes_dir', trailingslashit( $this->plugin_dir . 'templates' ) );
232 + $this->themes_url = apply_filters( 'bbp_themes_url', trailingslashit( $this->plugin_url . 'templates' ) );
308 233 }
309 234
310 235 /**
311 - * The main bbPress loader
236 + * Smart defaults to many bbPress specific class variables.
312 237 *
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
238 + * @since 2.6.0 bbPress (r6330)
318 239 */
319 - public function __construct() {
320 - $this->setup_globals();
321 - $this->includes();
322 - $this->setup_actions();
323 - }
240 + private function setup_variables() {
324 241
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 242 /** Identifiers *******************************************************/
353 243
354 244 // 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' );
245 + $this->forum_post_type = apply_filters( 'bbp_forum_post_type', 'forum' );
246 + $this->topic_post_type = apply_filters( 'bbp_topic_post_type', 'topic' );
247 + $this->topic_tag_tax_id = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' );
248 + $this->reply_post_type = apply_filters( 'bbp_reply_post_type', 'reply' );
359 249
360 250 // 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' );
251 + $this->spam_status_id = apply_filters( 'bbp_spam_post_status', 'spam' );
252 + $this->closed_status_id = apply_filters( 'bbp_closed_post_status', 'closed' );
253 + $this->orphan_status_id = apply_filters( 'bbp_orphan_post_status', 'orphan' );
254 + $this->public_status_id = apply_filters( 'bbp_public_post_status', 'publish' );
255 + $this->pending_status_id = apply_filters( 'bbp_pending_post_status', 'pending' );
256 + $this->private_status_id = apply_filters( 'bbp_private_post_status', 'private' );
257 + $this->hidden_status_id = apply_filters( 'bbp_hidden_post_status', 'hidden' );
258 + $this->trash_status_id = apply_filters( 'bbp_trash_post_status', 'trash' );
368 259
369 260 // 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' );
261 + $this->user_id = apply_filters( 'bbp_user_id', 'bbp_user' );
262 + $this->tops_id = apply_filters( 'bbp_tops_id', 'bbp_tops' );
263 + $this->reps_id = apply_filters( 'bbp_reps_id', 'bbp_reps' );
264 + $this->favs_id = apply_filters( 'bbp_favs_id', 'bbp_favs' );
265 + $this->subs_id = apply_filters( 'bbp_subs_id', 'bbp_subs' );
266 + $this->view_id = apply_filters( 'bbp_view_id', 'bbp_view' );
267 + $this->edit_id = apply_filters( 'bbp_edit_id', 'edit' );
268 + $this->paged_id = apply_filters( 'bbp_paged_id', 'paged' );
269 + $this->search_id = apply_filters( 'bbp_search_id', 'bbp_search' );
270 + $this->engagements_id = apply_filters( 'bbp_engagements_id', 'bbp_engagements' );
373 271
374 - /** Slugs *************************************************************/
272 + /** Queries ***********************************************************/
375 273
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' ) );
274 + $this->current_view_id = 0; // Current view id
275 + $this->current_forum_id = 0; // Current forum id
276 + $this->current_topic_id = 0; // Current topic id
277 + $this->current_reply_id = 0; // Current reply id
278 + $this->current_topic_tag_id = 0; // Current topic tag id
279 + $this->current_user_id = 0; // Current topic tag id
379 280
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 ) : '';
281 + $this->forum_query = new WP_Query(); // Main forum query
282 + $this->topic_query = new WP_Query(); // Main topic query
283 + $this->reply_query = new WP_Query(); // Main reply query
284 + $this->search_query = new WP_Query(); // Main search query
285 + $this->user_query = new BBP_User_Query(); // Main user query
382 286
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' ) );
287 + /** Theme Compat ******************************************************/
387 288
388 - // Taxonomy slugs
389 - $this->topic_tag_slug = apply_filters( 'bbp_topic_tag_slug', $prefix . get_option( '_bbp_topic_tag_slug', 'topic-tag' ) );
289 + $this->theme_compat = new stdClass(); // Base theme compatibility class
290 + $this->filters = new stdClass(); // Used when adding/removing filters
390 291
391 - /** Other Slugs *******************************************************/
292 + /** Users *************************************************************/
392 293
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' ) );
294 + $this->current_user = new WP_User(); // Currently logged in user
295 + $this->displayed_user = new WP_User(); // Currently displayed user
395 296
396 - /** Queries ***********************************************************/
397 -
398 - $this->forum_query = new stdClass;
399 - $this->topic_query = new stdClass;
400 - $this->reply_query = new stdClass;
401 -
402 297 /** Misc **************************************************************/
403 298
404 - // Errors
405 - $this->errors = new WP_Error();
299 + $this->domain = 'bbpress'; // Unique identifier for retrieving translated strings
300 + $this->extend = new stdClass(); // Plugins add data here
301 + $this->errors = new WP_Error(); // Feedback
406 302
407 - // Views
408 - $this->views = array();
303 + /** Deprecated ********************************************************/
409 304
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' );
305 + $this->tab_index = apply_filters( 'bbp_default_tab_index', 100 );
417 306 }
418 307
419 308 /**
420 309 * Include required files
421 310 *
422 - * @since bbPress (r2626)
311 + * @since 2.0.0 bbPress (r2626)
312 + *
423 313 * @access private
424 - *
425 - * @uses is_admin() If in WordPress admin, load additional file
426 314 */
427 315 private function includes() {
428 316
429 317 /** Core **************************************************************/
430 318
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
319 + require $this->includes_dir . 'core/abstraction.php';
320 + require $this->includes_dir . 'core/sub-actions.php';
321 + require $this->includes_dir . 'core/functions.php';
322 + require $this->includes_dir . 'core/cache.php';
323 + require $this->includes_dir . 'core/options.php';
324 + require $this->includes_dir . 'core/capabilities.php';
325 + require $this->includes_dir . 'core/update.php';
326 + require $this->includes_dir . 'core/template-functions.php';
327 + require $this->includes_dir . 'core/template-loader.php';
328 + require $this->includes_dir . 'core/theme-compat.php';
445 329
446 330 /** Components ********************************************************/
447 331
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
332 + // Common
333 + require $this->includes_dir . 'common/ajax.php';
334 + require $this->includes_dir . 'common/classes.php';
335 + require $this->includes_dir . 'common/engagements.php';
336 + require $this->includes_dir . 'common/functions.php';
337 + require $this->includes_dir . 'common/formatting.php';
338 + require $this->includes_dir . 'common/locale.php';
339 + require $this->includes_dir . 'common/locks.php';
340 + require $this->includes_dir . 'common/template.php';
341 + require $this->includes_dir . 'common/widgets.php';
342 + require $this->includes_dir . 'common/shortcodes.php';
450 343
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
344 + // Forums
345 + require $this->includes_dir . 'forums/capabilities.php';
346 + require $this->includes_dir . 'forums/functions.php';
347 + require $this->includes_dir . 'forums/template.php';
453 348
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
349 + // Topics
350 + require $this->includes_dir . 'topics/capabilities.php';
351 + require $this->includes_dir . 'topics/functions.php';
352 + require $this->includes_dir . 'topics/template.php';
456 353
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
354 + // Replies
355 + require $this->includes_dir . 'replies/capabilities.php';
356 + require $this->includes_dir . 'replies/functions.php';
357 + require $this->includes_dir . 'replies/template.php';
459 358
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
359 + // Search
360 + require $this->includes_dir . 'search/functions.php';
361 + require $this->includes_dir . 'search/template.php';
462 362
363 + // Users
364 + require $this->includes_dir . 'users/capabilities.php';
365 + require $this->includes_dir . 'users/engagements.php';
366 + require $this->includes_dir . 'users/functions.php';
367 + require $this->includes_dir . 'users/template.php';
368 + require $this->includes_dir . 'users/options.php';
369 + require $this->includes_dir . 'users/signups.php';
370 +
371 + /** Hooks *************************************************************/
372 +
373 + require $this->includes_dir . 'core/extend.php';
374 + require $this->includes_dir . 'core/actions.php';
375 + require $this->includes_dir . 'core/filters.php';
376 +
463 377 /** Admin *************************************************************/
464 378
465 379 // Quick admin check and load if needed
466 - if ( is_admin() )
467 - require( $this->plugin_dir . 'bbp-admin/bbp-admin.php' );
380 + if ( is_admin() ) {
381 + require $this->includes_dir . 'admin/actions.php';
382 + }
468 383 }
469 384
470 385 /**
471 386 * Setup the default hooks and actions
472 387 *
473 - * @since bbPress (r2644)
388 + * @since 2.0.0 bbPress (r2644)
389 + *
474 390 * @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 391 */
480 392 private function setup_actions() {
481 393
482 394 // Add actions to plugin activation and deactivation hooks
@@ -483,318 +395,258 @@
483 395 add_action( 'activate_' . $this->basename, 'bbp_activation' );
484 396 add_action( 'deactivate_' . $this->basename, 'bbp_deactivation' );
485 397
486 398 // If bbPress is being deactivated, do not add any actions
487 - if ( bbp_is_deactivation( $this->basename ) )
399 + if ( bbp_is_deactivation( $this->basename ) ) {
488 400 return;
401 + }
489 402
490 403 // Array of bbPress core actions
491 404 $actions = array(
405 + 'setup_theme', // Setup the default theme compat
492 406 'setup_current_user', // Setup currently logged in user
407 + 'setup_engagements', // Setup user engagements strategy
408 + 'roles_init', // User roles init
409 + 'register_meta', // Register meta (forum|topic|reply|user)
493 410 'register_post_types', // Register post types (forum|topic|reply)
494 411 'register_post_statuses', // Register post statuses (closed|spam|orphan|hidden)
495 412 'register_taxonomies', // Register taxonomies (topic-tag)
413 + 'register_shortcodes', // Register shortcodes (bbp-login)
496 414 'register_views', // Register the views (no-replies)
497 - 'register_theme_directory', // Register the theme directory (bbp-themes)
415 + 'register_theme_packages', // Register bundled theme packages (bbp-theme-compat/bbp-themes)
498 416 'load_textdomain', // Load textdomain (bbpress)
499 - 'add_rewrite_tags', // Add rewrite tags (view|user|edit)
500 - 'generate_rewrite_rules' // Generate rewrite rules (view|edit)
417 + 'add_rewrite_tags', // Add rewrite tags (view|user|edit|search)
418 + 'add_rewrite_rules', // Generate rewrite rules (view|edit|paged|search)
419 + 'add_permastructs' // Add permalink structures (view|user|search)
501 420 );
502 421
503 422 // Add the actions
504 - foreach( $actions as $class_action )
423 + foreach ( $actions as $class_action ) {
505 424 add_action( 'bbp_' . $class_action, array( $this, $class_action ), 5 );
425 + }
426 +
427 + // All bbPress actions are setup (includes bbp-core-hooks.php)
428 + do_action_ref_array( 'bbp_after_setup_actions', array( &$this ) );
506 429 }
507 430
431 + /** Public Methods ********************************************************/
432 +
508 433 /**
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.
434 + * Register bundled theme packages
512 435 *
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.
436 + * Note that since we currently have complete control over bbp-themes and
437 + * the bbp-theme-compat folders, it's fine to hardcode these here. If at a
438 + * later date we need to automate this, and API will need to be built.
516 439 *
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
440 + * @since 2.1.0 bbPress (r3829)
523 441 */
524 - public function load_textdomain() {
442 + public function register_theme_packages() {
525 443
526 - // Allow locale to be filtered
527 - $locale = apply_filters( 'bbpress_locale', get_locale() );
444 + // Register the basic theme stack. This is really dope.
445 + bbp_register_template_stack( 'get_stylesheet_directory', 6 );
446 + bbp_register_template_stack( 'get_template_directory', 8 );
528 447
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;
448 + // Register the default theme compatibility package
449 + bbp_register_theme_package( array(
450 + 'id' => 'default',
451 + 'name' => 'bbPress Default',
452 + 'version' => bbp_get_version(),
453 + 'dir' => trailingslashit( $this->themes_dir . 'default' ),
454 + 'url' => trailingslashit( $this->themes_url . 'default' )
455 + ) );
546 456 }
547 457
548 458 /**
549 - * Sets up the bbPress theme directory to use in WordPress
459 + * Setup the default bbPress theme compatibility location.
550 460 *
551 - * @since bbPress (r2507)
552 - *
553 - * @uses register_theme_directory() To register the theme directory
554 - * @return bool True on success, false on failure
461 + * @since 2.1.0 bbPress (r3778)
555 462 */
556 - public function register_theme_directory() {
557 - return register_theme_directory( $this->themes_dir );
463 + public function setup_theme() {
464 + bbp_setup_theme_compat( bbp_get_theme_package_id() );
558 465 }
559 466
560 467 /**
561 - * Setup the post types for forums, topics and replies
468 + * Load the translation file for current language. Checks the deprecated
469 + * languages folder inside the bbPress plugin first, and then the default
470 + * WordPress languages folder.
562 471 *
563 - * @since bbPress (r2597)
472 + * Note that custom translation files inside the bbPress plugin folder
473 + * will be removed on bbPress updates. If you're creating custom
474 + * translation files, please use the global language folder.
564 475 *
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()
476 + * @since 2.0.0 bbPress (r2596)
568 477 */
569 - public function register_post_types() {
478 + public function load_textdomain() {
570 479
571 - /** Forums ************************************************************/
480 + // Define the old directory
481 + $old_dir = WP_LANG_DIR . '/bbpress/';
572 482
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 - );
483 + // Old location, deprecated in 2.6.0
484 + if ( is_dir( $old_dir ) ) {
591 485
592 - // Forum rewrite
593 - $forum['rewrite'] = array(
594 - 'slug' => $this->forum_slug,
595 - 'with_front' => false
596 - );
486 + // Get locale & file-name
487 + $type = is_admin() ? get_user_locale() : get_locale();
488 + $locale = apply_filters( 'plugin_locale', $type, $this->domain );
489 + $mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
597 490
598 - // Forum supports
599 - $forum['supports'] = array(
600 - 'title',
601 - 'editor',
602 - 'revisions'
603 - );
491 + // Look in global /wp-content/languages/bbpress/ folder
492 + load_textdomain( $this->domain, $old_dir . $mofile );
493 + }
604 494
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 - ) );
495 + // Look in global /wp-content/languages/plugins/
496 + load_plugin_textdomain( $this->domain, false, $this->lang_base );
497 + }
624 498
625 - // Register Forum content type
626 - register_post_type( $this->forum_post_type, $bbp_cpt['forum'] );
499 + /**
500 + * Setup the post types for forums, topics and replies
501 + *
502 + * @since 2.0.0 bbPress (r2597)
503 + */
504 + public static function register_post_types() {
627 505
628 - /** Topics ************************************************************/
506 + /** Forums ************************************************************/
629 507
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' )
508 + // Register Forum content type
509 + register_post_type(
510 + bbp_get_forum_post_type(),
511 + apply_filters( 'bbp_register_forum_post_type', array(
512 + 'labels' => bbp_get_forum_post_type_labels(),
513 + 'rewrite' => bbp_get_forum_post_type_rewrite(),
514 + 'supports' => bbp_get_forum_post_type_supports(),
515 + 'description' => esc_html__( 'bbPress Forums', 'bbpress' ),
516 + 'capabilities' => bbp_get_forum_caps(),
517 + 'capability_type' => array( 'forum', 'forums' ),
518 + 'menu_position' => 555555,
519 + 'has_archive' => bbp_get_root_slug(),
520 + 'exclude_from_search' => true,
521 + 'show_in_nav_menus' => true,
522 + 'public' => true,
523 + 'show_ui' => current_user_can( 'bbp_forums_admin' ),
524 + 'can_export' => true,
525 + 'hierarchical' => true,
526 + 'query_var' => true,
527 + 'menu_icon' => '',
528 + 'source' => 'bbpress',
529 + ) )
647 530 );
648 531
649 - // Topic rewrite
650 - $topic['rewrite'] = array(
651 - 'slug' => $this->topic_slug,
652 - 'with_front' => false
653 - );
532 + /** Topics ************************************************************/
654 533
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' => ''
534 + // Register Topic content type
535 + register_post_type(
536 + bbp_get_topic_post_type(),
537 + apply_filters( 'bbp_register_topic_post_type', array(
538 + 'labels' => bbp_get_topic_post_type_labels(),
539 + 'rewrite' => bbp_get_topic_post_type_rewrite(),
540 + 'supports' => bbp_get_topic_post_type_supports(),
541 + 'description' => esc_html__( 'bbPress Topics', 'bbpress' ),
542 + 'capabilities' => bbp_get_topic_caps(),
543 + 'capability_type' => array( 'topic', 'topics' ),
544 + 'menu_position' => 555555,
545 + 'has_archive' => ( 'forums' === bbp_show_on_root() ) ? bbp_get_topic_archive_slug() : false,
546 + 'exclude_from_search' => true,
547 + 'show_in_nav_menus' => false,
548 + 'public' => true,
549 + 'show_ui' => current_user_can( 'bbp_topics_admin' ),
550 + 'can_export' => true,
551 + 'hierarchical' => false,
552 + 'query_var' => true,
553 + 'menu_icon' => '',
554 + 'source' => 'bbpress',
555 + )
680 556 ) );
681 557
682 - // Register Topic content type
683 - register_post_type( $this->topic_post_type, $bbp_cpt['topic'] );
684 -
685 558 /** Replies ***********************************************************/
686 559
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' )
560 + // Register reply content type
561 + register_post_type(
562 + bbp_get_reply_post_type(),
563 + apply_filters( 'bbp_register_reply_post_type', array(
564 + 'labels' => bbp_get_reply_post_type_labels(),
565 + 'rewrite' => bbp_get_reply_post_type_rewrite(),
566 + 'supports' => bbp_get_reply_post_type_supports(),
567 + 'description' => esc_html__( 'bbPress Replies', 'bbpress' ),
568 + 'capabilities' => bbp_get_reply_caps(),
569 + 'capability_type' => array( 'reply', 'replies' ),
570 + 'menu_position' => 555555,
571 + 'exclude_from_search' => true,
572 + 'has_archive' => false,
573 + 'show_in_nav_menus' => false,
574 + 'public' => true,
575 + 'show_ui' => current_user_can( 'bbp_replies_admin' ),
576 + 'can_export' => true,
577 + 'hierarchical' => false,
578 + 'query_var' => true,
579 + 'menu_icon' => '',
580 + 'source' => 'bbpress',
581 + ) )
704 582 );
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 583 }
742 584
743 585 /**
744 - * Register the post statuses
586 + * Register the post statuses used by bbPress
745 587 *
746 - * @since bbPress (r2727)
588 + * We do some manipulation of the 'trash' status so trashed topics and
589 + * replies can be viewed from within the theme.
747 590 *
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
591 + * @since 2.0.0 bbPress (r2727)
752 592 */
753 - public function register_post_statuses() {
754 - global $wp_post_statuses;
593 + public static function register_post_statuses() {
755 594
756 595 // 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 );
596 + register_post_status(
597 + bbp_get_closed_status_id(),
598 + apply_filters( 'bbp_register_closed_post_status', array(
599 + 'label' => _x( 'Closed', 'post', 'bbpress' ),
600 + 'label_count' => _nx_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'post', 'bbpress' ),
601 + 'public' => true,
602 + 'show_in_admin_status_list' => true,
603 + 'show_in_admin_all_list' => true,
604 + 'source' => 'bbpress'
605 + ) )
606 + );
764 607
765 608 // 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 );
609 + register_post_status(
610 + bbp_get_spam_status_id(),
611 + apply_filters( 'bbp_register_spam_post_status', array(
612 + 'label' => _x( 'Spam', 'post', 'bbpress' ),
613 + 'label_count' => _nx_noop( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'post', 'bbpress' ),
614 + 'protected' => true,
615 + 'exclude_from_search' => true,
616 + 'show_in_admin_status_list' => true,
617 + 'show_in_admin_all_list' => false,
618 + 'source' => 'bbpress'
619 + ) )
620 + );
775 621
776 622 // 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 );
623 + register_post_status(
624 + bbp_get_orphan_status_id(),
625 + apply_filters( 'bbp_register_orphan_post_status', array(
626 + 'label' => _x( 'Orphan', 'post', 'bbpress' ),
627 + 'label_count' => _nx_noop( 'Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'post', 'bbpress' ),
628 + 'protected' => true,
629 + 'exclude_from_search' => true,
630 + 'show_in_admin_status_list' => true,
631 + 'show_in_admin_all_list' => false,
632 + 'source' => 'bbpress'
633 + ) )
634 + );
786 635
787 636 // 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 );
637 + register_post_status(
638 + bbp_get_hidden_status_id(),
639 + apply_filters( 'bbp_register_hidden_post_status', array(
640 + 'label' => _x( 'Hidden', 'post', 'bbpress' ),
641 + 'label_count' => _nx_noop( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'post', 'bbpress' ),
642 + 'private' => true,
643 + 'exclude_from_search' => true,
644 + 'show_in_admin_status_list' => true,
645 + 'show_in_admin_all_list' => true,
646 + 'source' => 'bbpress'
647 + ) )
648 + );
797 649
798 650 /**
799 651 * Trash fix
800 652 *
@@ -802,10 +654,12 @@
802 654 * protected so that the users with 'view_trash' cap can view
803 655 * single trashed topics/replies in the front-end as wp_query
804 656 * doesn't allow any hack for the trashed topics to be viewed.
805 657 */
806 - if ( !empty( $wp_post_statuses['trash'] ) ) {
658 + global $wp_post_statuses;
807 659
660 + if ( ! empty( $wp_post_statuses['trash'] ) ) {
661 +
808 662 // User can view trash so set internal to false
809 663 if ( current_user_can( 'view_trash' ) ) {
810 664 $wp_post_statuses['trash']->internal = false;
811 665 $wp_post_statuses['trash']->protected = true;
@@ -810,9 +664,9 @@
810 664 $wp_post_statuses['trash']->internal = false;
811 665 $wp_post_statuses['trash']->protected = true;
812 666
813 667 // User cannot view trash so set internal to true
814 - } elseif ( !current_user_can( 'view_trash' ) ) {
668 + } else {
815 669 $wp_post_statuses['trash']->internal = true;
816 670 }
817 671 }
818 672 }
@@ -817,161 +671,394 @@
817 671 }
818 672 }
819 673
820 674 /**
821 - * Register the topic tag taxonomy
675 + * Register the topic tag and forum moderator taxonomies
822 676 *
823 - * @since bbPress (r2464)
677 + * @since 2.0.0 bbPress (r2464) Added bbp_get_topic_tag_tax_id() taxonomy
678 + */
679 + public static function register_taxonomies() {
680 +
681 + // Register the topic-tag taxonomy.
682 + register_taxonomy(
683 + bbp_get_topic_tag_tax_id(),
684 + bbp_get_topic_post_type(),
685 + apply_filters( 'bbp_register_topic_taxonomy', array(
686 + 'labels' => bbp_get_topic_tag_tax_labels(),
687 + 'rewrite' => bbp_get_topic_tag_tax_rewrite(),
688 + 'capabilities' => bbp_get_topic_tag_caps(),
689 + 'update_count_callback' => 'bbp_update_topic_tag_count',
690 + 'query_var' => true,
691 + 'show_tagcloud' => true,
692 + 'hierarchical' => false,
693 + 'show_in_nav_menus' => false,
694 + 'public' => true,
695 + 'show_ui' => bbp_allow_topic_tags() && current_user_can( 'bbp_topic_tags_admin' ),
696 + 'source' => 'bbpress'
697 + )
698 + ) );
699 + }
700 +
701 + /**
702 + * Register the bbPress views
824 703 *
825 - * @uses register_taxonomy() To register the taxonomy
704 + * @since 2.0.0 bbPress (r2789)
826 705 */
827 - public function register_taxonomies() {
706 + public static function register_views() {
828 707
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 - );
708 + // Popular topics
709 + bbp_register_view(
710 + 'popular',
711 + esc_html__( 'Most popular topics', 'bbpress' ),
712 + apply_filters( 'bbp_register_view_popular', array(
713 + 'meta_key' => '_bbp_reply_count',
714 + 'meta_type' => 'NUMERIC',
715 + 'max_num_pages' => 1,
716 + 'orderby' => 'meta_value_num',
717 + 'show_stickies' => false
718 + )
719 + ) );
842 720
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
721 + // Topics with no replies
722 + bbp_register_view(
723 + 'no-replies',
724 + esc_html__( 'Topics with no replies', 'bbpress' ),
725 + apply_filters( 'bbp_register_view_no_replies', array(
726 + 'meta_key' => '_bbp_reply_count',
727 + 'meta_type' => 'NUMERIC',
728 + 'meta_value' => 1,
729 + 'meta_compare' => '<',
730 + 'orderby' => '',
731 + 'show_stickies' => false
732 + )
860 733 ) );
734 + }
861 735
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 - );
736 + /**
737 + * Register the bbPress shortcodes
738 + *
739 + * @since 2.0.0 bbPress (r3031)
740 + */
741 + public function register_shortcodes() {
742 + $this->shortcodes = new BBP_Shortcodes();
868 743 }
869 744
870 745 /**
871 - * Register the bbPress views
746 + * Register bbPress meta-data
872 747 *
873 - * @since bbPress (r2789)
748 + * Counts added in 2.6.0 to avoid negative values
874 749 *
875 - * @uses bbp_register_view() To register the views
750 + * @since 2.6.0 bbPress (r6300)
876 751 */
877 - public function register_views() {
752 + public function register_meta() {
878 753
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' => ''
754 + // Define "count" meta-type array
755 + $count = array(
756 +
757 + // Counts are always integers
758 + 'type' => 'integer',
759 +
760 + // Generic count description
761 + 'description' => esc_html__( 'bbPress Item Count', 'bbpress' ),
762 +
763 + // Counts are single values
764 + 'single' => true,
765 +
766 + // Counts should be made available in REST
767 + 'show_in_rest' => true,
768 +
769 + // Never allow counts to go negative
770 + 'sanitize_callback' => 'bbp_number_not_negative',
771 +
772 + // All users may update count meta data
773 + 'auth_callback' => '__return_true'
774 + );
775 +
776 + /** Post **************************************************************/
777 +
778 + // Counts
779 + register_meta( 'post', '_bbp_topic_count', $count );
780 + register_meta( 'post', '_bbp_reply_count', $count );
781 + register_meta( 'post', '_bbp_total_topic_count', $count );
782 + register_meta( 'post', '_bbp_total_reply_count', $count );
783 + register_meta( 'post', '_bbp_voice_count', $count );
784 + register_meta( 'post', '_bbp_anonymous_reply_count', $count );
785 + register_meta( 'post', '_bbp_topic_count_hidden', $count );
786 + register_meta( 'post', '_bbp_reply_count_hidden', $count );
787 + register_meta( 'post', '_bbp_forum_subforum_count', $count );
788 +
789 + /* User ***************************************************************/
790 +
791 + // Counts
792 + register_meta( 'user', '_bbp_topic_count', $count );
793 + register_meta( 'user', '_bbp_reply_count', $count );
794 +
795 + // Activity
796 + register_meta( 'user', '_bbp_last_posted', array(
797 + 'type' => 'integer',
798 + 'description' => esc_html__( 'bbPress User Activity', 'bbpress' ),
799 + 'single' => true,
800 + 'show_in_rest' => true,
801 + 'sanitize_callback' => 'bbp_number_not_negative',
802 + 'auth_callback' => '__return_true'
885 803 ) );
886 -
887 - bbp_register_view( 'no-replies', __( 'Topics with no replies', 'bbpress' ), $no_replies );
888 804 }
889 805
890 806 /**
891 807 * Setup the currently logged-in user
892 808 *
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.
809 + * @since 2.0.0 bbPress (r2697)
810 + */
811 + public function setup_current_user() {
812 + $this->current_user = wp_get_current_user();
813 + }
814 +
815 + /**
816 + * Setup the user engagements strategy
897 817 *
898 - * @since bbPress (r2697)
818 + * @since 2.6.0 bbPress (r6875)
819 + */
820 + public function setup_engagements() {
821 +
822 + // Setup the class name
823 + $strategy = ucwords( bbp_engagements_strategy() );
824 + $class_name = "BBP_User_Engagements_{$strategy}";
825 +
826 + // Setup the engagements interface
827 + $this->engagements = new $class_name();
828 + }
829 +
830 + /**
831 + * Initialize forum-specific roles
899 832 *
900 - * @uses wp_get_current_user()
833 + * @since 2.6.0
901 834 */
902 - public function setup_current_user() {
903 - $this->current_user = &wp_get_current_user();
835 + public function roles_init() {
836 +
837 + // Get role IDs
838 + $keymaster = bbp_get_keymaster_role();
839 + $moderator = bbp_get_moderator_role();
840 + $participant = bbp_get_participant_role();
841 + $spectator = bbp_get_spectator_role();
842 + $blocked = bbp_get_blocked_role();
843 +
844 + // Build the roles into one useful array
845 + $this->roles[ $keymaster ] = new WP_Role( 'Keymaster', bbp_get_caps_for_role( $keymaster ) );
846 + $this->roles[ $moderator ] = new WP_Role( 'Moderator', bbp_get_caps_for_role( $moderator ) );
847 + $this->roles[ $participant ] = new WP_Role( 'Participant', bbp_get_caps_for_role( $participant ) );
848 + $this->roles[ $spectator ] = new WP_Role( 'Spectator', bbp_get_caps_for_role( $spectator ) );
849 + $this->roles[ $blocked ] = new WP_Role( 'Blocked', bbp_get_caps_for_role( $blocked ) );
904 850 }
905 851
852 + /** Custom Rewrite Rules **************************************************/
853 +
906 854 /**
907 855 * Add the bbPress-specific rewrite tags
908 856 *
909 - * @since bbPress (r2753)
857 + * @since 2.0.0 bbPress (r2753)
858 + */
859 + public static function add_rewrite_tags() {
860 + add_rewrite_tag( '%' . bbp_get_view_rewrite_id() . '%', '([^/]+)' ); // View Page tag
861 + add_rewrite_tag( '%' . bbp_get_edit_rewrite_id() . '%', '([1]{1,})' ); // Edit Page tag
862 + add_rewrite_tag( '%' . bbp_get_search_rewrite_id() . '%', '([^/]+)' ); // Search Results tag
863 + add_rewrite_tag( '%' . bbp_get_user_rewrite_id() . '%', '([^/]+)' ); // User Profile tag
864 + add_rewrite_tag( '%' . bbp_get_user_favorites_rewrite_id() . '%', '([1]{1,})' ); // User Favorites tag
865 + add_rewrite_tag( '%' . bbp_get_user_subscriptions_rewrite_id() . '%', '([1]{1,})' ); // User Subscriptions tag
866 + add_rewrite_tag( '%' . bbp_get_user_engagements_rewrite_id() . '%', '([1]{1,})' ); // User Engagements tag
867 + add_rewrite_tag( '%' . bbp_get_user_topics_rewrite_id() . '%', '([1]{1,})' ); // User Topics Tag
868 + add_rewrite_tag( '%' . bbp_get_user_replies_rewrite_id() . '%', '([1]{1,})' ); // User Replies Tag
869 + }
870 +
871 + /**
872 + * Add bbPress-specific rewrite rules for uri's that are not
873 + * setup for us by way of custom post types or taxonomies. This includes:
874 + * - Front-end editing
875 + * - Topic views
876 + * - User profiles
910 877 *
911 - * @uses add_rewrite_tag() To add the rewrite tags
878 + * @since 2.0.0 bbPress (r2688)
879 + *
880 + * @todo Extract into an API
912 881 */
913 - public function add_rewrite_tags() {
882 + public static function add_rewrite_rules() {
914 883
915 - // Pad attributes
916 - $pad = 2;
917 - $wrapper = '%';
884 + /** Setup *************************************************************/
918 885
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 );
886 + // Add rules to top or bottom?
887 + $priority = 'top';
923 888
924 - // User Profile tag
925 - add_rewrite_tag( $bbp_user, '([^/]+)' );
889 + // Single Slugs
890 + $forum_slug = bbp_get_forum_slug();
891 + $topic_slug = bbp_get_topic_slug();
892 + $reply_slug = bbp_get_reply_slug();
893 + $ttag_slug = bbp_get_topic_tag_tax_slug();
926 894
927 - // View Page tag
928 - add_rewrite_tag( $bbp_view, '([^/]+)' );
895 + // Archive Slugs
896 + $user_slug = bbp_get_user_slug();
897 + $view_slug = bbp_get_view_slug();
898 + $search_slug = bbp_get_search_slug();
899 + $topic_archive_slug = bbp_get_topic_archive_slug();
900 + $reply_archive_slug = bbp_get_reply_archive_slug();
929 901
930 - // Edit Page tag
931 - add_rewrite_tag( $bbp_edit, '([1]{1,})' );
902 + // Tertiary Slugs
903 + $feed_slug = 'feed';
904 + $edit_slug = bbp_get_edit_slug();
905 + $paged_slug = bbp_get_paged_slug();
906 + $user_favs_slug = bbp_get_user_favorites_slug();
907 + $user_subs_slug = bbp_get_user_subscriptions_slug();
908 + $user_engs_slug = bbp_get_user_engagements_slug();
909 +
910 + // Unique rewrite ID's
911 + $feed_id = 'feed';
912 + $edit_id = bbp_get_edit_rewrite_id();
913 + $view_id = bbp_get_view_rewrite_id();
914 + $paged_id = bbp_get_paged_rewrite_id();
915 + $search_id = bbp_get_search_rewrite_id();
916 + $user_id = bbp_get_user_rewrite_id();
917 + $user_favs_id = bbp_get_user_favorites_rewrite_id();
918 + $user_subs_id = bbp_get_user_subscriptions_rewrite_id();
919 + $user_tops_id = bbp_get_user_topics_rewrite_id();
920 + $user_reps_id = bbp_get_user_replies_rewrite_id();
921 + $user_engs_id = bbp_get_user_engagements_rewrite_id();
922 +
923 + // Rewrite rule matches used repeatedly below
924 + $root_rule = '/([^/]+)/?$';
925 + $feed_rule = '/([^/]+)/' . $feed_slug . '/?$';
926 + $edit_rule = '/([^/]+)/' . $edit_slug . '/?$';
927 + $paged_rule = '/([^/]+)/' . $paged_slug . '/?([0-9]{1,})/?$';
928 +
929 + // Search rules (without slug check)
930 + $search_root_rule = '/?$';
931 + $search_paged_rule = '/' . $paged_slug . '/?([0-9]{1,})/?$';
932 +
933 + /** Add ***************************************************************/
934 +
935 + // User profile rules
936 + $tops_rule = '/([^/]+)/' . $topic_archive_slug . '/?$';
937 + $reps_rule = '/([^/]+)/' . $reply_archive_slug . '/?$';
938 + $favs_rule = '/([^/]+)/' . $user_favs_slug . '/?$';
939 + $subs_rule = '/([^/]+)/' . $user_subs_slug . '/?$';
940 + $engs_rule = '/([^/]+)/' . $user_engs_slug . '/?$';
941 + $tops_paged_rule = '/([^/]+)/' . $topic_archive_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
942 + $reps_paged_rule = '/([^/]+)/' . $reply_archive_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
943 + $favs_paged_rule = '/([^/]+)/' . $user_favs_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
944 + $subs_paged_rule = '/([^/]+)/' . $user_subs_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
945 + $engs_paged_rule = '/([^/]+)/' . $user_engs_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
946 +
947 + // Edit Forum|Topic|Reply|Topic-tag
948 + add_rewrite_rule( $forum_slug . $edit_rule, 'index.php?' . bbp_get_forum_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority );
949 + add_rewrite_rule( $topic_slug . $edit_rule, 'index.php?' . bbp_get_topic_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority );
950 + add_rewrite_rule( $reply_slug . $edit_rule, 'index.php?' . bbp_get_reply_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority );
951 + add_rewrite_rule( $ttag_slug . $edit_rule, 'index.php?' . bbp_get_topic_tag_tax_id() . '=$matches[1]&' . $edit_id . '=1', $priority );
952 +
953 + // User Pagination|Edit|View
954 + add_rewrite_rule( $user_slug . $tops_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1&' . $paged_id . '=$matches[2]', $priority );
955 + add_rewrite_rule( $user_slug . $reps_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1&' . $paged_id . '=$matches[2]', $priority );
956 + add_rewrite_rule( $user_slug . $favs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1&' . $paged_id . '=$matches[2]', $priority );
957 + add_rewrite_rule( $user_slug . $subs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1&' . $paged_id . '=$matches[2]', $priority );
958 + add_rewrite_rule( $user_slug . $engs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_engs_id . '=1&' . $paged_id . '=$matches[2]', $priority );
959 + add_rewrite_rule( $user_slug . $tops_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1', $priority );
960 + add_rewrite_rule( $user_slug . $reps_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1', $priority );
961 + add_rewrite_rule( $user_slug . $favs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1', $priority );
962 + add_rewrite_rule( $user_slug . $subs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1', $priority );
963 + add_rewrite_rule( $user_slug . $engs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_engs_id . '=1', $priority );
964 + add_rewrite_rule( $user_slug . $edit_rule, 'index.php?' . $user_id . '=$matches[1]&' . $edit_id . '=1', $priority );
965 + add_rewrite_rule( $user_slug . $root_rule, 'index.php?' . $user_id . '=$matches[1]', $priority );
966 +
967 + // Topic-View Pagination|Feed|View
968 + add_rewrite_rule( $view_slug . $paged_rule, 'index.php?' . $view_id . '=$matches[1]&' . $paged_id . '=$matches[2]', $priority );
969 + add_rewrite_rule( $view_slug . $feed_rule, 'index.php?' . $view_id . '=$matches[1]&' . $feed_id . '=$matches[2]', $priority );
970 + add_rewrite_rule( $view_slug . $root_rule, 'index.php?' . $view_id . '=$matches[1]', $priority );
971 +
972 + // Search All
973 + add_rewrite_rule( $search_slug . $search_paged_rule, 'index.php?' . $paged_id .'=$matches[1]', $priority );
974 + add_rewrite_rule( $search_slug . $search_root_rule, 'index.php?' . $search_id, $priority );
932 975 }
933 976
934 977 /**
935 - * Register bbPress-specific rewrite rules
978 + * Add permalink structures for new archive-style destinations.
936 979 *
937 - * @since bbPress (r2688)
980 + * - Users
981 + * - Topic Views
982 + * - Search
938 983 *
939 - * @param WP_Rewrite $wp_rewrite bbPress-sepecific rules are appended in
940 - * $wp_rewrite->rules
984 + * @since 2.4.0 bbPress (r4930)
941 985 */
942 - public function generate_rewrite_rules( $wp_rewrite ) {
986 + public static function add_permastructs() {
943 987
944 - // New rules to merge with existing
945 - $bbp_rules = array(
988 + // Get unique ID's
989 + $user_id = bbp_get_user_rewrite_id();
990 + $view_id = bbp_get_view_rewrite_id();
991 + $search_id = bbp_get_search_rewrite_id();
946 992
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',
993 + // Get root slugs
994 + $user_slug = bbp_get_user_slug();
995 + $view_slug = bbp_get_view_slug();
996 + $search_slug = bbp_get_search_slug();
950 997
951 - // Edit Topic Tag
952 - $this->topic_tag_slug . '/([^/]+)/edit/?$' => 'index.php?' . $this->topic_tag_tax_id . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
998 + // User Permastruct
999 + add_permastruct( $user_id, $user_slug . '/%' . $user_id . '%', array(
1000 + 'with_front' => false,
1001 + 'ep_mask' => EP_NONE,
1002 + 'paged' => false,
1003 + 'feed' => false,
1004 + 'forcomments' => false,
1005 + 'walk_dirs' => true,
1006 + 'endpoints' => false,
1007 + ) );
953 1008
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',
1009 + // Topic View Permastruct
1010 + add_permastruct( $view_id, $view_slug . '/%' . $view_id . '%', array(
1011 + 'with_front' => false,
1012 + 'ep_mask' => EP_NONE,
1013 + 'paged' => false,
1014 + 'feed' => false,
1015 + 'forcomments' => false,
1016 + 'walk_dirs' => true,
1017 + 'endpoints' => false,
1018 + ) );
958 1019
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 - );
1020 + // Search Permastruct
1021 + add_permastruct( $search_id, $search_slug . '/%' . $search_id . '%', array(
1022 + 'with_front' => false,
1023 + 'ep_mask' => EP_NONE,
1024 + 'paged' => true,
1025 + 'feed' => false,
1026 + 'forcomments' => false,
1027 + 'walk_dirs' => true,
1028 + 'endpoints' => false,
1029 + ) );
1030 + }
1031 +}
963 1032
964 - // Merge bbPress rules with existing
965 - $wp_rewrite->rules = array_merge( $bbp_rules, $wp_rewrite->rules );
1033 +/**
1034 + * The main function responsible for returning the one true bbPress Instance
1035 + * to functions everywhere.
1036 + *
1037 + * Use this function like you would a global variable, except without needing
1038 + * to declare the global.
1039 + *
1040 + * Example: <?php $bbp = bbpress(); ?>
1041 + *
1042 + * @since 2.0.0 bbPress (r2464)
1043 + *
1044 + * @return bbPress The one true bbPress Instance
1045 + */
1046 +function bbpress() {
1047 + return bbPress::instance();
1048 +}
966 1049
967 - // Return merged rules
968 - return $wp_rewrite;
969 - }
970 -}
1050 +/**
1051 + * Hook bbPress early onto the 'plugins_loaded' action.
1052 + *
1053 + * This gives all other plugins the chance to load before bbPress, to get their
1054 + * actions, filters, and overrides setup without bbPress being in the way.
1055 + */
1056 +if ( defined( 'BBPRESS_LATE_LOAD' ) ) {
1057 + add_action( 'plugins_loaded', 'bbpress', (int) BBPRESS_LATE_LOAD );
971 1058
972 1059 // "And now here's something we hope you'll really like!"
973 -$GLOBALS['bbp'] = new bbPress();
1060 +} else {
1061 + bbpress();
1062 +}
974 1063
975 1064 endif; // class_exists check
976 -
977 -?>