| @@ -4,9 +4,9 @@ | ||
| 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 4471 2012-11-23 11:24:58Z johnjamesjacoby $ | |
| 8 | + * $Id: bbpress.php 7161 2020-11-06 01:05:46Z johnjamesjacoby $ | |
| 9 | 9 | * |
| 10 | 10 | * @package bbPress |
| 11 | 11 | * @subpackage Main |
| 12 | 12 | */ |
| @@ -11,28 +11,31 @@ | ||
| 11 | 11 | * @subpackage Main |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | - * Plugin Name: bbPress | |
| 16 | - * Plugin URI: http://bbpress.org | |
| 17 | - * Description: bbPress is forum software with a twist from the creators of WordPress. | |
| 18 | - * Author: The bbPress Community | |
| 19 | - * Author URI: http://bbpress.org | |
| 20 | - * Version: 2.2.2 | |
| 21 | - * Text Domain: bbpress | |
| 22 | - * Domain Path: /languages/ | |
| 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 | |
| 23 | 26 | */ |
| 24 | 27 | |
| 25 | 28 | // Exit if accessed directly |
| 26 | -if ( !defined( 'ABSPATH' ) ) exit; | |
| 29 | +defined( 'ABSPATH' ) || exit; | |
| 27 | 30 | |
| 28 | -if ( !class_exists( 'bbPress' ) ) : | |
| 31 | +if ( ! class_exists( 'bbPress' ) ) : | |
| 29 | 32 | /** |
| 30 | 33 | * Main bbPress Class |
| 31 | 34 | * |
| 32 | - * Tap tap tap... Is this thing on? | |
| 35 | + * "Word hard. Stay bumble." | |
| 33 | 36 | * |
| 34 | - * @since bbPress (r2464) | |
| 37 | + * @since 2.0.0 bbPress (r2464) | |
| 35 | 38 | */ |
| 36 | 39 | final class bbPress { |
| 37 | 40 | |
| 38 | 41 | /** Magic *****************************************************************/ |
| @@ -37,14 +40,15 @@ | ||
| 37 | 40 | |
| 38 | 41 | /** Magic *****************************************************************/ |
| 39 | 42 | |
| 40 | 43 | /** |
| 41 | - * bbPress uses many variables, most of which can be filtered to customize | |
| 42 | - * the way that it works. To prevent unauthorized access, these variables | |
| 43 | - * are stored in a private array that is magically updated using PHP 5.2+ | |
| 44 | - * methods. This is to prevent third party plugins from tampering with | |
| 45 | - * essential information indirectly, which would cause issues later. | |
| 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. | |
| 46 | 47 | * |
| 48 | + * This is a precautionary measure, to avoid potential errors produced by | |
| 49 | + * unanticipated direct manipulation of run-time data. | |
| 50 | + * | |
| 47 | 51 | * @see bbPress::setup_globals() |
| 48 | 52 | * @var array |
| 49 | 53 | */ |
| 50 | 54 | private $data; |
| @@ -56,9 +60,9 @@ | ||
| 56 | 60 | */ |
| 57 | 61 | public $current_user = false; |
| 58 | 62 | |
| 59 | 63 | /** |
| 60 | - * @var obj Add-ons append to this (Akismet, BuddyPress, etc...) | |
| 64 | + * @var stdClass Add-ons append to this (Akismet, BuddyPress, etc...) | |
| 61 | 65 | */ |
| 62 | 66 | public $extend; |
| 63 | 67 | |
| 64 | 68 | /** |
| @@ -63,27 +67,32 @@ | ||
| 63 | 67 | |
| 64 | 68 | /** |
| 65 | 69 | * @var array Topic views |
| 66 | 70 | */ |
| 67 | - public $views = array(); | |
| 71 | + public $views = array(); | |
| 68 | 72 | |
| 69 | 73 | /** |
| 70 | 74 | * @var array Overloads get_option() |
| 71 | 75 | */ |
| 72 | - public $options = array(); | |
| 76 | + public $options = array(); | |
| 73 | 77 | |
| 74 | 78 | /** |
| 79 | + * @var array Storage of options not in the database | |
| 80 | + */ | |
| 81 | + public $not_options = array(); | |
| 82 | + | |
| 83 | + /** | |
| 75 | 84 | * @var array Overloads get_user_meta() |
| 76 | 85 | */ |
| 77 | 86 | public $user_options = array(); |
| 78 | 87 | |
| 79 | - /** Singleton *************************************************************/ | |
| 80 | - | |
| 81 | 88 | /** |
| 82 | - * @var bbPress The one true bbPress | |
| 89 | + * @var array Dynamically initialized user roles | |
| 83 | 90 | */ |
| 84 | - private static $instance; | |
| 91 | + public $roles = array(); | |
| 85 | 92 | |
| 93 | + /** Singleton *************************************************************/ | |
| 94 | + | |
| 86 | 95 | /** |
| 87 | 96 | * Main bbPress Instance |
| 88 | 97 | * |
| 89 | 98 | * bbPress is fun |
| @@ -92,24 +101,30 @@ | ||
| 92 | 101 | * |
| 93 | 102 | * Insures that only one instance of bbPress exists in memory at any one |
| 94 | 103 | * time. Also prevents needing to define globals all over the place. |
| 95 | 104 | * |
| 96 | - * @since bbPress (r3757) | |
| 97 | - * @staticvar array $instance | |
| 98 | - * @uses bbPress::setup_globals() Setup the globals needed | |
| 99 | - * @uses bbPress::includes() Include the required files | |
| 100 | - * @uses bbPress::setup_actions() Setup the hooks and actions | |
| 105 | + * @since 2.1.0 bbPress (r3757) | |
| 106 | + * | |
| 107 | + * @staticvar object $instance | |
| 101 | 108 | * @see bbpress() |
| 102 | - * @return The one true bbPress | |
| 109 | + * @return bbPress The one true bbPress | |
| 103 | 110 | */ |
| 104 | 111 | public static function instance() { |
| 105 | - if ( ! isset( self::$instance ) ) { | |
| 106 | - self::$instance = new bbPress; | |
| 107 | - self::$instance->setup_globals(); | |
| 108 | - self::$instance->includes(); | |
| 109 | - self::$instance->setup_actions(); | |
| 112 | + | |
| 113 | + // Store the instance locally to avoid private static replication | |
| 114 | + static $instance = null; | |
| 115 | + | |
| 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(); | |
| 110 | 123 | } |
| 111 | - return self::$instance; | |
| 124 | + | |
| 125 | + // Always return the instance | |
| 126 | + return $instance; | |
| 112 | 127 | } |
| 113 | 128 | |
| 114 | 129 | /** Magic Methods *********************************************************/ |
| 115 | 130 | |
| @@ -115,9 +130,10 @@ | ||
| 115 | 130 | |
| 116 | 131 | /** |
| 117 | 132 | * A dummy constructor to prevent bbPress from being loaded more than once. |
| 118 | 133 | * |
| 119 | - * @since bbPress (r2464) | |
| 134 | + * @since 2.0.0 bbPress (r2464) | |
| 135 | + * | |
| 120 | 136 | * @see bbPress::instance() |
| 121 | 137 | * @see bbpress(); |
| 122 | 138 | */ |
| 123 | 139 | private function __construct() { /* Do nothing here */ } |
| @@ -124,9 +140,9 @@ | ||
| 124 | 140 | |
| 125 | 141 | /** |
| 126 | 142 | * A dummy magic method to prevent bbPress from being cloned |
| 127 | 143 | * |
| 128 | - * @since bbPress (r2464) | |
| 144 | + * @since 2.0.0 bbPress (r2464) | |
| 129 | 145 | */ |
| 130 | 146 | public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bbpress' ), '2.1' ); } |
| 131 | 147 | |
| 132 | 148 | /** |
| @@ -131,9 +147,9 @@ | ||
| 131 | 147 | |
| 132 | 148 | /** |
| 133 | 149 | * A dummy magic method to prevent bbPress from being unserialized |
| 134 | 150 | * |
| 135 | - * @since bbPress (r2464) | |
| 151 | + * @since 2.0.0 bbPress (r2464) | |
| 136 | 152 | */ |
| 137 | 153 | public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bbpress' ), '2.1' ); } |
| 138 | 154 | |
| 139 | 155 | /** |
| @@ -138,30 +154,41 @@ | ||
| 138 | 154 | |
| 139 | 155 | /** |
| 140 | 156 | * Magic method for checking the existence of a certain custom field |
| 141 | 157 | * |
| 142 | - * @since bbPress (r3951) | |
| 158 | + * @since 2.1.0 bbPress (r3951) | |
| 143 | 159 | */ |
| 144 | - public function __isset( $key ) { return isset( $this->data[$key] ); } | |
| 160 | + public function __isset( $key ) { return isset( $this->data[ $key ] ); } | |
| 145 | 161 | |
| 146 | 162 | /** |
| 147 | - * Magic method for getting bbPress varibles | |
| 163 | + * Magic method for getting bbPress variables | |
| 148 | 164 | * |
| 149 | - * @since bbPress (r3951) | |
| 165 | + * @since 2.1.0 bbPress (r3951) | |
| 150 | 166 | */ |
| 151 | - public function __get( $key ) { return isset( $this->data[$key] ) ? $this->data[$key] : null; } | |
| 167 | + public function __get( $key ) { return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null; } | |
| 152 | 168 | |
| 153 | 169 | /** |
| 154 | - * Magic method for setting bbPress varibles | |
| 170 | + * Magic method for setting bbPress variables | |
| 155 | 171 | * |
| 156 | - * @since bbPress (r3951) | |
| 172 | + * @since 2.1.0 bbPress (r3951) | |
| 157 | 173 | */ |
| 158 | - public function __set( $key, $value ) { $this->data[$key] = $value; } | |
| 174 | + public function __set( $key , $value ) { $this->data[ $key ] = $value; } | |
| 159 | 175 | |
| 160 | 176 | /** |
| 177 | + * Magic method for unsetting bbPress variables | |
| 178 | + * | |
| 179 | + * @since 2.3.0 bbPress (r4628) | |
| 180 | + */ | |
| 181 | + public function __unset( $key ) { | |
| 182 | + if ( isset( $this->data[ $key ] ) ) { | |
| 183 | + unset( $this->data[ $key ] ); | |
| 184 | + } | |
| 185 | + } | |
| 186 | + | |
| 187 | + /** | |
| 161 | 188 | * Magic method to prevent notices and errors from invalid method calls |
| 162 | 189 | * |
| 163 | - * @since bbPress (r4252) | |
| 190 | + * @since 2.2.0 bbPress (r4252) | |
| 164 | 191 | */ |
| 165 | 192 | public function __call( $name = '', $args = array() ) { unset( $name, $args ); return null; } |
| 166 | 193 | |
| 167 | 194 | /** Private Methods *******************************************************/ |
| @@ -166,50 +193,60 @@ | ||
| 166 | 193 | |
| 167 | 194 | /** Private Methods *******************************************************/ |
| 168 | 195 | |
| 169 | 196 | /** |
| 170 | - * Set some smart defaults to class variables. Allow some of them to be | |
| 171 | - * filtered to allow for early overriding. | |
| 197 | + * Setup the environment variables to allow the rest of bbPress to function | |
| 198 | + * more easily. | |
| 172 | 199 | * |
| 173 | - * @since bbPress (r2626) | |
| 200 | + * @since 2.0.0 bbPress (r2626) | |
| 201 | + * | |
| 174 | 202 | * @access private |
| 175 | - * @uses plugin_dir_path() To generate bbPress plugin path | |
| 176 | - * @uses plugin_dir_url() To generate bbPress plugin url | |
| 177 | - * @uses apply_filters() Calls various filters | |
| 178 | 203 | */ |
| 179 | - private function setup_globals() { | |
| 204 | + private function setup_environment() { | |
| 180 | 205 | |
| 181 | 206 | /** Versions **********************************************************/ |
| 182 | 207 | |
| 183 | - $this->version = '2.2.2'; | |
| 184 | - $this->db_version = '220'; | |
| 208 | + $this->version = '2.6.6'; | |
| 209 | + $this->db_version = '263'; | |
| 185 | 210 | |
| 186 | 211 | /** Paths *************************************************************/ |
| 187 | 212 | |
| 188 | - // Setup some base path and URL information | |
| 189 | - $this->file = __FILE__; | |
| 190 | - $this->basename = apply_filters( 'bbp_plugin_basenname', plugin_basename( $this->file ) ); | |
| 191 | - $this->plugin_dir = apply_filters( 'bbp_plugin_dir_path', plugin_dir_path( $this->file ) ); | |
| 192 | - $this->plugin_url = apply_filters( 'bbp_plugin_dir_url', plugin_dir_url ( $this->file ) ); | |
| 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 ) ) ); | |
| 193 | 217 | |
| 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 ) ); | |
| 221 | + | |
| 194 | 222 | // Includes |
| 195 | 223 | $this->includes_dir = apply_filters( 'bbp_includes_dir', trailingslashit( $this->plugin_dir . 'includes' ) ); |
| 196 | 224 | $this->includes_url = apply_filters( 'bbp_includes_url', trailingslashit( $this->plugin_url . 'includes' ) ); |
| 197 | 225 | |
| 198 | 226 | // Languages |
| 227 | + $this->lang_base = apply_filters( 'bbp_lang_base', trailingslashit( $this->basepath . 'languages' ) ); | |
| 199 | 228 | $this->lang_dir = apply_filters( 'bbp_lang_dir', trailingslashit( $this->plugin_dir . 'languages' ) ); |
| 200 | 229 | |
| 201 | 230 | // Templates |
| 202 | 231 | $this->themes_dir = apply_filters( 'bbp_themes_dir', trailingslashit( $this->plugin_dir . 'templates' ) ); |
| 203 | 232 | $this->themes_url = apply_filters( 'bbp_themes_url', trailingslashit( $this->plugin_url . 'templates' ) ); |
| 233 | + } | |
| 204 | 234 | |
| 235 | + /** | |
| 236 | + * Smart defaults to many bbPress specific class variables. | |
| 237 | + * | |
| 238 | + * @since 2.6.0 bbPress (r6330) | |
| 239 | + */ | |
| 240 | + private function setup_variables() { | |
| 241 | + | |
| 205 | 242 | /** Identifiers *******************************************************/ |
| 206 | 243 | |
| 207 | 244 | // Post type identifiers |
| 208 | 245 | $this->forum_post_type = apply_filters( 'bbp_forum_post_type', 'forum' ); |
| 209 | 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' ); | |
| 210 | 248 | $this->reply_post_type = apply_filters( 'bbp_reply_post_type', 'reply' ); |
| 211 | - $this->topic_tag_tax_id = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' ); | |
| 212 | 249 | |
| 213 | 250 | // Status identifiers |
| 214 | 251 | $this->spam_status_id = apply_filters( 'bbp_spam_post_status', 'spam' ); |
| 215 | 252 | $this->closed_status_id = apply_filters( 'bbp_closed_post_status', 'closed' ); |
| @@ -220,26 +257,33 @@ | ||
| 220 | 257 | $this->hidden_status_id = apply_filters( 'bbp_hidden_post_status', 'hidden' ); |
| 221 | 258 | $this->trash_status_id = apply_filters( 'bbp_trash_post_status', 'trash' ); |
| 222 | 259 | |
| 223 | 260 | // Other identifiers |
| 224 | - $this->user_id = apply_filters( 'bbp_user_id', 'bbp_user' ); | |
| 225 | - $this->tops_id = apply_filters( 'bbp_tops_id', 'bbp_tops' ); | |
| 226 | - $this->reps_id = apply_filters( 'bbp_reps_id', 'bbp_reps' ); | |
| 227 | - $this->favs_id = apply_filters( 'bbp_favs_id', 'bbp_favs' ); | |
| 228 | - $this->subs_id = apply_filters( 'bbp_subs_id', 'bbp_subs' ); | |
| 229 | - $this->view_id = apply_filters( 'bbp_view_id', 'bbp_view' ); | |
| 230 | - $this->edit_id = apply_filters( 'bbp_edit_id', 'edit' ); | |
| 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' ); | |
| 231 | 271 | |
| 232 | 272 | /** Queries ***********************************************************/ |
| 233 | 273 | |
| 274 | + $this->current_view_id = 0; // Current view id | |
| 234 | 275 | $this->current_forum_id = 0; // Current forum id |
| 235 | 276 | $this->current_topic_id = 0; // Current topic id |
| 236 | 277 | $this->current_reply_id = 0; // Current reply id |
| 237 | 278 | $this->current_topic_tag_id = 0; // Current topic tag id |
| 279 | + $this->current_user_id = 0; // Current topic tag id | |
| 238 | 280 | |
| 239 | - $this->forum_query = new stdClass(); // Main forum query | |
| 240 | - $this->topic_query = new stdClass(); // Main topic query | |
| 241 | - $this->reply_query = new stdClass(); // Main reply query | |
| 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 | |
| 242 | 286 | |
| 243 | 287 | /** Theme Compat ******************************************************/ |
| 244 | 288 | |
| 245 | 289 | $this->theme_compat = new stdClass(); // Base theme compatibility class |
| @@ -246,10 +290,10 @@ | ||
| 246 | 290 | $this->filters = new stdClass(); // Used when adding/removing filters |
| 247 | 291 | |
| 248 | 292 | /** Users *************************************************************/ |
| 249 | 293 | |
| 250 | - $this->current_user = new stdClass(); // Currently logged in user | |
| 251 | - $this->displayed_user = new stdClass(); // Currently displayed user | |
| 294 | + $this->current_user = new WP_User(); // Currently logged in user | |
| 295 | + $this->displayed_user = new WP_User(); // Currently displayed user | |
| 252 | 296 | |
| 253 | 297 | /** Misc **************************************************************/ |
| 254 | 298 | |
| 255 | 299 | $this->domain = 'bbpress'; // Unique identifier for retrieving translated strings |
| @@ -254,79 +298,88 @@ | ||
| 254 | 298 | |
| 255 | 299 | $this->domain = 'bbpress'; // Unique identifier for retrieving translated strings |
| 256 | 300 | $this->extend = new stdClass(); // Plugins add data here |
| 257 | 301 | $this->errors = new WP_Error(); // Feedback |
| 258 | - $this->tab_index = apply_filters( 'bbp_default_tab_index', 100 ); | |
| 259 | 302 | |
| 260 | - /** Cache *************************************************************/ | |
| 303 | + /** Deprecated ********************************************************/ | |
| 261 | 304 | |
| 262 | - // Add bbPress to global cache groups | |
| 263 | - wp_cache_add_global_groups( 'bbpress' ); | |
| 305 | + $this->tab_index = apply_filters( 'bbp_default_tab_index', 100 ); | |
| 264 | 306 | } |
| 265 | 307 | |
| 266 | 308 | /** |
| 267 | 309 | * Include required files |
| 268 | 310 | * |
| 269 | - * @since bbPress (r2626) | |
| 311 | + * @since 2.0.0 bbPress (r2626) | |
| 312 | + * | |
| 270 | 313 | * @access private |
| 271 | - * @uses is_admin() If in WordPress admin, load additional file | |
| 272 | 314 | */ |
| 273 | 315 | private function includes() { |
| 274 | 316 | |
| 275 | 317 | /** Core **************************************************************/ |
| 276 | 318 | |
| 277 | - require( $this->includes_dir . 'core/sub-actions.php' ); | |
| 278 | - require( $this->includes_dir . 'core/functions.php' ); | |
| 279 | - require( $this->includes_dir . 'core/cache.php' ); | |
| 280 | - require( $this->includes_dir . 'core/options.php' ); | |
| 281 | - require( $this->includes_dir . 'core/capabilities.php' ); | |
| 282 | - require( $this->includes_dir . 'core/update.php' ); | |
| 283 | - require( $this->includes_dir . 'core/template-functions.php' ); | |
| 284 | - require( $this->includes_dir . 'core/template-loader.php' ); | |
| 285 | - require( $this->includes_dir . 'core/theme-compat.php' ); | |
| 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'; | |
| 286 | 329 | |
| 287 | 330 | /** Components ********************************************************/ |
| 288 | 331 | |
| 289 | 332 | // Common |
| 290 | - require( $this->includes_dir . 'common/classes.php' ); | |
| 291 | - require( $this->includes_dir . 'common/functions.php' ); | |
| 292 | - require( $this->includes_dir . 'common/template-tags.php' ); | |
| 293 | - require( $this->includes_dir . 'common/widgets.php' ); | |
| 294 | - require( $this->includes_dir . 'common/shortcodes.php' ); | |
| 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'; | |
| 295 | 343 | |
| 296 | 344 | // Forums |
| 297 | - require( $this->includes_dir . 'forums/capabilities.php' ); | |
| 298 | - require( $this->includes_dir . 'forums/functions.php' ); | |
| 299 | - require( $this->includes_dir . 'forums/template-tags.php' ); | |
| 345 | + require $this->includes_dir . 'forums/capabilities.php'; | |
| 346 | + require $this->includes_dir . 'forums/functions.php'; | |
| 347 | + require $this->includes_dir . 'forums/template.php'; | |
| 300 | 348 | |
| 301 | 349 | // Topics |
| 302 | - require( $this->includes_dir . 'topics/capabilities.php' ); | |
| 303 | - require( $this->includes_dir . 'topics/functions.php' ); | |
| 304 | - require( $this->includes_dir . 'topics/template-tags.php' ); | |
| 350 | + require $this->includes_dir . 'topics/capabilities.php'; | |
| 351 | + require $this->includes_dir . 'topics/functions.php'; | |
| 352 | + require $this->includes_dir . 'topics/template.php'; | |
| 305 | 353 | |
| 306 | 354 | // Replies |
| 307 | - require( $this->includes_dir . 'replies/capabilities.php' ); | |
| 308 | - require( $this->includes_dir . 'replies/functions.php' ); | |
| 309 | - require( $this->includes_dir . 'replies/template-tags.php' ); | |
| 355 | + require $this->includes_dir . 'replies/capabilities.php'; | |
| 356 | + require $this->includes_dir . 'replies/functions.php'; | |
| 357 | + require $this->includes_dir . 'replies/template.php'; | |
| 310 | 358 | |
| 359 | + // Search | |
| 360 | + require $this->includes_dir . 'search/functions.php'; | |
| 361 | + require $this->includes_dir . 'search/template.php'; | |
| 362 | + | |
| 311 | 363 | // Users |
| 312 | - require( $this->includes_dir . 'users/capabilities.php' ); | |
| 313 | - require( $this->includes_dir . 'users/functions.php' ); | |
| 314 | - require( $this->includes_dir . 'users/template-tags.php' ); | |
| 315 | - require( $this->includes_dir . 'users/options.php' ); | |
| 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'; | |
| 316 | 370 | |
| 317 | 371 | /** Hooks *************************************************************/ |
| 318 | 372 | |
| 319 | - require( $this->includes_dir . 'core/extend.php' ); | |
| 320 | - require( $this->includes_dir . 'core/actions.php' ); | |
| 321 | - require( $this->includes_dir . 'core/filters.php' ); | |
| 373 | + require $this->includes_dir . 'core/extend.php'; | |
| 374 | + require $this->includes_dir . 'core/actions.php'; | |
| 375 | + require $this->includes_dir . 'core/filters.php'; | |
| 322 | 376 | |
| 323 | 377 | /** Admin *************************************************************/ |
| 324 | 378 | |
| 325 | 379 | // Quick admin check and load if needed |
| 326 | 380 | if ( is_admin() ) { |
| 327 | - require( $this->includes_dir . 'admin/admin.php' ); | |
| 328 | - require( $this->includes_dir . 'admin/actions.php' ); | |
| 381 | + require $this->includes_dir . 'admin/actions.php'; | |
| 329 | 382 | } |
| 330 | 383 | } |
| 331 | 384 | |
| 332 | 385 | /** |
| @@ -331,11 +384,11 @@ | ||
| 331 | 384 | |
| 332 | 385 | /** |
| 333 | 386 | * Setup the default hooks and actions |
| 334 | 387 | * |
| 335 | - * @since bbPress (r2644) | |
| 388 | + * @since 2.0.0 bbPress (r2644) | |
| 389 | + * | |
| 336 | 390 | * @access private |
| 337 | - * @uses add_action() To add various actions | |
| 338 | 391 | */ |
| 339 | 392 | private function setup_actions() { |
| 340 | 393 | |
| 341 | 394 | // Add actions to plugin activation and deactivation hooks |
| @@ -342,15 +395,19 @@ | ||
| 342 | 395 | add_action( 'activate_' . $this->basename, 'bbp_activation' ); |
| 343 | 396 | add_action( 'deactivate_' . $this->basename, 'bbp_deactivation' ); |
| 344 | 397 | |
| 345 | 398 | // If bbPress is being deactivated, do not add any actions |
| 346 | - if ( bbp_is_deactivation( $this->basename ) ) | |
| 399 | + if ( bbp_is_deactivation( $this->basename ) ) { | |
| 347 | 400 | return; |
| 401 | + } | |
| 348 | 402 | |
| 349 | 403 | // Array of bbPress core actions |
| 350 | 404 | $actions = array( |
| 351 | 405 | 'setup_theme', // Setup the default theme compat |
| 352 | 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) | |
| 353 | 410 | 'register_post_types', // Register post types (forum|topic|reply) |
| 354 | 411 | 'register_post_statuses', // Register post statuses (closed|spam|orphan|hidden) |
| 355 | 412 | 'register_taxonomies', // Register taxonomies (topic-tag) |
| 356 | 413 | 'register_shortcodes', // Register shortcodes (bbp-login) |
| @@ -356,15 +413,17 @@ | ||
| 356 | 413 | 'register_shortcodes', // Register shortcodes (bbp-login) |
| 357 | 414 | 'register_views', // Register the views (no-replies) |
| 358 | 415 | 'register_theme_packages', // Register bundled theme packages (bbp-theme-compat/bbp-themes) |
| 359 | 416 | 'load_textdomain', // Load textdomain (bbpress) |
| 360 | - 'add_rewrite_tags', // Add rewrite tags (view|user|edit) | |
| 361 | - '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) | |
| 362 | 420 | ); |
| 363 | 421 | |
| 364 | 422 | // Add the actions |
| 365 | - foreach( $actions as $class_action ) | |
| 423 | + foreach ( $actions as $class_action ) { | |
| 366 | 424 | add_action( 'bbp_' . $class_action, array( $this, $class_action ), 5 ); |
| 425 | + } | |
| 367 | 426 | |
| 368 | 427 | // All bbPress actions are setup (includes bbp-core-hooks.php) |
| 369 | 428 | do_action_ref_array( 'bbp_after_setup_actions', array( &$this ) ); |
| 370 | 429 | } |
| @@ -377,136 +436,84 @@ | ||
| 377 | 436 | * Note that since we currently have complete control over bbp-themes and |
| 378 | 437 | * the bbp-theme-compat folders, it's fine to hardcode these here. If at a |
| 379 | 438 | * later date we need to automate this, and API will need to be built. |
| 380 | 439 | * |
| 381 | - * @since bbPress (r3829) | |
| 440 | + * @since 2.1.0 bbPress (r3829) | |
| 382 | 441 | */ |
| 383 | 442 | public function register_theme_packages() { |
| 384 | 443 | |
| 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 ); | |
| 447 | + | |
| 385 | 448 | // Register the default theme compatibility package |
| 386 | 449 | bbp_register_theme_package( array( |
| 387 | 450 | 'id' => 'default', |
| 388 | - 'name' => __( 'bbPress Default', 'bbpress' ), | |
| 451 | + 'name' => 'bbPress Default', | |
| 389 | 452 | 'version' => bbp_get_version(), |
| 390 | 453 | 'dir' => trailingslashit( $this->themes_dir . 'default' ), |
| 391 | 454 | 'url' => trailingslashit( $this->themes_url . 'default' ) |
| 392 | 455 | ) ); |
| 393 | - | |
| 394 | - // Register the basic theme stack. This is really dope. | |
| 395 | - bbp_register_template_stack( 'get_stylesheet_directory', 10 ); | |
| 396 | - bbp_register_template_stack( 'get_template_directory', 12 ); | |
| 397 | - bbp_register_template_stack( 'bbp_get_theme_compat_dir', 14 ); | |
| 398 | 456 | } |
| 399 | 457 | |
| 400 | 458 | /** |
| 401 | - * Setup the default bbPress theme compatability location. | |
| 459 | + * Setup the default bbPress theme compatibility location. | |
| 402 | 460 | * |
| 403 | - * @since bbPress (r3778) | |
| 461 | + * @since 2.1.0 bbPress (r3778) | |
| 404 | 462 | */ |
| 405 | 463 | public function setup_theme() { |
| 406 | - | |
| 407 | - // Bail if something already has this under control | |
| 408 | - if ( ! empty( $this->theme_compat->theme ) ) | |
| 409 | - return; | |
| 410 | - | |
| 411 | - // Setup the theme package to use for compatibility | |
| 412 | 464 | bbp_setup_theme_compat( bbp_get_theme_package_id() ); |
| 413 | 465 | } |
| 414 | 466 | |
| 415 | 467 | /** |
| 416 | - * Load the translation file for current language. Checks the languages | |
| 417 | - * folder inside the bbPress plugin first, and then the default WordPress | |
| 418 | - * languages folder. | |
| 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. | |
| 419 | 471 | * |
| 420 | 472 | * Note that custom translation files inside the bbPress plugin folder |
| 421 | 473 | * will be removed on bbPress updates. If you're creating custom |
| 422 | 474 | * translation files, please use the global language folder. |
| 423 | 475 | * |
| 424 | - * @since bbPress (r2596) | |
| 425 | - * | |
| 426 | - * @uses apply_filters() Calls 'bbpress_locale' with the | |
| 427 | - * {@link get_locale()} value | |
| 428 | - * @uses load_textdomain() To load the textdomain | |
| 429 | - * @return bool True on success, false on failure | |
| 476 | + * @since 2.0.0 bbPress (r2596) | |
| 430 | 477 | */ |
| 431 | 478 | public function load_textdomain() { |
| 432 | 479 | |
| 433 | - // Traditional WordPress plugin locale filter | |
| 434 | - $locale = apply_filters( 'plugin_locale', get_locale(), $this->domain ); | |
| 435 | - $mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale ); | |
| 480 | + // Define the old directory | |
| 481 | + $old_dir = WP_LANG_DIR . '/bbpress/'; | |
| 436 | 482 | |
| 437 | - // Setup paths to current locale file | |
| 438 | - $mofile_local = $this->lang_dir . $mofile; | |
| 439 | - $mofile_global = WP_LANG_DIR . '/bbpress/' . $mofile; | |
| 483 | + // Old location, deprecated in 2.6.0 | |
| 484 | + if ( is_dir( $old_dir ) ) { | |
| 440 | 485 | |
| 441 | - // Look in global /wp-content/languages/bbpress folder | |
| 442 | - if ( file_exists( $mofile_global ) ) { | |
| 443 | - return load_textdomain( $this->domain, $mofile_global ); | |
| 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 ); | |
| 444 | 490 | |
| 445 | - // Look in local /wp-content/plugins/bbpress/bbp-languages/ folder | |
| 446 | - } elseif ( file_exists( $mofile_local ) ) { | |
| 447 | - return load_textdomain( $this->domain, $mofile_local ); | |
| 491 | + // Look in global /wp-content/languages/bbpress/ folder | |
| 492 | + load_textdomain( $this->domain, $old_dir . $mofile ); | |
| 448 | 493 | } |
| 449 | 494 | |
| 450 | - // Nothing found | |
| 451 | - return false; | |
| 495 | + // Look in global /wp-content/languages/plugins/ | |
| 496 | + load_plugin_textdomain( $this->domain, false, $this->lang_base ); | |
| 452 | 497 | } |
| 453 | 498 | |
| 454 | 499 | /** |
| 455 | 500 | * Setup the post types for forums, topics and replies |
| 456 | 501 | * |
| 457 | - * @since bbPress (r2597) | |
| 458 | - * @uses register_post_type() To register the post types | |
| 459 | - * @uses apply_filters() Calls various filters to modify the arguments | |
| 460 | - * sent to register_post_type() | |
| 502 | + * @since 2.0.0 bbPress (r2597) | |
| 461 | 503 | */ |
| 462 | 504 | public static function register_post_types() { |
| 463 | 505 | |
| 464 | - // Define local variable(s) | |
| 465 | - $post_type = array(); | |
| 466 | - | |
| 467 | 506 | /** Forums ************************************************************/ |
| 468 | 507 | |
| 469 | - // Forum labels | |
| 470 | - $post_type['labels'] = array( | |
| 471 | - 'name' => __( 'Forums', 'bbpress' ), | |
| 472 | - 'menu_name' => __( 'Forums', 'bbpress' ), | |
| 473 | - 'singular_name' => __( 'Forum', 'bbpress' ), | |
| 474 | - 'all_items' => __( 'All Forums', 'bbpress' ), | |
| 475 | - 'add_new' => __( 'New Forum', 'bbpress' ), | |
| 476 | - 'add_new_item' => __( 'Create New Forum', 'bbpress' ), | |
| 477 | - 'edit' => __( 'Edit', 'bbpress' ), | |
| 478 | - 'edit_item' => __( 'Edit Forum', 'bbpress' ), | |
| 479 | - 'new_item' => __( 'New Forum', 'bbpress' ), | |
| 480 | - 'view' => __( 'View Forum', 'bbpress' ), | |
| 481 | - 'view_item' => __( 'View Forum', 'bbpress' ), | |
| 482 | - 'search_items' => __( 'Search Forums', 'bbpress' ), | |
| 483 | - 'not_found' => __( 'No forums found', 'bbpress' ), | |
| 484 | - 'not_found_in_trash' => __( 'No forums found in Trash', 'bbpress' ), | |
| 485 | - 'parent_item_colon' => __( 'Parent Forum:', 'bbpress' ) | |
| 486 | - ); | |
| 487 | - | |
| 488 | - // Forum rewrite | |
| 489 | - $post_type['rewrite'] = array( | |
| 490 | - 'slug' => bbp_get_forum_slug(), | |
| 491 | - 'with_front' => false | |
| 492 | - ); | |
| 493 | - | |
| 494 | - // Forum supports | |
| 495 | - $post_type['supports'] = array( | |
| 496 | - 'title', | |
| 497 | - 'editor', | |
| 498 | - 'revisions' | |
| 499 | - ); | |
| 500 | - | |
| 501 | 508 | // Register Forum content type |
| 502 | 509 | register_post_type( |
| 503 | 510 | bbp_get_forum_post_type(), |
| 504 | 511 | apply_filters( 'bbp_register_forum_post_type', array( |
| 505 | - 'labels' => $post_type['labels'], | |
| 506 | - 'rewrite' => $post_type['rewrite'], | |
| 507 | - 'supports' => $post_type['supports'], | |
| 508 | - 'description' => __( 'bbPress Forums', 'bbpress' ), | |
| 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' ), | |
| 509 | 516 | 'capabilities' => bbp_get_forum_caps(), |
| 510 | 517 | 'capability_type' => array( 'forum', 'forums' ), |
| 511 | 518 | 'menu_position' => 555555, |
| 512 | 519 | 'has_archive' => bbp_get_root_slug(), |
| @@ -516,58 +523,27 @@ | ||
| 516 | 523 | 'show_ui' => current_user_can( 'bbp_forums_admin' ), |
| 517 | 524 | 'can_export' => true, |
| 518 | 525 | 'hierarchical' => true, |
| 519 | 526 | 'query_var' => true, |
| 520 | - 'menu_icon' => '' | |
| 527 | + 'menu_icon' => '', | |
| 528 | + 'source' => 'bbpress', | |
| 521 | 529 | ) ) |
| 522 | 530 | ); |
| 523 | 531 | |
| 524 | 532 | /** Topics ************************************************************/ |
| 525 | 533 | |
| 526 | - // Topic labels | |
| 527 | - $post_type['labels'] = array( | |
| 528 | - 'name' => __( 'Topics', 'bbpress' ), | |
| 529 | - 'menu_name' => __( 'Topics', 'bbpress' ), | |
| 530 | - 'singular_name' => __( 'Topic', 'bbpress' ), | |
| 531 | - 'all_items' => __( 'All Topics', 'bbpress' ), | |
| 532 | - 'add_new' => __( 'New Topic', 'bbpress' ), | |
| 533 | - 'add_new_item' => __( 'Create New Topic', 'bbpress' ), | |
| 534 | - 'edit' => __( 'Edit', 'bbpress' ), | |
| 535 | - 'edit_item' => __( 'Edit Topic', 'bbpress' ), | |
| 536 | - 'new_item' => __( 'New Topic', 'bbpress' ), | |
| 537 | - 'view' => __( 'View Topic', 'bbpress' ), | |
| 538 | - 'view_item' => __( 'View Topic', 'bbpress' ), | |
| 539 | - 'search_items' => __( 'Search Topics', 'bbpress' ), | |
| 540 | - 'not_found' => __( 'No topics found', 'bbpress' ), | |
| 541 | - 'not_found_in_trash' => __( 'No topics found in Trash', 'bbpress' ), | |
| 542 | - 'parent_item_colon' => __( 'Forum:', 'bbpress' ) | |
| 543 | - ); | |
| 544 | - | |
| 545 | - // Topic rewrite | |
| 546 | - $post_type['rewrite'] = array( | |
| 547 | - 'slug' => bbp_get_topic_slug(), | |
| 548 | - 'with_front' => false | |
| 549 | - ); | |
| 550 | - | |
| 551 | - // Topic supports | |
| 552 | - $post_type['supports'] = array( | |
| 553 | - 'title', | |
| 554 | - 'editor', | |
| 555 | - 'revisions' | |
| 556 | - ); | |
| 557 | - | |
| 558 | 534 | // Register Topic content type |
| 559 | 535 | register_post_type( |
| 560 | 536 | bbp_get_topic_post_type(), |
| 561 | 537 | apply_filters( 'bbp_register_topic_post_type', array( |
| 562 | - 'labels' => $post_type['labels'], | |
| 563 | - 'rewrite' => $post_type['rewrite'], | |
| 564 | - 'supports' => $post_type['supports'], | |
| 565 | - 'description' => __( 'bbPress Topics', 'bbpress' ), | |
| 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' ), | |
| 566 | 542 | 'capabilities' => bbp_get_topic_caps(), |
| 567 | 543 | 'capability_type' => array( 'topic', 'topics' ), |
| 568 | 544 | 'menu_position' => 555555, |
| 569 | - 'has_archive' => bbp_get_topic_archive_slug(), | |
| 545 | + 'has_archive' => ( 'forums' === bbp_show_on_root() ) ? bbp_get_topic_archive_slug() : false, | |
| 570 | 546 | 'exclude_from_search' => true, |
| 571 | 547 | 'show_in_nav_menus' => false, |
| 572 | 548 | 'public' => true, |
| 573 | 549 | 'show_ui' => current_user_can( 'bbp_topics_admin' ), |
| @@ -573,54 +549,23 @@ | ||
| 573 | 549 | 'show_ui' => current_user_can( 'bbp_topics_admin' ), |
| 574 | 550 | 'can_export' => true, |
| 575 | 551 | 'hierarchical' => false, |
| 576 | 552 | 'query_var' => true, |
| 577 | - 'menu_icon' => '' | |
| 553 | + 'menu_icon' => '', | |
| 554 | + 'source' => 'bbpress', | |
| 578 | 555 | ) |
| 579 | 556 | ) ); |
| 580 | 557 | |
| 581 | 558 | /** Replies ***********************************************************/ |
| 582 | 559 | |
| 583 | - // Reply labels | |
| 584 | - $post_type['labels'] = array( | |
| 585 | - 'name' => __( 'Replies', 'bbpress' ), | |
| 586 | - 'menu_name' => __( 'Replies', 'bbpress' ), | |
| 587 | - 'singular_name' => __( 'Reply', 'bbpress' ), | |
| 588 | - 'all_items' => __( 'All Replies', 'bbpress' ), | |
| 589 | - 'add_new' => __( 'New Reply', 'bbpress' ), | |
| 590 | - 'add_new_item' => __( 'Create New Reply', 'bbpress' ), | |
| 591 | - 'edit' => __( 'Edit', 'bbpress' ), | |
| 592 | - 'edit_item' => __( 'Edit Reply', 'bbpress' ), | |
| 593 | - 'new_item' => __( 'New Reply', 'bbpress' ), | |
| 594 | - 'view' => __( 'View Reply', 'bbpress' ), | |
| 595 | - 'view_item' => __( 'View Reply', 'bbpress' ), | |
| 596 | - 'search_items' => __( 'Search Replies', 'bbpress' ), | |
| 597 | - 'not_found' => __( 'No replies found', 'bbpress' ), | |
| 598 | - 'not_found_in_trash' => __( 'No replies found in Trash', 'bbpress' ), | |
| 599 | - 'parent_item_colon' => __( 'Topic:', 'bbpress' ) | |
| 600 | - ); | |
| 601 | - | |
| 602 | - // Reply rewrite | |
| 603 | - $post_type['rewrite'] = array( | |
| 604 | - 'slug' => bbp_get_reply_slug(), | |
| 605 | - 'with_front' => false | |
| 606 | - ); | |
| 607 | - | |
| 608 | - // Reply supports | |
| 609 | - $post_type['supports'] = array( | |
| 610 | - 'title', | |
| 611 | - 'editor', | |
| 612 | - 'revisions' | |
| 613 | - ); | |
| 614 | - | |
| 615 | 560 | // Register reply content type |
| 616 | 561 | register_post_type( |
| 617 | 562 | bbp_get_reply_post_type(), |
| 618 | 563 | apply_filters( 'bbp_register_reply_post_type', array( |
| 619 | - 'labels' => $post_type['labels'], | |
| 620 | - 'rewrite' => $post_type['rewrite'], | |
| 621 | - 'supports' => $post_type['supports'], | |
| 622 | - 'description' => __( 'bbPress Replies', 'bbpress' ), | |
| 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' ), | |
| 623 | 568 | 'capabilities' => bbp_get_reply_caps(), |
| 624 | 569 | 'capability_type' => array( 'reply', 'replies' ), |
| 625 | 570 | 'menu_position' => 555555, |
| 626 | 571 | 'exclude_from_search' => true, |
| @@ -630,9 +575,10 @@ | ||
| 630 | 575 | 'show_ui' => current_user_can( 'bbp_replies_admin' ), |
| 631 | 576 | 'can_export' => true, |
| 632 | 577 | 'hierarchical' => false, |
| 633 | 578 | 'query_var' => true, |
| 634 | - 'menu_icon' => '' | |
| 579 | + 'menu_icon' => '', | |
| 580 | + 'source' => 'bbpress', | |
| 635 | 581 | ) ) |
| 636 | 582 | ); |
| 637 | 583 | } |
| 638 | 584 | |
| @@ -641,13 +587,9 @@ | ||
| 641 | 587 | * |
| 642 | 588 | * We do some manipulation of the 'trash' status so trashed topics and |
| 643 | 589 | * replies can be viewed from within the theme. |
| 644 | 590 | * |
| 645 | - * @since bbPress (r2727) | |
| 646 | - * @uses register_post_status() To register post statuses | |
| 647 | - * @uses $wp_post_statuses To modify trash and private statuses | |
| 648 | - * @uses current_user_can() To check if the current user is capable & | |
| 649 | - * modify $wp_post_statuses accordingly | |
| 591 | + * @since 2.0.0 bbPress (r2727) | |
| 650 | 592 | */ |
| 651 | 593 | public static function register_post_statuses() { |
| 652 | 594 | |
| 653 | 595 | // Closed |
| @@ -653,12 +595,14 @@ | ||
| 653 | 595 | // Closed |
| 654 | 596 | register_post_status( |
| 655 | 597 | bbp_get_closed_status_id(), |
| 656 | 598 | apply_filters( 'bbp_register_closed_post_status', array( |
| 657 | - 'label' => _x( 'Closed', 'post', 'bbpress' ), | |
| 658 | - 'label_count' => _nx_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'bbpress' ), | |
| 659 | - 'public' => true, | |
| 660 | - 'show_in_admin_all' => true | |
| 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' | |
| 661 | 605 | ) ) |
| 662 | 606 | ); |
| 663 | 607 | |
| 664 | 608 | // Spam |
| @@ -665,15 +609,16 @@ | ||
| 665 | 609 | register_post_status( |
| 666 | 610 | bbp_get_spam_status_id(), |
| 667 | 611 | apply_filters( 'bbp_register_spam_post_status', array( |
| 668 | 612 | 'label' => _x( 'Spam', 'post', 'bbpress' ), |
| 669 | - 'label_count' => _nx_noop( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'bbpress' ), | |
| 613 | + 'label_count' => _nx_noop( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'post', 'bbpress' ), | |
| 670 | 614 | 'protected' => true, |
| 671 | 615 | 'exclude_from_search' => true, |
| 672 | 616 | 'show_in_admin_status_list' => true, |
| 673 | - 'show_in_admin_all_list' => false | |
| 617 | + 'show_in_admin_all_list' => false, | |
| 618 | + 'source' => 'bbpress' | |
| 674 | 619 | ) ) |
| 675 | - ); | |
| 620 | + ); | |
| 676 | 621 | |
| 677 | 622 | // Orphan |
| 678 | 623 | register_post_status( |
| 679 | 624 | bbp_get_orphan_status_id(), |
| @@ -678,13 +623,14 @@ | ||
| 678 | 623 | register_post_status( |
| 679 | 624 | bbp_get_orphan_status_id(), |
| 680 | 625 | apply_filters( 'bbp_register_orphan_post_status', array( |
| 681 | 626 | 'label' => _x( 'Orphan', 'post', 'bbpress' ), |
| 682 | - 'label_count' => _nx_noop( 'Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'bbpress' ), | |
| 627 | + 'label_count' => _nx_noop( 'Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'post', 'bbpress' ), | |
| 683 | 628 | 'protected' => true, |
| 684 | 629 | 'exclude_from_search' => true, |
| 685 | 630 | 'show_in_admin_status_list' => true, |
| 686 | - 'show_in_admin_all_list' => false | |
| 631 | + 'show_in_admin_all_list' => false, | |
| 632 | + 'source' => 'bbpress' | |
| 687 | 633 | ) ) |
| 688 | 634 | ); |
| 689 | 635 | |
| 690 | 636 | // Hidden |
| @@ -691,13 +637,14 @@ | ||
| 691 | 637 | register_post_status( |
| 692 | 638 | bbp_get_hidden_status_id(), |
| 693 | 639 | apply_filters( 'bbp_register_hidden_post_status', array( |
| 694 | 640 | 'label' => _x( 'Hidden', 'post', 'bbpress' ), |
| 695 | - 'label_count' => _nx_noop( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'bbpress' ), | |
| 641 | + 'label_count' => _nx_noop( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'post', 'bbpress' ), | |
| 696 | 642 | 'private' => true, |
| 697 | 643 | 'exclude_from_search' => true, |
| 698 | 644 | 'show_in_admin_status_list' => true, |
| 699 | - 'show_in_admin_all_list' => true | |
| 645 | + 'show_in_admin_all_list' => true, | |
| 646 | + 'source' => 'bbpress' | |
| 700 | 647 | ) ) |
| 701 | 648 | ); |
| 702 | 649 | |
| 703 | 650 | /** |
| @@ -709,9 +656,9 @@ | ||
| 709 | 656 | * doesn't allow any hack for the trashed topics to be viewed. |
| 710 | 657 | */ |
| 711 | 658 | global $wp_post_statuses; |
| 712 | 659 | |
| 713 | - if ( !empty( $wp_post_statuses['trash'] ) ) { | |
| 660 | + if ( ! empty( $wp_post_statuses['trash'] ) ) { | |
| 714 | 661 | |
| 715 | 662 | // User can view trash so set internal to false |
| 716 | 663 | if ( current_user_can( 'view_trash' ) ) { |
| 717 | 664 | $wp_post_statuses['trash']->internal = false; |
| @@ -717,9 +664,9 @@ | ||
| 717 | 664 | $wp_post_statuses['trash']->internal = false; |
| 718 | 665 | $wp_post_statuses['trash']->protected = true; |
| 719 | 666 | |
| 720 | 667 | // User cannot view trash so set internal to true |
| 721 | - } elseif ( !current_user_can( 'view_trash' ) ) { | |
| 668 | + } else { | |
| 722 | 669 | $wp_post_statuses['trash']->internal = true; |
| 723 | 670 | } |
| 724 | 671 | } |
| 725 | 672 | } |
| @@ -724,52 +671,30 @@ | ||
| 724 | 671 | } |
| 725 | 672 | } |
| 726 | 673 | |
| 727 | 674 | /** |
| 728 | - * Register the topic tag taxonomy | |
| 675 | + * Register the topic tag and forum moderator taxonomies | |
| 729 | 676 | * |
| 730 | - * @since bbPress (r2464) | |
| 731 | - * @uses register_taxonomy() To register the taxonomy | |
| 677 | + * @since 2.0.0 bbPress (r2464) Added bbp_get_topic_tag_tax_id() taxonomy | |
| 732 | 678 | */ |
| 733 | 679 | public static function register_taxonomies() { |
| 734 | 680 | |
| 735 | - // Define local variable(s) | |
| 736 | - $topic_tag = array(); | |
| 737 | - | |
| 738 | - // Topic tag labels | |
| 739 | - $topic_tag['labels'] = array( | |
| 740 | - 'name' => __( 'Topic Tags', 'bbpress' ), | |
| 741 | - 'singular_name' => __( 'Topic Tag', 'bbpress' ), | |
| 742 | - 'search_items' => __( 'Search Tags', 'bbpress' ), | |
| 743 | - 'popular_items' => __( 'Popular Tags', 'bbpress' ), | |
| 744 | - 'all_items' => __( 'All Tags', 'bbpress' ), | |
| 745 | - 'edit_item' => __( 'Edit Tag', 'bbpress' ), | |
| 746 | - 'update_item' => __( 'Update Tag', 'bbpress' ), | |
| 747 | - 'add_new_item' => __( 'Add New Tag', 'bbpress' ), | |
| 748 | - 'new_item_name' => __( 'New Tag Name', 'bbpress' ), | |
| 749 | - 'view_item' => __( 'View Topic Tag', 'bbpress' ) | |
| 750 | - ); | |
| 751 | - | |
| 752 | - // Topic tag rewrite | |
| 753 | - $topic_tag['rewrite'] = array( | |
| 754 | - 'slug' => bbp_get_topic_tag_tax_slug(), | |
| 755 | - 'with_front' => false | |
| 756 | - ); | |
| 757 | - | |
| 758 | - // Register the topic tag taxonomy | |
| 681 | + // Register the topic-tag taxonomy. | |
| 759 | 682 | register_taxonomy( |
| 760 | 683 | bbp_get_topic_tag_tax_id(), |
| 761 | 684 | bbp_get_topic_post_type(), |
| 762 | 685 | apply_filters( 'bbp_register_topic_taxonomy', array( |
| 763 | - 'labels' => $topic_tag['labels'], | |
| 764 | - 'rewrite' => $topic_tag['rewrite'], | |
| 686 | + 'labels' => bbp_get_topic_tag_tax_labels(), | |
| 687 | + 'rewrite' => bbp_get_topic_tag_tax_rewrite(), | |
| 765 | 688 | 'capabilities' => bbp_get_topic_tag_caps(), |
| 766 | - 'update_count_callback' => '_update_post_term_count', | |
| 689 | + 'update_count_callback' => 'bbp_update_topic_tag_count', | |
| 767 | 690 | 'query_var' => true, |
| 768 | 691 | 'show_tagcloud' => true, |
| 769 | 692 | 'hierarchical' => false, |
| 693 | + 'show_in_nav_menus' => false, | |
| 770 | 694 | 'public' => true, |
| 771 | - 'show_ui' => bbp_allow_topic_tags() && current_user_can( 'bbp_topic_tags_admin' ) | |
| 695 | + 'show_ui' => bbp_allow_topic_tags() && current_user_can( 'bbp_topic_tags_admin' ), | |
| 696 | + 'source' => 'bbpress' | |
| 772 | 697 | ) |
| 773 | 698 | ) ); |
| 774 | 699 | } |
| 775 | 700 | |
| @@ -775,22 +700,36 @@ | ||
| 775 | 700 | |
| 776 | 701 | /** |
| 777 | 702 | * Register the bbPress views |
| 778 | 703 | * |
| 779 | - * @since bbPress (r2789) | |
| 780 | - * @uses bbp_register_view() To register the views | |
| 704 | + * @since 2.0.0 bbPress (r2789) | |
| 781 | 705 | */ |
| 782 | 706 | public static function register_views() { |
| 783 | 707 | |
| 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 | + ) ); | |
| 720 | + | |
| 784 | 721 | // Topics with no replies |
| 785 | 722 | bbp_register_view( |
| 786 | 723 | 'no-replies', |
| 787 | - __( 'Topics with no replies', 'bbpress' ), | |
| 724 | + esc_html__( 'Topics with no replies', 'bbpress' ), | |
| 788 | 725 | apply_filters( 'bbp_register_view_no_replies', array( |
| 789 | - 'meta_key' => '_bbp_reply_count', | |
| 790 | - 'meta_value' => 1, | |
| 791 | - 'meta_compare' => '<', | |
| 792 | - 'orderby' => '' | |
| 726 | + 'meta_key' => '_bbp_reply_count', | |
| 727 | + 'meta_type' => 'NUMERIC', | |
| 728 | + 'meta_value' => 1, | |
| 729 | + 'meta_compare' => '<', | |
| 730 | + 'orderby' => '', | |
| 731 | + 'show_stickies' => false | |
| 793 | 732 | ) |
| 794 | 733 | ) ); |
| 795 | 734 | } |
| 796 | 735 | |
| @@ -796,11 +735,9 @@ | ||
| 796 | 735 | |
| 797 | 736 | /** |
| 798 | 737 | * Register the bbPress shortcodes |
| 799 | 738 | * |
| 800 | - * @since bbPress (r3031) | |
| 801 | - * | |
| 802 | - * @uses BBP_Shortcodes | |
| 739 | + * @since 2.0.0 bbPress (r3031) | |
| 803 | 740 | */ |
| 804 | 741 | public function register_shortcodes() { |
| 805 | 742 | $this->shortcodes = new BBP_Shortcodes(); |
| 806 | 743 | } |
| @@ -805,115 +742,292 @@ | ||
| 805 | 742 | $this->shortcodes = new BBP_Shortcodes(); |
| 806 | 743 | } |
| 807 | 744 | |
| 808 | 745 | /** |
| 746 | + * Register bbPress meta-data | |
| 747 | + * | |
| 748 | + * Counts added in 2.6.0 to avoid negative values | |
| 749 | + * | |
| 750 | + * @since 2.6.0 bbPress (r6300) | |
| 751 | + */ | |
| 752 | + public function register_meta() { | |
| 753 | + | |
| 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' | |
| 803 | + ) ); | |
| 804 | + } | |
| 805 | + | |
| 806 | + /** | |
| 809 | 807 | * Setup the currently logged-in user |
| 810 | 808 | * |
| 811 | - * Do not to call this prematurely, I.E. before the 'init' action has | |
| 812 | - * started. This function is naturally hooked into 'init' to ensure proper | |
| 813 | - * execution. get_currentuserinfo() is used to check for XMLRPC_REQUEST to | |
| 814 | - * avoid xmlrpc errors. | |
| 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 | |
| 815 | 817 | * |
| 816 | - * @since bbPress (r2697) | |
| 817 | - * @uses wp_get_current_user() | |
| 818 | + * @since 2.6.0 bbPress (r6875) | |
| 818 | 819 | */ |
| 819 | - public function setup_current_user() { | |
| 820 | - $this->current_user = &wp_get_current_user(); | |
| 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(); | |
| 821 | 828 | } |
| 822 | 829 | |
| 830 | + /** | |
| 831 | + * Initialize forum-specific roles | |
| 832 | + * | |
| 833 | + * @since 2.6.0 | |
| 834 | + */ | |
| 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 ) ); | |
| 850 | + } | |
| 851 | + | |
| 823 | 852 | /** Custom Rewrite Rules **************************************************/ |
| 824 | 853 | |
| 825 | 854 | /** |
| 826 | 855 | * Add the bbPress-specific rewrite tags |
| 827 | 856 | * |
| 828 | - * @since bbPress (r2753) | |
| 829 | - * @uses add_rewrite_tag() To add the rewrite tags | |
| 857 | + * @since 2.0.0 bbPress (r2753) | |
| 830 | 858 | */ |
| 831 | 859 | public static function add_rewrite_tags() { |
| 832 | - add_rewrite_tag( '%%' . bbp_get_view_rewrite_id() . '%%', '([^/]+)' ); // View Page tag | |
| 833 | - add_rewrite_tag( '%%' . bbp_get_edit_rewrite_id() . '%%', '([1]{1,})' ); // Edit Page tag | |
| 834 | - add_rewrite_tag( '%%' . bbp_get_user_rewrite_id() . '%%', '([^/]+)' ); // User Profile tag | |
| 835 | - add_rewrite_tag( '%%' . bbp_get_user_favorites_rewrite_id() . '%%', '([1]{1,})' ); // User Favorites tag | |
| 836 | - add_rewrite_tag( '%%' . bbp_get_user_subscriptions_rewrite_id() . '%%', '([1]{1,})' ); // User Subscriptions tag | |
| 837 | - add_rewrite_tag( '%%' . bbp_get_user_topics_rewrite_id() . '%%', '([1]{1,})' ); // User Topics Tag | |
| 838 | - add_rewrite_tag( '%%' . bbp_get_user_replies_rewrite_id() . '%%', '([1]{1,})' ); // User Replies Tag | |
| 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 | |
| 839 | 869 | } |
| 840 | 870 | |
| 841 | 871 | /** |
| 842 | - * Register bbPress-specific rewrite rules for uri's that are not | |
| 872 | + * Add bbPress-specific rewrite rules for uri's that are not | |
| 843 | 873 | * setup for us by way of custom post types or taxonomies. This includes: |
| 844 | 874 | * - Front-end editing |
| 845 | 875 | * - Topic views |
| 846 | 876 | * - User profiles |
| 847 | 877 | * |
| 848 | - * @since bbPress (r2688) | |
| 849 | - * @param WP_Rewrite $wp_rewrite bbPress-sepecific rules are appended in | |
| 850 | - * $wp_rewrite->rules | |
| 878 | + * @since 2.0.0 bbPress (r2688) | |
| 879 | + * | |
| 880 | + * @todo Extract into an API | |
| 851 | 881 | */ |
| 852 | - public static function generate_rewrite_rules( $wp_rewrite ) { | |
| 882 | + public static function add_rewrite_rules() { | |
| 853 | 883 | |
| 854 | - // Slugs | |
| 855 | - $view_slug = bbp_get_view_slug(); | |
| 856 | - $user_slug = bbp_get_user_slug(); | |
| 884 | + /** Setup *************************************************************/ | |
| 857 | 885 | |
| 886 | + // Add rules to top or bottom? | |
| 887 | + $priority = 'top'; | |
| 888 | + | |
| 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(); | |
| 894 | + | |
| 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(); | |
| 901 | + | |
| 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 | + | |
| 858 | 910 | // Unique rewrite ID's |
| 859 | - $edit_id = bbp_get_edit_rewrite_id(); | |
| 860 | - $view_id = bbp_get_view_rewrite_id(); | |
| 861 | - $user_id = bbp_get_user_rewrite_id(); | |
| 862 | - $favs_id = bbp_get_user_favorites_rewrite_id(); | |
| 863 | - $subs_id = bbp_get_user_subscriptions_rewrite_id(); | |
| 864 | - $tops_id = bbp_get_user_topics_rewrite_id(); | |
| 865 | - $reps_id = bbp_get_user_replies_rewrite_id(); | |
| 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(); | |
| 866 | 922 | |
| 867 | 923 | // Rewrite rule matches used repeatedly below |
| 868 | - $root_rule = '/([^/]+)/?$'; | |
| 869 | - $edit_rule = '/([^/]+)/edit/?$'; | |
| 870 | - $feed_rule = '/([^/]+)/feed/?$'; | |
| 871 | - $page_rule = '/([^/]+)/page/?([0-9]{1,})/?$'; | |
| 924 | + $root_rule = '/([^/]+)/?$'; | |
| 925 | + $feed_rule = '/([^/]+)/' . $feed_slug . '/?$'; | |
| 926 | + $edit_rule = '/([^/]+)/' . $edit_slug . '/?$'; | |
| 927 | + $paged_rule = '/([^/]+)/' . $paged_slug . '/?([0-9]{1,})/?$'; | |
| 872 | 928 | |
| 929 | + // Search rules (without slug check) | |
| 930 | + $search_root_rule = '/?$'; | |
| 931 | + $search_paged_rule = '/' . $paged_slug . '/?([0-9]{1,})/?$'; | |
| 932 | + | |
| 933 | + /** Add ***************************************************************/ | |
| 934 | + | |
| 873 | 935 | // User profile rules |
| 874 | - $tops_rule = '/([^/]+)/topics/?$'; | |
| 875 | - $reps_rule = '/([^/]+)/replies/?$'; | |
| 876 | - $favs_rule = '/([^/]+)/' . bbp_get_user_favorites_slug() . '/?$'; | |
| 877 | - $subs_rule = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/?$'; | |
| 878 | - $tops_page_rule = '/([^/]+)/topics/page/?([0-9]{1,})/?$'; | |
| 879 | - $reps_page_rule = '/([^/]+)/replies/page/?([0-9]{1,})/?$'; | |
| 880 | - $favs_page_rule = '/([^/]+)/' . bbp_get_user_favorites_slug() . '/page/?([0-9]{1,})/?$'; | |
| 881 | - $subs_page_rule = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/page/?([0-9]{1,})/?$'; | |
| 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,})/?$'; | |
| 882 | 946 | |
| 883 | - // New bbPress specific rules to merge with existing that are not | |
| 884 | - // handled automatically by custom post types or taxonomy types | |
| 885 | - $bbp_rules = array( | |
| 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 ); | |
| 886 | 952 | |
| 887 | - // Edit Forum|Topic|Reply|Topic-tag | |
| 888 | - bbp_get_forum_slug() . $edit_rule => 'index.php?' . bbp_get_forum_post_type() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1', | |
| 889 | - bbp_get_topic_slug() . $edit_rule => 'index.php?' . bbp_get_topic_post_type() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1', | |
| 890 | - bbp_get_reply_slug() . $edit_rule => 'index.php?' . bbp_get_reply_post_type() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1', | |
| 891 | - bbp_get_topic_tag_tax_slug() . $edit_rule => 'index.php?' . bbp_get_topic_tag_tax_id() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1', | |
| 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 ); | |
| 892 | 966 | |
| 893 | - // User Pagination|Edit|View | |
| 894 | - $user_slug . $tops_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $tops_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ), | |
| 895 | - $user_slug . $reps_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $reps_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ), | |
| 896 | - $user_slug . $favs_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $favs_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ), | |
| 897 | - $user_slug . $subs_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $subs_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ), | |
| 898 | - $user_slug . $tops_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $tops_id . '=1', | |
| 899 | - $user_slug . $reps_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $reps_id . '=1', | |
| 900 | - $user_slug . $favs_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $favs_id . '=1', | |
| 901 | - $user_slug . $subs_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $subs_id . '=1', | |
| 902 | - $user_slug . $edit_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1', | |
| 903 | - $user_slug . $root_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ), | |
| 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 ); | |
| 904 | 971 | |
| 905 | - // Topic-View Pagination|Feed|View | |
| 906 | - $view_slug . $page_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ), | |
| 907 | - $view_slug . $feed_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&feed=' . $wp_rewrite->preg_index( 2 ), | |
| 908 | - $view_slug . $root_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ), | |
| 909 | - ); | |
| 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 ); | |
| 975 | + } | |
| 910 | 976 | |
| 911 | - // Merge bbPress rules with existing | |
| 912 | - $wp_rewrite->rules = array_merge( $bbp_rules, $wp_rewrite->rules ); | |
| 977 | + /** | |
| 978 | + * Add permalink structures for new archive-style destinations. | |
| 979 | + * | |
| 980 | + * - Users | |
| 981 | + * - Topic Views | |
| 982 | + * - Search | |
| 983 | + * | |
| 984 | + * @since 2.4.0 bbPress (r4930) | |
| 985 | + */ | |
| 986 | + public static function add_permastructs() { | |
| 913 | 987 | |
| 914 | - // Return merged rules | |
| 915 | - return $wp_rewrite; | |
| 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(); | |
| 992 | + | |
| 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(); | |
| 997 | + | |
| 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 | + ) ); | |
| 1008 | + | |
| 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 | + ) ); | |
| 1019 | + | |
| 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 | + ) ); | |
| 916 | 1030 | } |
| 917 | 1031 | } |
| 918 | 1032 | |
| 919 | 1033 | /** |
| @@ -924,12 +1038,14 @@ | ||
| 924 | 1038 | * to declare the global. |
| 925 | 1039 | * |
| 926 | 1040 | * Example: <?php $bbp = bbpress(); ?> |
| 927 | 1041 | * |
| 928 | - * @return The one true bbPress Instance | |
| 1042 | + * @since 2.0.0 bbPress (r2464) | |
| 1043 | + * | |
| 1044 | + * @return bbPress The one true bbPress Instance | |
| 929 | 1045 | */ |
| 930 | 1046 | function bbpress() { |
| 931 | - return bbpress::instance(); | |
| 1047 | + return bbPress::instance(); | |
| 932 | 1048 | } |
| 933 | 1049 | |
| 934 | 1050 | /** |
| 935 | 1051 | * Hook bbPress early onto the 'plugins_loaded' action. |