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