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