| @@ -7,15 +7,15 @@ | ||
| 7 | 7 | * @subpackage Shortcodes |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | // Exit if accessed directly |
| 11 | -if ( !defined( 'ABSPATH' ) ) exit; | |
| 11 | +defined( 'ABSPATH' ) || exit; | |
| 12 | 12 | |
| 13 | -if ( !class_exists( 'BBP_Shortcodes' ) ) : | |
| 13 | +if ( ! class_exists( 'BBP_Shortcodes' ) ) : | |
| 14 | 14 | /** |
| 15 | 15 | * bbPress Shortcode Class |
| 16 | 16 | * |
| 17 | - * @since bbPress (r3031) | |
| 17 | + * @since 2.0.0 bbPress (r3031) | |
| 18 | 18 | */ |
| 19 | 19 | class BBP_Shortcodes { |
| 20 | 20 | |
| 21 | 21 | /** Vars ******************************************************************/ |
| @@ -29,12 +29,10 @@ | ||
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Add the register_shortcodes action to bbp_init |
| 32 | 32 | * |
| 33 | - * @since bbPress (r3031) | |
| 33 | + * @since 2.0.0 bbPress (r3031) | |
| 34 | 34 | * |
| 35 | - * @uses setup_globals() | |
| 36 | - * @uses add_shortcodes() | |
| 37 | 35 | */ |
| 38 | 36 | public function __construct() { |
| 39 | 37 | $this->setup_globals(); |
| 40 | 38 | $this->add_shortcodes(); |
| @@ -42,12 +40,11 @@ | ||
| 42 | 40 | |
| 43 | 41 | /** |
| 44 | 42 | * Shortcode globals |
| 45 | 43 | * |
| 46 | - * @since bbPress (r3143) | |
| 44 | + * @since 2.0.0 bbPress (r3143) | |
| 45 | + * | |
| 47 | 46 | * @access private |
| 48 | - * | |
| 49 | - * @uses apply_filters() | |
| 50 | 47 | */ |
| 51 | 48 | private function setup_globals() { |
| 52 | 49 | |
| 53 | 50 | // Setup the shortcodes |
| @@ -78,13 +75,22 @@ | ||
| 78 | 75 | /** Views *********************************************************/ |
| 79 | 76 | |
| 80 | 77 | 'bbp-single-view' => array( $this, 'display_view' ), // Single view |
| 81 | 78 | |
| 79 | + /** Search ********************************************************/ | |
| 80 | + | |
| 81 | + 'bbp-search-form' => array( $this, 'display_search_form' ), // Search form | |
| 82 | + 'bbp-search' => array( $this, 'display_search' ), // Search | |
| 83 | + | |
| 82 | 84 | /** Account *******************************************************/ |
| 83 | 85 | |
| 84 | 86 | 'bbp-login' => array( $this, 'display_login' ), // Login |
| 85 | 87 | 'bbp-register' => array( $this, 'display_register' ), // Register |
| 86 | 88 | 'bbp-lost-pass' => array( $this, 'display_lost_pass' ), // Lost Password |
| 89 | + | |
| 90 | + /** Others *******************************************************/ | |
| 91 | + | |
| 92 | + 'bbp-stats' => array( $this, 'display_stats' ), // Stats | |
| 87 | 93 | ) ); |
| 88 | 94 | } |
| 89 | 95 | |
| 90 | 96 | /** |
| @@ -89,15 +95,12 @@ | ||
| 89 | 95 | |
| 90 | 96 | /** |
| 91 | 97 | * Register the bbPress shortcodes |
| 92 | 98 | * |
| 93 | - * @since bbPress (r3031) | |
| 94 | - * | |
| 95 | - * @uses add_shortcode() | |
| 96 | - * @uses do_action() | |
| 99 | + * @since 2.0.0 bbPress (r3031) | |
| 97 | 100 | */ |
| 98 | 101 | private function add_shortcodes() { |
| 99 | - foreach( (array) $this->codes as $code => $function ) { | |
| 102 | + foreach ( (array) $this->codes as $code => $function ) { | |
| 100 | 103 | add_shortcode( $code, $function ); |
| 101 | 104 | } |
| 102 | 105 | } |
| 103 | 106 | |
| @@ -103,19 +106,21 @@ | ||
| 103 | 106 | |
| 104 | 107 | /** |
| 105 | 108 | * Unset some globals in the $bbp object that hold query related info |
| 106 | 109 | * |
| 107 | - * @since bbPress (r3034) | |
| 110 | + * @since 2.0.0 bbPress (r3034) | |
| 108 | 111 | */ |
| 109 | 112 | private function unset_globals() { |
| 110 | 113 | $bbp = bbpress(); |
| 111 | 114 | |
| 112 | 115 | // Unset global queries |
| 113 | - $bbp->forum_query = new stdClass; | |
| 114 | - $bbp->topic_query = new stdClass; | |
| 115 | - $bbp->reply_query = new stdClass; | |
| 116 | + $bbp->forum_query = new WP_Query(); | |
| 117 | + $bbp->topic_query = new WP_Query(); | |
| 118 | + $bbp->reply_query = new WP_Query(); | |
| 119 | + $bbp->search_query = new WP_Query(); | |
| 116 | 120 | |
| 117 | 121 | // Unset global ID's |
| 122 | + $bbp->current_view_id = 0; | |
| 118 | 123 | $bbp->current_forum_id = 0; |
| 119 | 124 | $bbp->current_topic_id = 0; |
| 120 | 125 | $bbp->current_reply_id = 0; |
| 121 | 126 | $bbp->current_topic_tag_id = 0; |
| @@ -132,14 +137,11 @@ | ||
| 132 | 137 | * This is used to put the contents of the shortcode into a variable rather |
| 133 | 138 | * than outputting the HTML at run-time. This allows shortcodes to appear |
| 134 | 139 | * in the correct location in the_content() instead of when it's created. |
| 135 | 140 | * |
| 136 | - * @since bbPress (r3079) | |
| 141 | + * @since 2.0.0 bbPress (r3079) | |
| 137 | 142 | * |
| 138 | 143 | * @param string $query_name |
| 139 | - * | |
| 140 | - * @uses bbp_set_query_name() | |
| 141 | - * @uses ob_start() | |
| 142 | 144 | */ |
| 143 | 145 | private function start( $query_name = '' ) { |
| 144 | 146 | |
| 145 | 147 | // Set query name |
| @@ -144,11 +146,8 @@ | ||
| 144 | 146 | |
| 145 | 147 | // Set query name |
| 146 | 148 | bbp_set_query_name( $query_name ); |
| 147 | 149 | |
| 148 | - // Remove 'bbp_replace_the_content' filter to prevent infinite loops | |
| 149 | - remove_filter( 'the_content', 'bbp_replace_the_content' ); | |
| 150 | - | |
| 151 | 150 | // Start output buffer |
| 152 | 151 | ob_start(); |
| 153 | 152 | } |
| 154 | 153 | |
| @@ -154,31 +153,28 @@ | ||
| 154 | 153 | |
| 155 | 154 | /** |
| 156 | 155 | * Return the contents of the output buffer and flush its contents. |
| 157 | 156 | * |
| 158 | - * @since bbPress( r3079) | |
| 157 | + * @since 2.0.0 bbPress (r3079) | |
| 159 | 158 | * |
| 160 | - * @uses BBP_Shortcodes::unset_globals() Cleans up global values | |
| 161 | 159 | * @return string Contents of output buffer. |
| 162 | 160 | */ |
| 163 | 161 | private function end() { |
| 164 | 162 | |
| 165 | - // Put output into usable variable | |
| 166 | - $output = ob_get_contents(); | |
| 167 | - | |
| 168 | 163 | // Unset globals |
| 169 | 164 | $this->unset_globals(); |
| 170 | 165 | |
| 171 | - // Flush the output buffer | |
| 172 | - ob_end_clean(); | |
| 166 | + // Get the query name, for filter | |
| 167 | + $query_name = bbp_get_query_name(); | |
| 173 | 168 | |
| 174 | 169 | // Reset the query name |
| 175 | 170 | bbp_reset_query_name(); |
| 176 | 171 | |
| 177 | - // Add 'bbp_replace_the_content' filter back (@see $this::start()) | |
| 178 | - add_filter( 'the_content', 'bbp_replace_the_content' ); | |
| 172 | + // Return and flush the output buffer | |
| 173 | + $output = ob_get_clean(); | |
| 179 | 174 | |
| 180 | - return $output; | |
| 175 | + // Filter & return | |
| 176 | + return apply_filters( 'bbp_display_shortcode', $output, $query_name ); | |
| 181 | 177 | } |
| 182 | 178 | |
| 183 | 179 | /** Forum shortcodes ******************************************************/ |
| 184 | 180 | |
| @@ -185,14 +181,10 @@ | ||
| 185 | 181 | /** |
| 186 | 182 | * Display an index of all visible root level forums in an output buffer |
| 187 | 183 | * and return to ensure that post/page contents are displayed first. |
| 188 | 184 | * |
| 189 | - * @since bbPress (r3031) | |
| 185 | + * @since 2.0.0 bbPress (r3031) | |
| 190 | 186 | * |
| 191 | - * @param array $attr | |
| 192 | - * @param string $content | |
| 193 | - * @uses bbp_has_forums() | |
| 194 | - * @uses get_template_part() | |
| 195 | 187 | * @return string |
| 196 | 188 | */ |
| 197 | 189 | public function display_forum_index() { |
| 198 | 190 | |
| @@ -211,28 +203,28 @@ | ||
| 211 | 203 | /** |
| 212 | 204 | * Display the contents of a specific forum ID in an output buffer |
| 213 | 205 | * and return to ensure that post/page contents are displayed first. |
| 214 | 206 | * |
| 215 | - * @since bbPress (r3031) | |
| 207 | + * @since 2.0.0 bbPress (r3031) | |
| 216 | 208 | * |
| 217 | 209 | * @param array $attr |
| 218 | 210 | * @param string $content |
| 219 | - * @uses get_template_part() | |
| 220 | - * @uses bbp_single_forum_description() | |
| 221 | 211 | * @return string |
| 222 | 212 | */ |
| 223 | 213 | public function display_forum( $attr, $content = '' ) { |
| 224 | 214 | |
| 225 | 215 | // Sanity check required info |
| 226 | - if ( !empty( $content ) || ( empty( $attr['id'] ) || !is_numeric( $attr['id'] ) ) ) | |
| 216 | + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 227 | 217 | return $content; |
| 218 | + } | |
| 228 | 219 | |
| 229 | 220 | // Set passed attribute to $forum_id for clarity |
| 230 | 221 | $forum_id = bbpress()->current_forum_id = $attr['id']; |
| 231 | 222 | |
| 232 | 223 | // Bail if ID passed is not a forum |
| 233 | - if ( !bbp_is_forum( $forum_id ) ) | |
| 224 | + if ( ! bbp_is_forum( $forum_id ) ) { | |
| 234 | 225 | return $content; |
| 226 | + } | |
| 235 | 227 | |
| 236 | 228 | // Start output buffer |
| 237 | 229 | $this->start( 'bbp_single_forum' ); |
| 238 | 230 | |
| @@ -252,11 +244,9 @@ | ||
| 252 | 244 | /** |
| 253 | 245 | * Display the forum form in an output buffer and return to ensure |
| 254 | 246 | * post/page contents are displayed first. |
| 255 | 247 | * |
| 256 | - * @since bbPress (r3566) | |
| 257 | - * | |
| 258 | - * @uses get_template_part() | |
| 248 | + * @since 2.1.0 bbPress (r3566) | |
| 259 | 249 | */ |
| 260 | 250 | public function display_forum_form() { |
| 261 | 251 | |
| 262 | 252 | // Start output buffer |
| @@ -274,14 +264,10 @@ | ||
| 274 | 264 | /** |
| 275 | 265 | * Display an index of all visible root level topics in an output buffer |
| 276 | 266 | * and return to ensure that post/page contents are displayed first. |
| 277 | 267 | * |
| 278 | - * @since bbPress (r3031) | |
| 268 | + * @since 2.0.0 bbPress (r3031) | |
| 279 | 269 | * |
| 280 | - * @param array $attr | |
| 281 | - * @param string $content | |
| 282 | - * @uses bbp_get_hidden_forum_ids() | |
| 283 | - * @uses get_template_part() | |
| 284 | 270 | * @return string |
| 285 | 271 | */ |
| 286 | 272 | public function display_topic_index() { |
| 287 | 273 | |
| @@ -306,20 +292,20 @@ | ||
| 306 | 292 | /** |
| 307 | 293 | * Display the contents of a specific topic ID in an output buffer |
| 308 | 294 | * and return to ensure that post/page contents are displayed first. |
| 309 | 295 | * |
| 310 | - * @since bbPress (r3031) | |
| 296 | + * @since 2.0.0 bbPress (r3031) | |
| 311 | 297 | * |
| 312 | 298 | * @param array $attr |
| 313 | 299 | * @param string $content |
| 314 | - * @uses get_template_part() | |
| 315 | 300 | * @return string |
| 316 | 301 | */ |
| 317 | 302 | public function display_topic( $attr, $content = '' ) { |
| 318 | 303 | |
| 319 | 304 | // Sanity check required info |
| 320 | - if ( !empty( $content ) || ( empty( $attr['id'] ) || !is_numeric( $attr['id'] ) ) ) | |
| 305 | + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 321 | 306 | return $content; |
| 307 | + } | |
| 322 | 308 | |
| 323 | 309 | // Unset globals |
| 324 | 310 | $this->unset_globals(); |
| 325 | 311 | |
| @@ -327,13 +313,14 @@ | ||
| 327 | 313 | $topic_id = bbpress()->current_topic_id = $attr['id']; |
| 328 | 314 | $forum_id = bbp_get_topic_forum_id( $topic_id ); |
| 329 | 315 | |
| 330 | 316 | // Bail if ID passed is not a topic |
| 331 | - if ( !bbp_is_topic( $topic_id ) ) | |
| 317 | + if ( ! bbp_is_topic( $topic_id ) ) { | |
| 332 | 318 | return $content; |
| 319 | + } | |
| 333 | 320 | |
| 334 | 321 | // Reset the queries if not in theme compat |
| 335 | - if ( !bbp_is_theme_compat_active() ) { | |
| 322 | + if ( ! bbp_is_theme_compat_active() ) { | |
| 336 | 323 | |
| 337 | 324 | $bbp = bbpress(); |
| 338 | 325 | |
| 339 | 326 | // Reset necessary forum_query attributes for topics loop to function |
| @@ -366,20 +353,56 @@ | ||
| 366 | 353 | /** |
| 367 | 354 | * Display the topic form in an output buffer and return to ensure |
| 368 | 355 | * post/page contents are displayed first. |
| 369 | 356 | * |
| 370 | - * @since bbPress (r3031) | |
| 357 | + * Supports 'forum_id' attribute to display the topic form for a particular | |
| 358 | + * forum. This currently has styling issues from not being wrapped in | |
| 359 | + * <div id="bbpress-forums" class="bbpress-wrapper"></div> which will need to be sorted out later. | |
| 371 | 360 | * |
| 372 | - * @uses get_template_part() | |
| 361 | + * @since 2.0.0 bbPress (r3031) | |
| 362 | + * | |
| 363 | + * @param array $attr | |
| 364 | + * @param string $content | |
| 365 | + * @return string | |
| 373 | 366 | */ |
| 374 | - public function display_topic_form() { | |
| 367 | + public function display_topic_form( $attr = array(), $content = '' ) { | |
| 375 | 368 | |
| 376 | - // Start output buffer | |
| 377 | - $this->start( 'bbp_topic_form' ); | |
| 369 | + // Sanity check supplied info | |
| 370 | + if ( ! empty( $content ) || ( ! empty( $attr['forum_id'] ) && ( ! is_numeric( $attr['forum_id'] ) || ! bbp_is_forum( $attr['forum_id'] ) ) ) ) { | |
| 371 | + return $content; | |
| 372 | + } | |
| 378 | 373 | |
| 379 | - // Output templates | |
| 380 | - bbp_get_template_part( 'form', 'topic' ); | |
| 374 | + // Unset globals | |
| 375 | + $this->unset_globals(); | |
| 381 | 376 | |
| 377 | + // If forum id is set, use the 'bbp_single_forum' query name | |
| 378 | + if ( ! empty( $attr['forum_id'] ) ) { | |
| 379 | + | |
| 380 | + // Set the global current_forum_id for future requests | |
| 381 | + bbpress()->current_forum_id = $forum_id = bbp_get_forum_id( $attr['forum_id'] ); | |
| 382 | + | |
| 383 | + // Start output buffer | |
| 384 | + $this->start( 'bbp_single_forum' ); | |
| 385 | + | |
| 386 | + // No forum id was passed | |
| 387 | + } else { | |
| 388 | + | |
| 389 | + // Set the $forum_id variable to satisfy checks below | |
| 390 | + $forum_id = 0; | |
| 391 | + | |
| 392 | + // Start output buffer | |
| 393 | + $this->start( 'bbp_topic_form' ); | |
| 394 | + } | |
| 395 | + | |
| 396 | + // If the forum id is set, check forum caps else display normal topic form | |
| 397 | + if ( empty( $forum_id ) || bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) { | |
| 398 | + bbp_get_template_part( 'form', 'topic' ); | |
| 399 | + | |
| 400 | + // Forum is private and user does not have caps | |
| 401 | + } elseif ( bbp_is_forum_private( $forum_id, false ) ) { | |
| 402 | + bbp_get_template_part( 'feedback', 'no-access' ); | |
| 403 | + } | |
| 404 | + | |
| 382 | 405 | // Return contents of output buffer |
| 383 | 406 | return $this->end(); |
| 384 | 407 | } |
| 385 | 408 | |
| @@ -388,20 +411,20 @@ | ||
| 388 | 411 | /** |
| 389 | 412 | * Display the contents of a specific reply ID in an output buffer |
| 390 | 413 | * and return to ensure that post/page contents are displayed first. |
| 391 | 414 | * |
| 392 | - * @since bbPress (r3031) | |
| 415 | + * @since 2.0.0 bbPress (r3031) | |
| 393 | 416 | * |
| 394 | 417 | * @param array $attr |
| 395 | 418 | * @param string $content |
| 396 | - * @uses get_template_part() | |
| 397 | 419 | * @return string |
| 398 | 420 | */ |
| 399 | 421 | public function display_reply( $attr, $content = '' ) { |
| 400 | 422 | |
| 401 | 423 | // Sanity check required info |
| 402 | - if ( !empty( $content ) || ( empty( $attr['id'] ) || !is_numeric( $attr['id'] ) ) ) | |
| 424 | + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 403 | 425 | return $content; |
| 426 | + } | |
| 404 | 427 | |
| 405 | 428 | // Unset globals |
| 406 | 429 | $this->unset_globals(); |
| 407 | 430 | |
| @@ -409,22 +432,23 @@ | ||
| 409 | 432 | $reply_id = bbpress()->current_reply_id = $attr['id']; |
| 410 | 433 | $forum_id = bbp_get_reply_forum_id( $reply_id ); |
| 411 | 434 | |
| 412 | 435 | // Bail if ID passed is not a reply |
| 413 | - if ( !bbp_is_reply( $reply_id ) ) | |
| 436 | + if ( ! bbp_is_reply( $reply_id ) ) { | |
| 414 | 437 | return $content; |
| 438 | + } | |
| 415 | 439 | |
| 416 | 440 | // Reset the queries if not in theme compat |
| 417 | - if ( !bbp_is_theme_compat_active() ) { | |
| 441 | + if ( ! bbp_is_theme_compat_active() ) { | |
| 418 | 442 | |
| 419 | 443 | $bbp = bbpress(); |
| 420 | 444 | |
| 421 | - // Reset necessary forum_query attributes for replys loop to function | |
| 445 | + // Reset necessary forum_query attributes for reply loop to function | |
| 422 | 446 | $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type(); |
| 423 | 447 | $bbp->forum_query->in_the_loop = true; |
| 424 | 448 | $bbp->forum_query->post = get_post( $forum_id ); |
| 425 | 449 | |
| 426 | - // Reset necessary reply_query attributes for replys loop to function | |
| 450 | + // Reset necessary reply_query attributes for reply loop to function | |
| 427 | 451 | $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type(); |
| 428 | 452 | $bbp->reply_query->in_the_loop = true; |
| 429 | 453 | $bbp->reply_query->post = get_post( $reply_id ); |
| 430 | 454 | } |
| @@ -448,11 +472,9 @@ | ||
| 448 | 472 | /** |
| 449 | 473 | * Display the reply form in an output buffer and return to ensure |
| 450 | 474 | * post/page contents are displayed first. |
| 451 | 475 | * |
| 452 | - * @since bbPress (r3031) | |
| 453 | - * | |
| 454 | - * @uses get_template_part() | |
| 476 | + * @since 2.0.0 bbPress (r3031) | |
| 455 | 477 | */ |
| 456 | 478 | public function display_reply_form() { |
| 457 | 479 | |
| 458 | 480 | // Start output buffer |
| @@ -470,9 +492,9 @@ | ||
| 470 | 492 | /** |
| 471 | 493 | * Display a tag cloud of all topic tags in an output buffer and return to |
| 472 | 494 | * ensure that post/page contents are displayed first. |
| 473 | 495 | * |
| 474 | - * @since bbPress (r3110) | |
| 496 | + * @since 2.0.0 bbPress (r3110) | |
| 475 | 497 | * |
| 476 | 498 | * @return string |
| 477 | 499 | */ |
| 478 | 500 | public function display_topic_tags() { |
| @@ -498,20 +520,20 @@ | ||
| 498 | 520 | /** |
| 499 | 521 | * Display the contents of a specific topic tag in an output buffer |
| 500 | 522 | * and return to ensure that post/page contents are displayed first. |
| 501 | 523 | * |
| 502 | - * @since bbPress (r3110) | |
| 524 | + * @since 2.0.0 bbPress (r3110) | |
| 503 | 525 | * |
| 504 | 526 | * @param array $attr |
| 505 | 527 | * @param string $content |
| 506 | - * @uses get_template_part() | |
| 507 | 528 | * @return string |
| 508 | 529 | */ |
| 509 | 530 | public function display_topics_of_tag( $attr, $content = '' ) { |
| 510 | 531 | |
| 511 | 532 | // Sanity check required info |
| 512 | - if ( !empty( $content ) || ( empty( $attr['id'] ) || !is_numeric( $attr['id'] ) ) ) | |
| 533 | + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 513 | 534 | return $content; |
| 535 | + } | |
| 514 | 536 | |
| 515 | 537 | // Unset globals |
| 516 | 538 | $this->unset_globals(); |
| 517 | 539 | |
| @@ -536,13 +558,10 @@ | ||
| 536 | 558 | /** |
| 537 | 559 | * Display the contents of a specific topic tag in an output buffer |
| 538 | 560 | * and return to ensure that post/page contents are displayed first. |
| 539 | 561 | * |
| 540 | - * @since bbPress (r3346) | |
| 562 | + * @since 2.0.0 bbPress (r3346) | |
| 541 | 563 | * |
| 542 | - * @param array $attr | |
| 543 | - * @param string $content | |
| 544 | - * @uses get_template_part() | |
| 545 | 564 | * @return string |
| 546 | 565 | */ |
| 547 | 566 | public function display_topic_tag_form() { |
| 548 | 567 | |
| @@ -564,21 +583,20 @@ | ||
| 564 | 583 | /** |
| 565 | 584 | * Display the contents of a specific view in an output buffer and return to |
| 566 | 585 | * ensure that post/page contents are displayed first. |
| 567 | 586 | * |
| 568 | - * @since bbPress (r3031) | |
| 587 | + * @since 2.0.0 bbPress (r3031) | |
| 569 | 588 | * |
| 570 | 589 | * @param array $attr |
| 571 | 590 | * @param string $content |
| 572 | - * @uses get_template_part() | |
| 573 | - * @uses bbp_single_forum_description() | |
| 574 | 591 | * @return string |
| 575 | 592 | */ |
| 576 | 593 | public function display_view( $attr, $content = '' ) { |
| 577 | 594 | |
| 578 | 595 | // Sanity check required info |
| 579 | - if ( empty( $attr['id'] ) ) | |
| 596 | + if ( empty( $attr['id'] ) ) { | |
| 580 | 597 | return $content; |
| 598 | + } | |
| 581 | 599 | |
| 582 | 600 | // Set passed attribute to $view_id for clarity |
| 583 | 601 | $view_id = $attr['id']; |
| 584 | 602 | |
| @@ -587,8 +605,11 @@ | ||
| 587 | 605 | |
| 588 | 606 | // Unset globals |
| 589 | 607 | $this->unset_globals(); |
| 590 | 608 | |
| 609 | + // Set the current view ID | |
| 610 | + bbpress()->current_view_id = $view_id; | |
| 611 | + | |
| 591 | 612 | // Load the view |
| 592 | 613 | bbp_view_query( $view_id ); |
| 593 | 614 | |
| 594 | 615 | // Output template |
| @@ -597,14 +618,89 @@ | ||
| 597 | 618 | // Return contents of output buffer |
| 598 | 619 | return $this->end(); |
| 599 | 620 | } |
| 600 | 621 | |
| 622 | + /** Search ****************************************************************/ | |
| 623 | + | |
| 624 | + /** | |
| 625 | + * Display the search form in an output buffer and return to ensure | |
| 626 | + * post/page contents are displayed first. | |
| 627 | + * | |
| 628 | + * @since 2.3.0 bbPress (r4585) | |
| 629 | + */ | |
| 630 | + public function display_search_form() { | |
| 631 | + | |
| 632 | + // Bail if search is disabled | |
| 633 | + if ( ! bbp_allow_search() ) { | |
| 634 | + return; | |
| 635 | + } | |
| 636 | + | |
| 637 | + // Start output buffer | |
| 638 | + $this->start( 'bbp_search_form' ); | |
| 639 | + | |
| 640 | + // Output templates | |
| 641 | + bbp_get_template_part( 'form', 'search' ); | |
| 642 | + | |
| 643 | + // Return contents of output buffer | |
| 644 | + return $this->end(); | |
| 645 | + } | |
| 646 | + | |
| 647 | + /** | |
| 648 | + * Display the contents of search results in an output buffer and return to | |
| 649 | + * ensure that post/page contents are displayed first. | |
| 650 | + * | |
| 651 | + * @since 2.3.0 bbPress (r4579) | |
| 652 | + * | |
| 653 | + * @param array $attr | |
| 654 | + * @param string $content | |
| 655 | + */ | |
| 656 | + public function display_search( $attr, $content = '' ) { | |
| 657 | + | |
| 658 | + // Sanity check required info | |
| 659 | + if ( ! empty( $content ) ) { | |
| 660 | + return $content; | |
| 661 | + } | |
| 662 | + | |
| 663 | + // Bail if search is disabled | |
| 664 | + if ( ! bbp_allow_search() ) { | |
| 665 | + return; | |
| 666 | + } | |
| 667 | + | |
| 668 | + // Trim search attribute if it's set | |
| 669 | + if ( isset( $attr['search'] ) ) { | |
| 670 | + $attr['search'] = trim( $attr['search'] ); | |
| 671 | + } | |
| 672 | + | |
| 673 | + // Set passed attribute to $search_terms for clarity | |
| 674 | + $search_terms = empty( $attr['search'] ) | |
| 675 | + ? bbp_get_search_terms() | |
| 676 | + : $attr['search']; | |
| 677 | + | |
| 678 | + // Get the rewrite ID (one time, to avoid repeated calls) | |
| 679 | + $rewrite_id = bbp_get_search_rewrite_id(); | |
| 680 | + | |
| 681 | + // Unset globals | |
| 682 | + $this->unset_globals(); | |
| 683 | + | |
| 684 | + // Set terms for query | |
| 685 | + set_query_var( $rewrite_id, $search_terms ); | |
| 686 | + | |
| 687 | + // Start output buffer | |
| 688 | + $this->start( $rewrite_id ); | |
| 689 | + | |
| 690 | + // Output template | |
| 691 | + bbp_get_template_part( 'content', 'search' ); | |
| 692 | + | |
| 693 | + // Return contents of output buffer | |
| 694 | + return $this->end(); | |
| 695 | + } | |
| 696 | + | |
| 601 | 697 | /** Account ***************************************************************/ |
| 602 | 698 | |
| 603 | 699 | /** |
| 604 | 700 | * Display a login form |
| 605 | 701 | * |
| 606 | - * @since bbPress (r3302) | |
| 702 | + * @since 2.0.0 bbPress (r3302) | |
| 607 | 703 | * |
| 608 | 704 | * @return string |
| 609 | 705 | */ |
| 610 | 706 | public function display_login() { |
| @@ -615,12 +711,13 @@ | ||
| 615 | 711 | // Start output buffer |
| 616 | 712 | $this->start( 'bbp_login' ); |
| 617 | 713 | |
| 618 | 714 | // Output templates |
| 619 | - if ( !is_user_logged_in() ) | |
| 715 | + if ( ! is_user_logged_in() ) { | |
| 620 | 716 | bbp_get_template_part( 'form', 'user-login' ); |
| 621 | - else | |
| 717 | + } else { | |
| 622 | 718 | bbp_get_template_part( 'feedback', 'logged-in' ); |
| 719 | + } | |
| 623 | 720 | |
| 624 | 721 | // Return contents of output buffer |
| 625 | 722 | return $this->end(); |
| 626 | 723 | } |
| @@ -627,9 +724,9 @@ | ||
| 627 | 724 | |
| 628 | 725 | /** |
| 629 | 726 | * Display a register form |
| 630 | 727 | * |
| 631 | - * @since bbPress (r3302) | |
| 728 | + * @since 2.0.0 bbPress (r3302) | |
| 632 | 729 | * |
| 633 | 730 | * @return string |
| 634 | 731 | */ |
| 635 | 732 | public function display_register() { |
| @@ -640,12 +737,13 @@ | ||
| 640 | 737 | // Start output buffer |
| 641 | 738 | $this->start( 'bbp_register' ); |
| 642 | 739 | |
| 643 | 740 | // Output templates |
| 644 | - if ( !is_user_logged_in() ) | |
| 741 | + if ( ! is_user_logged_in() ) { | |
| 645 | 742 | bbp_get_template_part( 'form', 'user-register' ); |
| 646 | - else | |
| 743 | + } else { | |
| 647 | 744 | bbp_get_template_part( 'feedback', 'logged-in' ); |
| 745 | + } | |
| 648 | 746 | |
| 649 | 747 | // Return contents of output buffer |
| 650 | 748 | return $this->end(); |
| 651 | 749 | } |
| @@ -652,9 +750,9 @@ | ||
| 652 | 750 | |
| 653 | 751 | /** |
| 654 | 752 | * Display a lost password form |
| 655 | 753 | * |
| 656 | - * @since bbPress (r3302) | |
| 754 | + * @since 2.0.0 bbPress (r3302) | |
| 657 | 755 | * |
| 658 | 756 | * @return string |
| 659 | 757 | */ |
| 660 | 758 | public function display_lost_pass() { |
| @@ -665,13 +763,14 @@ | ||
| 665 | 763 | // Start output buffer |
| 666 | 764 | $this->start( 'bbp_lost_pass' ); |
| 667 | 765 | |
| 668 | 766 | // Output templates |
| 669 | - if ( !is_user_logged_in() ) | |
| 767 | + if ( ! is_user_logged_in() ) { | |
| 670 | 768 | bbp_get_template_part( 'form', 'user-lost-pass' ); |
| 671 | - else | |
| 769 | + } else { | |
| 672 | 770 | bbp_get_template_part( 'feedback', 'logged-in' ); |
| 673 | - | |
| 771 | + } | |
| 772 | + | |
| 674 | 773 | // Return contents of output buffer |
| 675 | 774 | return $this->end(); |
| 676 | 775 | } |
| 677 | 776 | |
| @@ -677,11 +776,33 @@ | ||
| 677 | 776 | |
| 678 | 777 | /** Other *****************************************************************/ |
| 679 | 778 | |
| 680 | 779 | /** |
| 780 | + * Display forum statistics | |
| 781 | + * | |
| 782 | + * @since 2.3.0 bbPress (r4509) | |
| 783 | + * | |
| 784 | + * @return string | |
| 785 | + */ | |
| 786 | + public function display_stats() { | |
| 787 | + | |
| 788 | + // Unset globals | |
| 789 | + $this->unset_globals(); | |
| 790 | + | |
| 791 | + // Start output buffer | |
| 792 | + $this->start(); | |
| 793 | + | |
| 794 | + // Output statistics | |
| 795 | + bbp_get_template_part( 'content', 'statistics' ); | |
| 796 | + | |
| 797 | + // Return contents of output buffer | |
| 798 | + return $this->end(); | |
| 799 | + } | |
| 800 | + | |
| 801 | + /** | |
| 681 | 802 | * Display a breadcrumb |
| 682 | 803 | * |
| 683 | - * @since bbPress (r3302) | |
| 804 | + * @since 2.0.0 bbPress (r3302) | |
| 684 | 805 | * |
| 685 | 806 | * @return string |
| 686 | 807 | */ |
| 687 | 808 | public function display_breadcrumb() { |
| @@ -703,9 +824,9 @@ | ||
| 703 | 824 | |
| 704 | 825 | /** |
| 705 | 826 | * Filter the query for the topic index |
| 706 | 827 | * |
| 707 | - * @since bbPress (r3637) | |
| 828 | + * @since 2.1.0 bbPress (r3637) | |
| 708 | 829 | * |
| 709 | 830 | * @param array $args |
| 710 | 831 | * @return array |
| 711 | 832 | */ |
| @@ -718,9 +839,9 @@ | ||
| 718 | 839 | |
| 719 | 840 | /** |
| 720 | 841 | * Filter the query for topic tags |
| 721 | 842 | * |
| 722 | - * @since bbPress (r3637) | |
| 843 | + * @since 2.1.0 bbPress (r3637) | |
| 723 | 844 | * |
| 724 | 845 | * @param array $args |
| 725 | 846 | * @return array |
| 726 | 847 | */ |